NAME

Math::Rotation - Perl class to represent rotations

HIERARCHY

-+- Math::Rotation

SEE ALSO

Math::Color, Math::Image, Math::Vec2, Math::Vec3, Math::Rotation Math::Quaternion

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;

DESCRIPTION

METHODS

new
# Make a new unit rotation.
my $r = new Math::Rotation;

my $r2 = new Math::Rotation(1,2,3,4);         # (x,y,z, angle)
my $r3 = new Math::Rotation([1,2,3],4);       # (axis, angle)
my $r3 = new Math::Rotation([1,2,3],[1,2,3]); # (fromVec, toVec)
new_from_quaternion $r5 = new_from_quaternion Math::Rotation(new Math::Quaternion);
copy

Makes a copy of the rotation

$r2 = $r1->copy;
$r2 = new Math::Rotation($r1);
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);
setAngle(angle)

Sets angle of rotation in radiants.

$r->setAngle(4);
setAxisAngle(x,y,z, angle)
setValue(x,y,z, angle)

Sets value of rotation from axis angle.

$r->setAxisAngle(1,2,3,4);
$r->setValue(1,2,3,4);
setQuaternion(quaternion)

Sets value of rotation from a quaternion.

$r->setQuaternion(new Math::Quaternion(1,2,3,4));
getX

Returns the first value of the axis vector.

$x = $r->getX;
getY

Returns the second value of the axis vector.

$y = $r->getY;
getZ

Returns the third value of the axis vector

$z = $r->getZ;
getAxis

Returns the axis of rotation as an @array.

@axis = $r->getAxis;
getAngle

Returns corresponding 3D rotation angle in radians.

$angle = $r->getAngle;
getAxisAngle
getValue

Returns corresponding 3D rotation (x, y, z, angle).

($x, $y, $z, $angle) = $r->getAxisAngle;
($x, $y, $z, $angle) = $r->getValue;

$v4 = [ $r->getValue ];
getQuaternion

Returns corresponding Math::Quaternion.

$q = $r->getQuaternion;
inverse

Returns a Math::Rotation object whose value is the inverse of this object's rotation.

$i = $r->inverse;
$i = -$r;
$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;

$r = $r1 + $r2;
multVec(x,y,z) or 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);
eq(rotation)
my $bool = $r1->eq($r2);
my $bool = $r1 eq $r2;
my $bool = $r1 == $r2;
ne(rotation)
my $bool = $r1->ne($r2);
my $bool = $r1 ne $r2;
my $bool = $r1 != $r2;
stringify

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->stringify;                # "1 2 3 4"
print "$q";                         # "1 2 3 4"

1 POD Error

The following errors were encountered while parsing the POD:

Around line 62:

=over without closing =back