Jump to content
  • Advertisement
Sign in to follow this  
littletray26

A few quick math questions

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

Okay, I picked up a book yesterday to help me further understand some math concepts to do with Vectors and Matrices. I'll list a few, correct me if I'm wrong? I just need to get my head around these.

D3DXVec3Normalize() - What does this do exactly? if I put in a vector (0, 5, 4.33) what would that return? (0, 1, 1) ??

D3DXVec3TransformCoord() - I used this yesterday in making a First Person Camera, though I do not know what it does. Example?

D3DXVec3Dot() - I have no idea what this does.

D3DXVec3Cross() - I think I know what this does. You give it 2 Vectors and it returns a Vector that is Right Angle to both given Vectors?

========================================

Can someone explain these to me better? Please don't suggest I go do a course or read a book because I'm not really all that good with Mathso I need an explanation is simple ENGLISH rather than a bunch of math equations tongue.png

Thanks Edited by littletray26

Share this post


Link to post
Share on other sites
Advertisement
Just based on general 3D knowledge, I would assume:

- Normalize normalises a vector, e.g. returns a vector with the same direction but magnitude (length) of 1. http://en.wikipedia.org/wiki/Normalized_vector
- Dot gets the dot product of two vectors. http://en.wikipedia.org/wiki/Dot_product
- Cross gets the cross product of two vectors, and you're pretty much on the money with your answer. http://en.wikipedia.org/wiki/Cross_product

TransformCoord... not sure. I'm not a D3D guy.

Share this post


Link to post
Share on other sites
Normalize - divides each component of the vector by the vector's total length (the length of a vector v = (x, y, z) is computed by sqrt(x*x + y*y + z*z), also can be written as |v|). The length of the new vector is now equal to 1
.
TransformCoord - transforms the vector using the transformation defined by the matrix argument. The w component is assumed to be equal to 1. Read about matrix maths if you aren't sure what this means

Dot and Cross are two different ways of multiplying vectors together. Dot returns a single number, whereas Cross returns a vector

Dot - calculates the dot product of 2 vectors, which is the younger sibling of the cross product, speaking mathematically. If v1 = (a, b, c) and v2 = (d, e, f), then Dot(v1, v2) returns (a*d + b*e + c*f), the sum of the multiples of components from each vector. This is also equal to |v1||v2|cos(t), where t is the angle between the two vectors in 3D space, and also notice that Dot(v1, v1) = |v1||v1|cos(0) = |v1|[sup]2[/sup] - the dot product of the vector with itself is equal to the length squared, if you look at the two formulas this is easy to see. This is useful for many many things

Cross - calculates the cross product of 2 vectors. The returned vector is, as you said, perpendicular to the two vectors. If I set v3 = Cross(v1, v2), then the length of v3 is equal to: |v3| = |v1||v2|sin(t), where t is the angle between v1 and v2. Now if v1 and v2 are parallel then notice that t = 0, therefore the returned vector is (0, 0, 0).

Now the really interesting thing about Cross is that the answer is different if you pass in the two vectors in different orders, In other words, Cross(v1, v2) is not equal to Cross(v2, v1). (To be precise, Cross(v1, v2) = -Cross(v2, v1)). If you think about it, if v1 and v2 are (non-parallel) vectors, there are 2 possible vectors v3 and v4 perpendicular to v1 and v2 - they are the negative version of each other (v3 = -v4). For example, if v1 = (1, 0, 0) and v2 = (0, 1, 0) then you can easily see that v3 = (0, 0, 1) is perpendicular to both v1 and v2, but also v4 = (0, 0, -1) is as well! the Cross product of two vectors 'decides' which direction to return based on the order, so if you pass in the two arguments the other way around you will get the opposite direction.

Ok that was quite a lecture, if you still don't understand something then speak now or forever hold your peace wink.png

Share this post


Link to post
Share on other sites

D3DXVec3TransformCoord() - I used this yesterday in making a First Person Camera, though I do not know what it does. Example?


This is where a basic linear algebra course would help you. To answer your question: It transforms a vector by a transform matrix (and assumes the vector's 4th component is 1) and returns a result. Which is a fancy way of saying that it multiplies the vector into the matrix, and returns the resulting vector. Edited by Washu

Share this post


Link to post
Share on other sites
Sorry guys, you's are helping, I'm just slow :P


Normalize normalises a vector, e.g. returns a vector with the same direction but magnitude (length) of 1


What do you mean "magnitude"?

Okay so D3DXVec3Dot() returns D3DXVECTOR3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z) ?
and D3DXVec3Cross() returns either a positive or negative value the represent a Vector that right angle to the given parameters?

I still don't really understand Normalizing or TransformCoord, only that normalizing has to do with 1 :c someone dumb it down for me, please? xD

Sorry, I really want to understand these but I'm finding it hard :/

Share this post


Link to post
Share on other sites

Normalize normalises a vector, e.g. returns a vector with the same direction but magnitude (length) of 1.


Is the length the distance from the origin? So if I had like (0, 10, 0) it's length is 10? Or (0, 10, 5) is 15?

Share this post


Link to post
Share on other sites

Is the length the distance from the origin? So if I had like (0, 10, 0) it's length is 10? Or (0, 10, 5) is 15?


A vector is often used to indicate a direction rather than a point, but the distance from the origin idea is close enough for magnitude. Think of it as the distance (as the crow flies) from the origin to the point. For example, (0, 1, 0) has length 1, (0, 1, 1) has length square root of 2 (roughly 1.4142).

Share this post


Link to post
Share on other sites

[quote name='jefferytitan' timestamp='1338512556' post='4945144']
Normalize normalises a vector, e.g. returns a vector with the same direction but magnitude (length) of 1.


Is the length the distance from the origin? So if I had like (0, 10, 0) it's length is 10? Or (0, 10, 5) is 15?
[/quote]

Yes, if you picture yourself the vector as a point in 3D space, then magnitude of the vector is distance from the origin.
But your examples are wrong!

Magnitude of vector (0, 10, 0) really is 10
But magnitude of vector (0, 10, 5) isn't 15 but 11.18034...
15 is the distance from origin, but not the shortest (straight) distance, you simply went 10 units on the y axis and then 5 units parallel with the z axis, which made the resulting 15. But if you went straight from the origin to the point (0, 10, 5), you would get there in 11.18034 units.

How did I get this weird number?
Using thePythagorean theorem in 3D space:
magnitude[sup]2[/sup] = x[sup]2[/sup] + y[sup]2[/sup] + z[sup]2[/sup]
Where x, y, z are the elements of the vector. So in your example:
magnitude[sup]2[/sup] = 0[sup]2[/sup] + 10[sup]2[/sup] + 5[sup]2[/sup]
magnitude[sup]2[/sup] = 125
magnitude = 11.18034... Edited by Tom KQT

Share this post


Link to post
Share on other sites
Thank you guys! I think I get it now:

Normalization - Takes the 2 vectors and gives it a magnitude of 1. Same direction, different length.
Cross - returns a vector perpendicular to the 2 given vectors
Dot - Returns a float equal to (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z) but I don't know when you would use it?
TranformCoords - Still have no idea. Anyone want to explain this one in its most basic definition? :P

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!