Math::Vectors2 - Vectors in two dimensions
use Math::Vectors2; my ($o, $x, $y) = Math::Vectors2::zeroAndUnits; ok $o->print($x, $y) eq '(0,0), (1,0), (0,1)'; my $p1 = $x->times(3); my $p2 = $y->times(4); my $p = $o->add($p1, $p2); ok $p->print($p1, $p2) eq '(3,4), (3,0), (0,4)'; ok $o->d($p) == 5;
Or more briefly:
use Math::Vectors2; *v = *Math::Vectors2::new; ok v(3,4)->l == 5;
The following sections describe the methods in each functional area of this module. For an alphabetic listing of all methods by name see Index.
Methods
X component of vector
Y component of vector
Create new vector from components
1 $x X component 2 $y Y component
Example:
ok $o->print($x, $y) eq '(0,0), (1,0), (0,1)'; ok near2(Math::Vectors2::new(0, 0), $o);
Create the useful vectors: o=(0,0), x=(1,0), y=(0,1)
my ($o, $x, $y) = Math::Vectors2::zeroAndUnits; ok $o->print($x, $y) eq '(0,0), (1,0), (0,1)';
Print one or more vectors
1 $p Vector to print 2 @p More vectors to print
ok $o->print($x, $y) eq '(0,0), (1,0), (0,1)';
Clone a vector
1 $o Vector to clone
ok $o->print($P, $p1, $p2) eq '(0,0), (3,4), (3,0), (0,4)'; my $p = $P->clone; ok $p->print($P) eq '(3,4), (3,4)';
Add zero or more other vectors to the first vector
1 $o First vector 2 @p Other vectors
my $P = $o->add($p1, $p2); ok $o->print($P, $p1, $p2) eq '(0,0), (3,4), (3,0), (0,4)';
Subtract zero or more vectors from the first vector
ok $o->print($p, $p1, $p2) eq '(0,0), (3,4), (3,0), (0,4)'; ok near2($o, $p->minus($p1, $p2));
Multiply a vector by a scalar
1 $o Vector 2 $m Scalar to multiply by
ok $o->print($x, $y) eq '(0,0), (1,0), (0,1)'; my $p1 = $x->times(3); my $p2 = $y->times(4); ok $o->print($P, $p1, $p2) eq '(0,0), (3,4), (3,0), (0,4)';
Length of a vector
1 $o Vector
ok $p->print($P) eq '(3,4), (3,4)'; ok $p->l == 5;
Distance between the points identified by two vectors when placed on the same point
1 $o Vector 1 2 $p Vector 2
ok $o->print($p) eq '(0,0), (3,4)'; ok $o->d($p) == 5;
1 add
2 clone
3 d
4 l
5 minus
6 new
7 print
8 times
9 x
10 y
11 zeroAndUnits
This module is written in 100% Pure Perl and, thus, it is easy to read, use, modify and install.
Standard Module::Build process for building and installing modules:
perl Build.PL ./Build ./Build test ./Build install
philiprbrenan@gmail.com
http://www.appaapps.com
Copyright (c) 2016-2017 Philip R Brenan.
This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
To install Math::Vectors2, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::Vectors2
CPAN shell
perl -MCPAN -e shell install Math::Vectors2
For more information on module installation, please visit the detailed CPAN module installation guide.