When working with spherical coordinates it is often useful to be able to perform cross and dot product calculations. The cross product of two Cartesian coordinates, and is defined as a Cartesian coordinates that is perpendicular to the plane of and .
The following algorithm calculates the cross product of two Cartesian coordinates. This algorithm takes in two Cartesian coordinates and returns a Cartesian coordinate representing the cross product vector.
var x = p1.Y*p2.Z - p1.Z*p2.Y;
var y = p1.Z*p2.X - p1.X*p2.Z;
var z = p1.X*p2.Y - p1.Y*p2.X;
return new Cartesian(x,y,z);
Listing 1 Cross Product function
The following algorithm calculates the dot product of two Cartesian coordinates. This algorithm takes in two Cartesian coordinates and returns a float representing the dot product.
Listing 2 Dot Production function
The following post has additional information on the Cartesian object: http://rbrundritt.spaces.live.com/blog/cns!E7DBA9A4BFD458C5!280.entry