Skip to main content
gamedev.net
🔒 Locked

Vectors

Started by Mr_Ridd Oct 29, 2004 at 4:16 AM 4 replies 700+ views
Original Post
Mr_Ridd
Mr_Ridd
Hey I know this probably a basic question but... How does a vector represent magnitude and direction from only three values. x, y, z ? Thanks
The ability to succeed is the ability to adapt
jacksaccountongamedev
jacksaccountongamedev
Picture drawing a line from the origin ( 0,0,0 ) to the vector point (x,y,z). The direction and length of this line is the direction and length of the vector. This is how a vector indicates direction and size.

Hope this helps,
Jackson Allan
Mr_Ridd
Mr_Ridd
So if there is no destination vector, you will always use 0,0,0?
The ability to succeed is the ability to adapt
jacksaccountongamedev
jacksaccountongamedev
The direction of a vector is always from 0,0,0 to the vector points. However, you will often wish to merely use a vector as a position in space, in which case the direction and size would not come into play.
Here is a half-decent brief explanation of vectors. The article deals with two dimensions but the same principals apply to 3d vectors. There are some good links in the forum FAQ to more in-depth explanations and articles regarding vectors.

Anyhow, good luck
Jackson Allan
LilBudyWizer
LilBudyWizer
A vector has no position. 60mph due north, if the world were flat, is 60mph due north no matter where you are.
Keys to success: Ability, ambition and opportunity.
Zakwayda
Zakwayda
Just to elaborate a little on what has been said before...

Some confusion can be caused by the convention in 3d programming of representing 'points' using 'vectors'. As has been said, a vector has no position - it is a relative measure only, i.e. 5 up and 3 left from some other position.

Most people use a vector class of some sort to represent points in 3d space. What we're really doing is defining a vector from the origin to the point we wish to represent.

These inconsistencies can be smoothed out by using homogenous coordinates (i.e. adding an additional vector component 'w'). In 3d, a homogenous coordinate is the 4d vector x, y, z, w. To convert it to a specific point in 3d, you divide x, y, and z by w. If w is 0, you get a 'point at infinity', which represents direction and magnitude only, i.e. a vector.

So, if one were to use 4d vectors in place of 3d, all points (such as triangle vertices) would have a w component of 1, while all vectors (such as normals, axes, etc.) would have a w component of 0.

The cool thing is that with this representation, all the math comes out right. 4x4 matrices transform points but only rotate vectors, as they should, and adding points and vectors all works out as it should as well.

In practice doing it this way involves a lot of superfluous multiplication and division, and isn't really very efficient, so most people don't actually use homogenous coordinates (except in cases, such as projection, where they are definitely needed). Most of the time we know a priori whether we're dealing with vectors or points, so we just represent them all the same way (as a 3d vector) and perform whatever operations are appropriate.

Anyway, I'm no math expert, so I may have gotten a detail or term wrong somewhere. But that's the general idea.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.