Cross and Dot products

Theory

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, clip_image002 and clip_image004 is defined as a Cartesian coordinates that is perpendicular to the plane of clip_image002[1] and clip_image004[1].

clip_image006

Where

clip_image008

The dot product of two Cartesian coordinates, clip_image002[2] and clip_image004[2] is defined as a length of the projection of clip_image004[3] onto the vector clip_image002[3].

clip_image010

Application

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.

function crossProduct(p1,p2)
{
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.

function dotProduct(p1,p2)
{
return p1.X*p2.X+p1.Y*p2.Y+p1.Z*p2.Z;
}

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s