Vector2
Manipulate 2D vectors
PhilipRBrenan@yahoo.com, 2004, Perl License
Synopsis
Example t/vector2.t
#_ Vector _____________________________________________________________
# Test 2d vectors
# philiprbrenan@yahoo.com, 2004, Perl License
#______________________________________________________________________
use Math::Zap::Vector2 vector2=>v, units=>u;
use Test::Simple tests=>7;
my ($x, $y) = u();
ok(!$x == 1);
ok(2*$x+3*$y == v( 2, 3));
ok(-$x-$y == v(-1, -1));
ok((2*$x+3*$y) + (-$x-$y) == v( 1, 2));
ok((2*$x+3*$y) * (-$x-$y) == -5);
ok($x*2 == v( 2, 0));
ok($y/2 == v( 0, 0.5));
Description
Manipulate 2D vectors
Constructors
new
Create a vector from numbers
vector2
Create a vector from numbers - synonym for "new"
units
Unit vectors
Methods
check
Check its a vector
is
Test its a vector
accuracy
Get/Set accuracy for comparisons
round
Round: round to nearest integer if within accuracy of that integer
components
x,y components of vector
clone
Create a vector from another vector
length
Length of a vector
Print vector
normalize
Normalize vector
rightAngle
At right angles
dot
Dot product
angle
Angle between two vectors
add
Add vectors
subtract
Subtract vectors
multiply
Vector times a scalar
divide
Vector divided by a non zero scalar
equals
Equals to within accuracy
Operators
# Operator overloads
add
Add operator.
subtract
Subtract operator.
multiply
Multiply operator.
divide
Divide operator.
angle
Angle between two vectors.
equals
Equals operator.
Print a vector.
Exports
Export "vector2", "units", "check", "is"
Credits
Author
philiprbrenan@yahoo.com
Copyright
philiprbrenan@yahoo.com, 2004
License
Perl License.