judge&jury

09-11-2000, 03:45 PM

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

thanx in advance

thanx in advance

View Full Version : dot & cross products

judge&jury

09-11-2000, 03:45 PM

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

thanx in advance

thanx in advance

DPalomo

09-11-2000, 11:08 PM

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_1*x_2 + y_1*y_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).]

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_1*x_2 + y_1*y_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).]

judge&jury

09-11-2000, 11:15 PM

thanx a whole heap man, i think i ought to go back to the basic stuff for a while. Thanks nonetheless http://www.opengl.org/discussion_boards/ubb/smile.gif

David

09-15-2000, 05:46 AM

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).]

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).]

judge&jury

09-15-2000, 06:08 AM

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 http://www.opengl.org/discussion_boards/ubb/smile.gif

sorry if this is a stupid question...

thanks again for your help http://www.opengl.org/discussion_boards/ubb/smile.gif

Bob

09-15-2000, 07:32 AM

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.

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.

grady

09-15-2000, 10:16 AM

grady

09-15-2000, 10:34 AM

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. http://www.opengl.org/discussion_boards/ubb/wink.gif

judge&jury

09-15-2000, 04:37 PM

thanks a whole ton guys http://www.opengl.org/discussion_boards/ubb/smile.gif

i'm pretty clear on these things now, thanks again http://www.opengl.org/discussion_boards/ubb/smile.gif

i'm pretty clear on these things now, thanks again http://www.opengl.org/discussion_boards/ubb/smile.gif

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.