 # dot & cross products

im very new to opengl, and not quite sure which bb this belongs to, but im wondering what dot and cross products are…

I think this is off-topic, anyway here you have some math-theory:

Dot and Cross products are calculations between vectors (and matrices).

The dot product between two vectors <x_1, y_1, z_1> and <x_2, y_2, z_3> is calculated like so:

p_1 * p_2 = x_1x_2 + y_1y_2 + z_1*z_2
If p_1 and p_2 are unit vectors then the dot product is the cosine of the angle between them, so the angle itself can be calculated by taking the inverse cosine of the dot product:

theta = invcos (p_1 * p_2)
Fortunately you’ll often only need the cosine of the angle between 2 vectors and not the angle itself, so the expensive step of calculating the inverse cosine can be skipped.

(From ‘Introduction to Algorithms’, Thoma H. Cormen, et al., 1996, MIT press)

For two vectors p_1 and p_2:
The Crossproduct p_1 x p_2 can be interpreted as the signed area of the parallelogram formed by the points (0,0), p_1, p_2 and (p_1 + p_2)( = (x_1 + x_2, y_1 + y_2)).
An equivalent, but more useful, definition gives the crossproduct as the determinant of a matrix (It is a vector that is perpendicular to both p_1 and p_2 according to the right-hand rule and whose magnitude is |x_1y_2 - x_2y_1|).

p_1 x p_2 = det | x_1 x_2 |
| y_1 y_2 |

``````      = x_1y_2 - x_2y_1

= -p_2 x p_1
``````

Hope this helps,

Daniel Palomo van Es

[This message has been edited by DPalomo (edited 09-12-2000).]

thanx a whole heap man, i think i ought to go back to the basic stuff for a while. Thanks nonetheless Judge,

It is not as complicated as you think…

Simply put, the dot product is used to find the cosine of an angle between two vectors.
(ie apply inverse cos to the result gives you the angle in degrees)

The cross product used to find a vector perpendicular to (at right angles to) two vectors.

Here is a nice scenario…

A triangle has three points which can be used to create two vectors.

use these vectors with the cross product to obtain the normal vector (vector sticking out of the polygon)

Now, by calculating the angle between the ‘normal’ and the viewing vector(direction the viewer is looking at) (using the dot product) you can calculate light intensities etc.

One particular use is back face culling, if the angle between the viewing vector and a polygon normal is greater than 90 degrees, then dont draw the polygon, as you cant see it…

Hopefully I havent confused you even more. A lot of web sites will tell you how to create vectors, calculate dot and cross products…

David

[This message has been edited by David (edited 09-15-2000).]

thanks david, this certainly cleared things up a lot, although i still cant create a picture of the cross product in my mind. would the perpendicular vector found by the cross product be, say of the three points were -1 -1 -1, -1 -1 1 and 1 -1 0, which direction would the normal vector be pointing?

sorry if this is a stupid question…

thanks again for your help I haven’t calculated this at all, but I think the normal (i.e. the crossproduct) will be (0,1,0) or (0,-1.0) depending on how (in what order) you cross the two vectors. Crossing them the other way will cause the normal to point in the oposite direction. In other words, (v1 x v2) != (v2 x v1) and (v1 x v2) = -1*(v2 x v1).

So, how do I calculate this in my head like that? All points got the same y-coordinate, i.e. they all lie on the y=-1 plane, and the y=-1 plane got (0,1 (or -1),0 as normal.

If you are having trouble seeing the crossproduct, just think of it as a vector telling you in what direction a plane, like a polygon, is pointing.

Ok, i cant figure out how to put pictures up in the messages, though i’ve seen it done before. so i emailed you pictures of the dot and cross products. with an explanation of how i understand it. hope it helps. thanks a whole ton guys i’m pretty clear on these things now, thanks again 