Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Cartesian 3-Vectors

by Zaxo (Archbishop)
on Jun 18, 2001 at 10:56 UTC ( #89236=snippet: print w/ replies, xml ) Need Help??


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 {

# Cartesian 3-vector cross product
# returns reference to array over [0..2]
sub cross {

# length of a Cartesian 3-vector
# returns number
sub norm {

# angle between two Cartesian 3-vectors
# returns number: angle in radians
sub arc {
    atan2 norm(cross($_[0],$_[1])), dot($_[0],$_[1]);
Comment on Cartesian 3-Vectors
Download Code

Back to Snippets Section

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://89236]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2016-02-08 13:29 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (276 votes), past polls