http://qs321.pair.com?node_id=89236

These functions implement common operations on three dimensional vectors. Applications may use these by transforming to rectangular coordinates before calling the functions.

# These functions all take references to arrays over [0..2] without # modifying the arguments. Arguments assume Cartesian(x,y,z) geometry # This could be expanded to a module. # Cartesian 3-vector dot product sub dot { $_[0]->[0]*$_[1]->[0]+$_[0]->[1]*$_[1]->[1]+$_[0]->[2]*$_[1]->[2]; } # Cartesian 3-vector cross product # returns reference to array over [0..2] sub cross { [$_[0]->[1]*$_[1]->[2]-$_[0]->[2]*$_[1]->[1], $_[0]->[2]*$_[1]->[0]-$_[0]->[0]*$_[1]->[2], $_[0]->[0]*$_[1]->[1]-$_[0]->[1]*$_[1]->[0]]; } # length of a Cartesian 3-vector # returns number sub norm { sqrt(dot($_[0],$_[0])); } # angle between two Cartesian 3-vectors # returns number: angle in radians sub arc { atan2 norm(cross($_[0],$_[1])), dot($_[0],$_[1]); }