NAME
Math::Rotation - Perl class to represent rotations
VERSION
TREE
-+- Math::Rotation
REQUIRES
SEE ALSO
Math::Color, Math::ColorRGBA, Math::Image, Math::Vec2, Math::Vec3, Math::Rotation
SYNOPSIS
use Math::Rotation;
my $r = new Math::Rotation; # Make a new unit rotation
# Make a rotation about the axis (0,1,0)
my $r2 = new Math::Rotation([0,1,0], 0.1);
my $r3 = new Math::Rotation(1, 2, 3, 4);
my $fromVector = [1,2,3];
my $toVector = [2,3,4];
my $r4 = new Math::Rotation($fromVector, $toVector);
my $r5 = $r2 + $r3;
my $r6 = -$r5;
~-$r2 == $r2;
DESCRIPTION
Default value
0 0 1 0
OPERATORS
Summary
'~' => Returns the inverse of this rotation.
'!' => Returns true if the angle of this rotation is 0
'==' => Numerical eq. Performs a componentwise equation.
'!=' => Numerical ne. Performs a componentwise equation.
'eq' => Stringwise eq
'ne' => Stringwise ne
'bool' => Returns true if the angle of this rotation is not 0
'*' => Multiply this rotation with a rotation or a Math::Vec3 object.
'""' => Returns a string representation of the rotation.
METHODS
new
# Make a new unit rotation.
my $r = new Math::Rotation;
my $r1 = new Math::Rotation([1,2,3],[1,2,3]); # (fromVector, toVector)
my $r2 = new Math::Rotation(1,2,3,4); # (x,y,z, angle)
my $r3 = new Math::Rotation([1,2,3],4); # (axis, angle)
new_from_quaternion(new Math::Quaternion)
$r5 = new_from_quaternion Math::Rotation(new Math::Quaternion);
copy
Makes a copy
$r2 = $r1->copy;
setValue(x,y,z, angle)
Sets value of rotation from axis angle.
$r->setValue(1,2,3,4);
setX(x)
Sets the first value of the axis vector
$r->setX(1);
setY(y)
Sets the second value of the axis vector
$r->setY(2);
setZ(z)
Sets the third value of the axis vector
$r->setZ(3);
setAxis([x,y,z])
Sets axis of rotation from a 3 components array.
$r->setAxis([1,2,3]);
$r->setAxis(Math::Vec3(1,2,3));
setAngle(angle)
Sets angle of rotation in radiants [0, 2 PI].
$r->setAngle(4);
setQuaternion(quaternion)
Sets value of rotation from a quaternion.
$r->setQuaternion(new Math::Quaternion(1,2,3,4));
getValue
Returns corresponding 3D rotation (x, y, z, angle) as a 4 components array.
($x, $y, $z, $angle) = $r->getValue;
$v4 = [ $r->getValue ];
getX
Returns the first value of the axis vector.
$x = $r->getX;
getY
Returns the second value of the axis vector.
$y = $r->y;
$y = $r->getY;
getZ
Returns the third value of the axis vector
$z = $r->getZ;
getAxis
Returns the axis of rotation as an Math::Vec3 object.
$axis = $r->getAxis;
getAngle
Returns corresponding 3D rotation angle in radiants [0, 2 PI].
$angle = $r->getAngle;
getQuaternion
Returns corresponding quaternion. This function is experimental
$q = $r->getQuaternion;
inverse
Returns a Math::Rotation object whose value is the inverse of this object's rotation.
$i = $r->inverse;
$i = ~$r;
multiply(rotation)
Returns an Math::Rotation whose value is the object multiplied by the passed Math::Rotation.
$r = $r1->multiply($r2);
$r = $r1 * $r2;
$r1 *= $r1;
multVec(x,y,z)
multVec([x,y,z])
Returns an array whose value is the 3D vector [x,y,z] multiplied by the matrix corresponding to this object's rotation.
$v = $r->multVec([1,2,3]);
@v = $r->multVec(1,2,3);
$v = $r1 * [1,2,3];
$v = $r1 * Math::Vec3->new(1,2,3);
$v = $r->multVec(new Math::Vec3(1,2,3));
ref($v) eq "Math::Vec3";
slerp(destRotation, t)
Returns a Math::Rotation object whose value is the spherical linear interpolation between this object's rotation and destRotation at value 0 <= t <= 1. For t = 0, the value is this object's rotation. For t = 1, the value is destRotation.
$r = $r1->slerp($r2, $_) foreach map {$_/10} (1..10);
toString
Returns a string representation of the rotation. This is used to overload the '""' operator, so that rotations may be freely interpolated in strings.
my $q = new Math::Rotation(1,2,3,4);
print $q->toString; # "1 2 3 4"
print "$q"; # "1 2 3 4"
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.