NAME

Math::Rotation - Perl class to represent rotations

HIERARCHY

-+- Math::Rotation

SEE ALSO

Math::Quaternion

Math::Color, 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;

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

$r2 = $r1->copy;
$r2 = new Math::Rotation($r1);

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)

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);

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).

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

$v4 = [ $r->getValue ];

x

getX

Returns the first value of the axis vector.

$x = $r->x
$x = $r->getX;

y

getY

Returns the second value of the axis vector.

$y = $r->y;
$y = $r->getY;

z

getZ

Returns the third value of the axis vector

$z = $r->z;
$z = $r->getZ;

getAxis

Returns the axis of rotation as an @array.

@axis = $r->getAxis;

angle

getAngle

Returns corresponding 3D rotation angle in radians.

$angle = $r->angle;
$angle = $r->getAngle;

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)

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;

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

perlfunc

POSIX

Math::Complex, Math::Trig, Math::Quaternion

Math::Color, 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  E<holger.seelig@yahoo.de>

COPYRIGHT

This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.