Math-Vectors2
view release on metacpan or search on metacpan
lib/Math/Vectors2.pm view on Meta::CPAN
genHash(__PACKAGE__, # Attributes of a vector
x => $x, # X coordinate
y => $y, # Y coordinate
);
}
sub zeroAndUnits() #S Create the useful vectors: zero=(0,0), x=(1,0), y=(0,1).
{map {&new(@$_)} ([0, 0], [1, 0], [0, 1])
}
sub eq($$) # Whether two vectors are equal to within the accuracy of floating point arithmetic.
{my ($o, $p) = @_; # First vector, second vector
near2($o, $p)
}
sub zero($) # Whether a vector is equal to zero within the accuracy of floating point arithmetic.
{my ($o) = @_; # Vector
near($o->x, 0) && near($o->y, 0)
}
sub print($@) # Print one or more vectors.
lib/Math/Vectors2.pm view on Meta::CPAN
sub divide($$) # Divide a copy of a vector by a scalar and return the result.
{my ($o, $d) = @_; # Vector, scalar to divide by
$o->clone->Divide($d)
}
sub l($) # Length of a vector.
{my ($o) = @_; # Vector
sqrt($o->x**2 + $o->y**2)
}
sub l2($) # Length squared of a vector.
{my ($o) = @_; # Vector
$o->x**2 + $o->y**2
}
sub d($$) # Distance between the points identified by two vectors when placed on the same point.
{my ($o, $p) = @_; # Vector 1, vector 2
sqrt(($o->x-$p->x)**2 + ($o->y-$p->y)**2)
}
sub d2($$) # Distance squared between the points identified by two vectors when placed on the same point.
{my ($o, $p) = @_; # Vector 1, vector 2
($o->x-$p->x)**2 + ($o->y-$p->y)**2
}
sub n($) # Return a normalized a copy of a vector.
{my ($o) = @_; # Vector
my $l = $o->l;
$l == 0 and confess;
new($o->x / $l, $o->y / $l)
}
( run in 1.086 second using v1.01-cache-2.11-cpan-524268b4103 )