DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Using Perl's Math-class

01.17.2007
| 864 views |
  • submit to reddit
        A 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";