Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


A few quick math questions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 littletray26   Members   -  Reputation: 267

Like
0Likes
Like

Posted 31 May 2012 - 05:33 PM

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 Posted Image

Thanks

Edited by littletray26, 31 May 2012 - 05:35 PM.

The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky :)

Sponsor:

#2 jefferytitan   Crossbones+   -  Reputation: 2242

Like
0Likes
Like

Posted 31 May 2012 - 07:02 PM

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.

#3 hupsilardee   Members   -  Reputation: 487

Like
1Likes
Like

Posted 31 May 2012 - 07:04 PM

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|2 - 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 Posted Image

#4 Washu   Senior Moderators   -  Reputation: 5416

Like
0Likes
Like

Posted 31 May 2012 - 07:05 PM

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, 31 May 2012 - 07:06 PM.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ScapeCode - Blog | SlimDX


#5 littletray26   Members   -  Reputation: 267

Like
0Likes
Like

Posted 31 May 2012 - 10:28 PM

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 :/
The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky :)

#6 littletray26   Members   -  Reputation: 267

Like
0Likes
Like

Posted 31 May 2012 - 10:32 PM

Sorry, D3DXVec3Dot() returns a number equal to (v1.x * v2.x + v1.y * v2.y + v1.z + v2.z) ?

What is the use of this?
The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky :)

#7 littletray26   Members   -  Reputation: 267

Like
0Likes
Like

Posted 31 May 2012 - 10:42 PM

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?
The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky :)

#8 jefferytitan   Crossbones+   -  Reputation: 2242

Like
0Likes
Like

Posted 01 June 2012 - 12:02 AM

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

#9 Tom KQT   Members   -  Reputation: 1620

Like
0Likes
Like

Posted 01 June 2012 - 12:27 AM


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?


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:
magnitude2 = x2 + y2 + z2
Where x, y, z are the elements of the vector. So in your example:
magnitude2 = 02 + 102 + 52
magnitude2 = 125
magnitude = 11.18034...

Edited by Tom KQT, 01 June 2012 - 12:28 AM.


#10 littletray26   Members   -  Reputation: 267

Like
0Likes
Like

Posted 01 June 2012 - 01:50 AM

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
The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky :)

#11 btower   Members   -  Reputation: 980

Like
1Likes
Like

Posted 01 June 2012 - 02:13 AM

I refer you to this blog post I found that explains all the concepts above in plain English with game-related examples. Sounds like it's exactly what you're looking for: http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-2/

Hope it helps!

#12 kauna   Crossbones+   -  Reputation: 2832

Like
0Likes
Like

Posted 01 June 2012 - 02:39 AM

Normalization - Takes the 2 vectors and gives it a magnitude of 1. Same direction, different length.


Normalization - takes one vector, returns another vector with same direction, but length / magnitude of 1.

Dot product is actually used almost everywhere. For example, a simple lighting model would calculate the dot product between surface normal and light direction to get the light intensity at each fragment or vertex. If the surface normal and light directions aren't normalized vectors, the light intensity will be wrong (ie. scaled by the length of the normals).


D3DXVec3TransformCoord requires a little understanding of vectors and matrices. A vector may define many things, including a position in some space (for example local/object or world space).

- for example, if you model a 3D object, you'd typically create it around origo. In order to place this object else where than in origo in your game engine, you'll need a translation matrix which may be used to transform the object to a different location. Practically, a translation matrix contains a offset vector which tells how much the mesh has to be moved in certain direction. The matrix may contain also rotations so that the object may be rotated to different directions.

So a matrix can be used to transform a position from one space to another.

In computer graphics, typically you'll have several spaces such as :

- local space. Each object is defined in local space
- world space. Each object has a transform matrix which is used to transform from local space to world space.
- view space. Your camera has a camera matrix, which is used to transform position from world space to view space.
- projection/clip space. Your camera has a projection matrix which is used to transform a position from view space to projection space

And to mess things up a bit more, vector matrix multiply is practically few dot products.


Best regards!

Edited by kauna, 01 June 2012 - 04:59 AM.


#13 littletray26   Members   -  Reputation: 267

Like
0Likes
Like

Posted 01 June 2012 - 10:56 PM

I refer you to this blog post I found that explains all the concepts above in plain English with game-related examples. Sounds like it's exactly what you're looking for: http://blog.wolfire....elopers-part-2/

Hope it helps!


That's awesome! I saved it for future reference ;) Thank you!
The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky :)

#14 littletray26   Members   -  Reputation: 267

Like
0Likes
Like

Posted 01 June 2012 - 10:56 PM


Normalization - Takes the 2 vectors and gives it a magnitude of 1. Same direction, different length.


Normalization - takes one vector, returns another vector with same direction, but length / magnitude of 1.

Dot product is actually used almost everywhere. For example, a simple lighting model would calculate the dot product between surface normal and light direction to get the light intensity at each fragment or vertex. If the surface normal and light directions aren't normalized vectors, the light intensity will be wrong (ie. scaled by the length of the normals).


D3DXVec3TransformCoord requires a little understanding of vectors and matrices. A vector may define many things, including a position in some space (for example local/object or world space).

- for example, if you model a 3D object, you'd typically create it around origo. In order to place this object else where than in origo in your game engine, you'll need a translation matrix which may be used to transform the object to a different location. Practically, a translation matrix contains a offset vector which tells how much the mesh has to be moved in certain direction. The matrix may contain also rotations so that the object may be rotated to different directions.

So a matrix can be used to transform a position from one space to another.

In computer graphics, typically you'll have several spaces such as :

- local space. Each object is defined in local space
- world space. Each object has a transform matrix which is used to transform from local space to world space.
- view space. Your camera has a camera matrix, which is used to transform position from world space to view space.
- projection/clip space. Your camera has a projection matrix which is used to transform a position from view space to projection space

And to mess things up a bit more, vector matrix multiply is practically few dot products.


Best regards!


Thank you for that lesson in math ;) :)
The majority of Internet Explorer users don't understand the concept of a browsing application, or that there are options.
They just see the big blue 'e' and think "Internet". The thought process usually does not get much deeper than that.

Worms are the weirdest and nicest creatures, and will one day prove themselves to the world.

I love the word Clicky :)

#15 taby   Members   -  Reputation: 336

Like
0Likes
Like

Posted 01 June 2012 - 11:54 PM

The dot product is very intuitive especially when you use two unit length (... normalized... magnitude of 1) vectors for the input. If the vectors are pointing in the same direction, then the dot product is 1. If they are orthogonal (at right angle) then dot prod is 0. If they are pointing in opposite direction the dot prod is -1.

Now, if you go ahead and plot arccos (see http://www.wolframal...os from 1 to -1), you will see that the dot prod of two unit vectors fed into acos gives you the angle between the vectors in radians. That is, acos(1) is 0, acos(0) is pi/2 and acos(-1) is pi.

Of course 0 radians is 0 degrees, pi/2 radians is 90 degrees, and pi radians is 180 degrees.

Dot prod is used for lighting calculations, and friction between two surfaces, and backface culling, and all kinds of other things. Try experimenting with non-unit vectors to see how it affects the dot product. Fun times.

I see that the link given above has a similar explanation. :) Oh well.

Edited by taby, 02 June 2012 - 12:11 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS