Jump to content
  • Advertisement
Sign in to follow this  
Sijmen

Dot and cross product of a vector

This topic is 5066 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

Hi there, I'm currently reading 'Beginning Math and Physics for Game Programming'. Right now I'm at the part about vectors. About this, I have these questions: - What exactly does the dot product of a vector represent? I know how to calculate it, I know that when A.B = 0 then they are perpendicular, that when A.B < 0 the angle is > 90 degrees, and that when A.B > 0 the angle is < 90 degrees.. but.. I don't get the clue. What /is/ the number? - I don't get anything of the vector cross product. I can read the formula, but I still don't know what it does. Could someone please explain this? Thanks

Share this post


Link to post
Share on other sites
Advertisement
I'm learning vectors right now at school.
The dot product of a vector and itself is also the magnitude squared.

||v||^2 = v . v

Its used to find the angle between two vectors, the formula is

v . u
------------- = cos( X )
||v|| * ||u||

where X is the angle between the two vectors.

[Edited by - chaosgame on January 6, 2005 1:48:06 PM]

Share this post


Link to post
Share on other sites
What exactly does the dot product of a vector represent?

ab : Projection of b on a multiplied by |a| or Projection of a on b multiplied by |b|

I don't get anything of the vector cross product.

Geometrically, ab is a vector that is perpendicular (and forms a direct base if the two vectors aren't colinear) to a and b. Its magnitude is equal to the area of the parallelogram formed by a and b.

In R3, a⋅(bc) is the determinant of the 3x3 [a,b,c] matrix.

Share this post


Link to post
Share on other sites
Well, given two vectors A and B:

A.B = |A|*|B|*cos(theta) = A.x*B.x + A.y*B.y + ...

Where theta is the angle between the two vectors. |A| and |B| are the magnitudes of the vectors. If the dot product is 0, then you know that either you have a vector of magnitude 0 (but you should usually know if you do or not) or the value cos(theta) is 0. Some simple inverse trig will tell you that cos(theta) = 0 => theta = 90 degrees. Then, you just need to draw out curve graphing theta against cos(theta). Everywhere less than 90 degrees will yield a cosine greater than 0 and anything from 90 to 180 degrees (actually 270, but you rarely if ever use convex angles) will give you a negative cosine value.

Now assuming you know the formula for the magnitude of a vector, it should be clear that a vector cannot have a negative magnitude, so you know right there that the cosine of the angle between the two vectors is the only part that can determine whether the dot product is positive or negative.

As for cross products, the simple answer is that the cross product of two vectors will give you a vector that is perpendicular to the plane defined by the two vectors you are crossing. If the two vectors are parallel, then it is impossible to determine a vector perpendicular to them as two parallel vectors cannot define a plane.

I'm truly surprised that your book isn't explaining any of that.

-Auron

Share this post


Link to post
Share on other sites
Quote:
Original post by chaosgame
I'm learning vectors right now at school. The dot product is also the magnitude squared. Its used to find the angle between two vectors, the formula is

v . u
------------- = cos( X )
||v|| * ||u||

where X is the angle between the two vectors.


I'm also a bit uncomfortable with the notation - what does the || || indicate? And by *, do you mean the cross thingy?


/edit:

Wow, that's alot of posts since I clicked the 'new post' button. But yes, the book does explain these things, but somehow, I cannot see trough. I can't get the point. To be honest, I still can't.

Maybe some answers on these questions will make it clearer, too:

- What does the |x| notation indicate?
- What does the ||x|| notation indicate?
- And what is the difference between ||a.b|| and ||a||.||b||?

Share this post


Link to post
Share on other sites
Quote:
- What does the |x| notation indicate?
Either the absolute value of the number x, or the length of the vector x.

Quote:
- What does the ||x|| notation indicate?
Same as above, different notation.

Quote:
- And what is the difference between ||a.b|| and ||a||.||b||?

Assuming a and b are vectors, ||a.b|| is the absolute value of the dot product between a and b. The dot product is only defined for vectors and the length of a vector is a number. So ||a||.||b|| is not legal.

[edit]Corrected some errors[/edit]

Share this post


Link to post
Share on other sites
v, u are vectors.

||v|| is a float and is the length of the vector v.

* is obviously a normal multiplication, but in C++, it can be overload to do dot products (or cross products, although I'd use another operator).

I have

// 'scalar product', or 'dot product'
float Vector::operator * (const Vector& V) const { return x*V.x + y*V.y + z*V.z; }

but also

// 'scalar multiplication', or 'uniform scaling'
Vector Vector::operator * (float k) const { return Vector(x*k, y*k, z*k); }

this is generally acceptable to have the same operator do two different thing, since the two parameters are different, as well as the type of the value returned.

Share this post


Link to post
Share on other sites
you have to distinguish between scalars (int, float shorts...) and vectors, and their 'special' relationship with their operators. Can be confusing, but maths generally is. like '*' and '.', for two vector operands, it's a dot product, for a vector and a float, it's a multiplication, for two floats, it's also a multiplication. ||V|| and |V| are the norm (aka length) of the vector 'V', |k| is absolute value of scalar 'k'.

for vectors, I use Uppercase notations ('V', 'A', 'Direction') and lowercase notation for scalars ('vector_length', 'scale', 'd') to make it easier.

[Edited by - oliii on January 5, 2005 6:26:48 PM]

Share this post


Link to post
Share on other sites
Quote:
And by *, do you mean the cross thingy?


||a|| and ||b|| are both scalars, so it's an ordinary multiplication.

Quote:
Original post by greldik
So ||a||.||b|| is not legal.


||a||.||b|| is exactly the same thing as ||a||*||b|| : a scalar multiplication.

Incidentally, back home, we use for the cross product (but the HTML entities reference pointed to ⊗ so that's what I used).

Share this post


Link to post
Share on other sites
I also use '^' for cross, since it's also a valid C++ operator and i used to use '^' for calculating tensors in mechanics (a looong time ago).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!