With the untested code below, you can probably make it "Normalize" for you:
Update 1:Fixed "print" statement (Original post needed +Normalize(), and tested. It works correctly, producing the output: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 2: I found out that the "versor()" method does exactly the same thing as Normalize() , and both produce identical results.Norm = {0.285714285714286, -0.428571428571429, 0.857142857142857} Versor= {0.285714285714286, -0.428571428571429, 0.857142857142857}
All power corrupts, but we need electricity.
In reply to Re^5: The problem of getting the unit vector "Undefined subroutine &main::Normalize"
by NetWallah
in thread The problem of getting the unit vector "Undefined subroutine &main::Normalize"
by windcrazy86
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |