use strict;
use warnings;
use Math::Vector::Real;
my $v = V(2,-3,6); # Your example vector
print "Norm = ", Normalize ($v),"\n";
print "Versor= ", $v->versor(),"\n";
sub Normalize{
my ($v) = @_; # parameter is a single vector
my $result = $v->div ( $v->abs() );
# abs of vector (x,y,z) = sqrt(x**2 + y**2 + z**2)
return $result;
}
Update 1:Fixed "print" statement (Original post needed +Normalize(), and tested. It works correctly, producing the output:
Norm = {0.285714285714286, -0.428571428571429, 0.857142857142857}
Versor= {0.285714285714286, -0.428571428571429, 0.857142857142857}
Update 2: I found out that the "versor()" method does exactly the same thing as Normalize() , and both produce identical results.
All power corrupts, but we need electricity.
|