Using Perl's Math-class
Join the DZone community and get the full member experience.
Join For FreeA little demo that shows how to perform some vector-algebra using Math::-methods.
#!/usr/bin/perl
#use strict;
use Math::VectorReal qw( :all );
use Math::Trig qw( acos );
$a=vector(10,0,0.1);
$b=vector(0,0,1);
$lnorm=($a->length)*($b->length);
$scalprod= $a . $b;
$arccosthis=$scalprod/$lnorm;
$rangle=acos($arccosthis);
$dangle=($rangle/3.1415926535897931)*180;
print $a."".$b."\n";
print "Angle = ".$dangle."\n";
Perl (programming language)
Opinions expressed by DZone contributors are their own.
Comments