Math::Shape::Vector - A 2d vector object in cartesian space
version 0.02
use Math::Shape::Vector; my $v1 = Math::Shape::Vector->new(3, 5); my $v2 = Math::Shape::Vector->new(1, 17); $v1->add_vector($v2); $v1->negate; $v1->multiply(5); $v1->is_equal($v2);
Create a new vector. Requires two numerical arguments for the origin and magnitude.
my $vector = Math::Shape::Vector->new(3, 5);
Adds a vector to the vector object, updating its x & y values.
$vector->add_vector($vector_2);
Subtracts a vector from the vector object, updating its x & y values.
$vector->subtract_vector($vector_2);
Negates the vector's values e.g. (1,3) becomes (-1, -3).
$vector->negate();
Compares a vector to the vector object, returning 1 if they are the same or 0 if they are different.
$vector->is_equal($vector_2);
Multiplies the vector's x and y values by a number.
$vector->multiply(3);
Divides the vector's x and y values by a number.
$vector->divide(2);
https://github.com/sillymoose/Math-Shape-Vector.git
The source code for this object was inspired by the code in Thomas Schwarzl's 2d collision detection book http://www.collisiondetection2d.net.
David Farrell <sillymoos@cpan.org>
This software is copyright (c) 2014 by David Farrell.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Math::Shape::Vector, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::Shape::Vector
CPAN shell
perl -MCPAN -e shell install Math::Shape::Vector
For more information on module installation, please visit the detailed CPAN module installation guide.