Archived

This topic is now archived and is closed to further replies.

Cross Products?

This topic is 6078 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How does one calculate cross products in c? I have looked at this web page (http://www.physics.uoguelph.ca/tutorials/torque/Q.torque.cross.html) and other books - I get the general concept...but I have no clue how do work out a real example with real numbers. I have my vectors a and b and want to create the normal vector c. Lets say that I have a polygon, side of a square and wnat to create a normal vector for that polygon for lighting purposes....how would I do that? The polygons are created dynamically, so I need to create there normal vectors dynamically too...but how? Can anyone give me a real example with real numbers? Thanks! Thanks! John William Blair

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Take a look here: http://amir.cfxweb.net/mb3.html

Share this post


Link to post
Share on other sites
I am still very confused. I understand how to use the cross product...but it fails to produce a normal vector when we have a polygon on the xy plane...becuase z is allways zero. Isn''t there an easier way?


Share this post


Link to post
Share on other sites
Well, if you really are using the right formula, then it will never fail to give you a normal. The following formula will give the cross product.

result.x = a.y * b.z - a.z * b.y;
result.y = a.z * b.x - a.x * b.z;
result.z = a.x * b.y - a.y * b.x;

When the polygon is in the xy plane, then z is zero for both vectors, and thus both the x and y components of the cross product will be 0. Only the z component of the cross product will be something other than 0. To get a normal from the cross product, the cross product has to be divided by the magnitude of the cross product resulting in a vector of length 1. Once again, for a polygon in the xy plane, the x and y components of the normal will be 0, and the z component should be +/- 1 depending on which way the polygon is facing.

for example, if you have a triangle with vertices
<0,0,0>, <1,0,0>, <0,1,0>

you will get the vectors
<1,0,0> and <-1,1,0>

Cross product = <1,0,0> x <-1,1,0> = <0,0,1>

In this case the cross product is already of length 1, so it is the normal vector.

Hope this helps!

Share this post


Link to post
Share on other sites