Advertisement

Dot Products

Started by August 06, 2002 11:31 AM
6 comments, last by sic_nemesis 22 years, 6 months ago
helo, welcome to the beggining of my lack of understanding of dot products! All i have managed to discover through my google searching and text book reading is that the dot product DOES SOMETHING! Ive seen drawings of what the dot product looks like between 2 vectors, but i really do not understand what they do, why they do it, or what they are good for. For example, why would i ever need to take the dot product between 2 vectors? What exactly sdoes this number represent? how do i go about using it? these are all things that i dont understand. PLease dont tell me that the dopt product is (formula). I know that part i just dont know WHAT it is... also, i only really know 2d, so if you could explain in terms of 2d it would be nice, if not, go ahead and explain in 3d, im trying to learn it anyways. thanks
______________blah
One use of the dot product is to find the angle between two vectors:

θ = angle between two vectors
Vectors A and B must be normalized to work correctly

cos( θ ) = A dot B

To normalize a vector you divide each of its components by its length.

length = sqrt(x2+y2...)

The ... is for additional variables (i.e. z2) that would evaluate to zero if not considered.

This concept does extend into 3D although you have to think about it a little more. θ then represents the angle between the two vectors, but only across the plane the two vectors share.

I know there are several other ways to use the dot product but I'm not sure how to use them correctly.

I hope this helps a bit.

_____________________________

And the Phoenix shall rise from the ashes...

--Thunder_Hawk -- ¦þ
______________________________



[edited by - Thunder_Hawk on August 6, 2002 12:55:42 PM]
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
Advertisement
so the only real use of finding the dot product is to get the angle between vectors? (unit vectors.. how do i get the unit vector again..isnt a nromalized vector a vector that has been turned into a unit vector? dont i just divide by its length?)

anyways, thats it? :x

isnt that almost the same as the atan() function? (except im pretty sure atan() wont work in 3d, but in 2D anyways)

and what happens when i take the dot product of 2 vectors that are not normalized/in unit vector form?

thanks
______________blah
Dot products involving unit vectors (length 1) are very useful.

For example, if you had a set of vectors defining your viewpoint (up vector, left vector, forward vector, all perpendicular to each other, and length 1), you could take the offset vector leading from the viewpoint to a point in 3D space, and calculate the left offset, up offset and forward offset to that point by performing a dot product with the viewpoint vectors.

Dot product is also a quick way to figure out if a point is in front or behind an object by performing a dot product with the offset vector and the forward vector for the object.

Figuring out what you need to do with dot products will depend more on what conditions you need to calculate or check for, and how dot products will help you to do that.

By the way, if the length of one of the vectors in the dot product is not 1, then the resulting value is multiplied by the magnitude of the vector that is not 1. (The magnitudes of the vectors factor directly into the resulting value of the dot product)

a * b = cos(angle between a and b) |a| |b| (I think that's right)

[edited by - Waverider on August 6, 2002 2:40:18 PM]
It's not what you're taught, it's what you learn.
No, it''s not the only use. It can also be used to determine facing. For example if you have a vectore (1, 0) in 2D representing the direction the player is facing, and another vector (-.707, .707) representing a billboard, calculating the dot product and getting a negative value quickly tells you the character is looking at the front of the billboard, not the back. Just a quick use without finding the angle.

It can also be used for distance. Again say (1, 0) represents the player and say there is a tree at (4,2) Calculating the dot product here will give you the disance to the tree, parallel to the way the character is facing, or in this case 4.

Another use is for shading, by taking the negative dot product of a surface normal and a normalized vector to a light (basically taking the angle without the cosine) and using that as a coefficient for the RGB color of the surface, <= 0 meaning there is no light.

Just some other possibilities.

tj963
tj963
ok, let me know if i understand this:

about the light thing: When the value is <=0, thats when the surface is facing away from the lgiht source correct? ...but what exactly is a surface normal..?

say i have 2 vectors... (10,15) and (3,27)...
how would i go about normalizing? do i just divide the vector with the smallest lenght(magnitude?) by the one with the longest? and then set the longest one to (1,1)?

also, say i got the dot product of them the way they are.. then
Magnitude of largest * dot product of both when in unit form = dot product of both when not in unit form?

thanks again for the help, im actually starting to under stand this

that thing about the fplayer is facing the tree at a distance of 4 kind of has me confused... ikll plug in some numbers when i get home to figure that out a bit
______________blah
Advertisement
oh yeah,
what is this sigh:
(i see it on the equation for gettin g the point sof intersection on a circle, and sometimes with dot products)

||V1 - V0||

______________blah
Hi!
Normalize a vector A = A / |A| = A / sqrt(A.x^2 + A.y^2 + A.z^2)
Sometimes people write ||A|| its the same thing as |A|.

(edit)

I think you have it all wrong.

If you have 2 vectors you divide EACH vector whit IT'S LENGTH to get the vectors normalized.

Normalized(A) = A / |A| = (A.x / |A|, A.y / |A|, A.z / |A|)

If you want the angle and you have 2 none nomalized vectors then the angle = acos((A dotproduct B) / (|A| * |B|))

[edited by - axodoss on August 6, 2002 3:40:20 PM]

This topic is closed to new replies.

Advertisement