NAME
Math::Vec3 - Perl class to represent 3d vectors
TREE
-+- Math::Vec2 -+- Math::Vec3
SEE ALSO
Math::Color, Math::ColorRGBA, Math::Image, Math::Vec2, Math::Vec3, Math::Rotation
SYNOPSIS
use Math::Vec3;
my $v = new Math::Vec3; # Make a new vec3
my $v1 = new Math::Vec3(0,1,0);
DESCRIPTION
3D vector class used to store 3D vectors and points.
DefaultValue
0 0 0
OPERATORS
Overview
'~' => reverse
'>>' => rotate
'<<' => rotate
'<' => numerical gt
'>' => numerical lt
'<=>' => numerical cmp
'==' => eq
'!=' => ne
'lt' => lt
'le' => le
'gt' => gt
'ge' => ge
'cmp' => cmp
'eq' => eq
'ne' => ne
'bool' => length
'0+' => length
'abs' => abs
'neg' => negate
'+=' => add
'-=' => subtract
'*=' => multiply
'/=' => divide
'**=' => pow
'x=' => cross
'+' => add
'-' => subtract
'*' => multiply
'/' => divide
'**' => pow
'.' => dot
'x' => cross
'""' => toString
~
Returns the reverse of this vector.
my $v = new Math::Vec3(1,2,3);
printf "3 2 1 = %s\n", ~$v;
printf "1 2 3 = %s\n", ~~$v;
<<
Performs a counter-clockwise rotation of the components. Very similar to bitwise left-shift.
my $v = new Math::Vec3(1,2,3);
printf "2 3 1= %s\n", $v << 1;
printf "3 1 2 = %s\n", $v << 2;
>>
Performs a clockwise rotation of the components. Very similar to bitwise right-shift.
my $v = new Math::Vec3(1,2,3);
printf "3 1 2 = %s\n", $v >> 1;
printf "2 3 1 = %s\n", $v >> 2;
$v x= [1, 2, 3];
$v x= ~$v x [1, 2, 3] >> 2;
METHODS
new
Derived from "new" in Math::Vec2.
my $v = new Math::Vec3;
my $v2 = new Math::Vec3(1,2,3);
my @v3 = @$v;
If you call new() with a reference to an array, it will be used as reference.
my $v3 = new Math::Vec3([1,2,3]);
I=cut
copy
Makes a copy
$v2 = $v1->copy;
setValue(x,y,z)
Sets the value of the vector
$v1->setValue(1,2,3);
setX(x)
Sets the first value of the vector
$v1->setX(1);
$v1->x = 1;
$v1->[0] = 1;
setY(y)
Sets the second value of the vector
$v1->setY(2);
$v1->y = 2;
$v1->[1] = 2;
setZ(z)
Sets the third value of the vector
$v1->setZ(3);
$v1->z = 3;
$v1->[2] = 3;
getValue
Returns the value of the vector (x, y, z) as a 3 components array.
@v = $v1->getValue;
x
getX
Returns the first value of the vector.
$x = $v1->getX;
$x = $v1->x;
$x = $v1->[0];
y
getY
Returns the second value of the vector.
$y = $v1->getY;
$y = $v1->y;
$y = $v1->[1];
z
getZ
Returns the third value of the vector
$z = $v1->getZ;
$z = $v1->z;
$z = $v1->[2];
negate
$v = $v1->negate;
$v = -$v1;
add(vec3)
$v = $v1->add($v2);
$v = $v1 + $v2;
$v1 += $v2;
subtract(vec3)
$v = $v1->subtract($v2);
$v = $v1 - $v2;
$v1 -= $v2;
multiply(scalar)
multiply(vec3)
$v = $v1->multiply($v2);
$v = $v1->multiply(2);
$v = $v1 * 2;
$v1 *= 2;
divide(scalar)
divide(vec3)
$v = $v1->divide($v2);
$v = $v1->divide(2);
$v = $v1 / 2;
$v1 /= 2;
pow(scalar)
This is used to overload the '**' operator.
$v = $v1->pow(3);
$v = $v1 * $v1 * $v1;
$v = $v1 ** 3;
dot(vec3)
$s = $v1->dot($v2);
$s = $v1 . $v2;
$s = $v1 . [ 2, 3, 4 ];
cross(vec3)
$v = $v1->cross($v2);
$v = $v1 x $v2;
$v = $v1 x [ 2, 3, 4 ];
length
Returns the length of the vector
$l = $v1->length;
normalize
$v = $v1->normalize;
reverse()
Returns the reverse of this vector. This is used to overload the '~' operator.
$v = $vec3->reverse;
rotate(n)
Performs a componentwise rotation. This is used to overload the '>>' and '<<' operator.
$v = $vec->rotate(1);
$v = $vec->rotate(-2);
toString()
Returns a string representation of the vector. This is used to overload the '""' operator, so that vector may be freely interpolated in strings.
my $v = new Math::Vec3(1,2,3,4);
print $v->toString; # "1 2 3"
print "$v"; # "1 2 3"
SEE ALSO
Math::Color, Math::ColorRGBA, Math::Image, Math::Vec2, Math::Vec3, Math::Rotation
BUGS & SUGGESTIONS
If you run into a miscalculation, need some sort of feature or an additional holiday, or if you know of any new changes to the funky math, please drop the author a note.
ARRANGED BY
Holger Seelig holger.seelig@yahoo.de
COPYRIGHT
This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.