Vector confusion

This topic is 2977 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, Im a little bit stuck on vectors. As i understand vectors should have direction and length, therefore requiring two points (start and end). But i see in all game engines that vectors are usually only consist of a single x,y,z coordinates, meaning they only have one point and therefore cant have a direction.

My confusion comes in when it comes to normalizing. How can you normalize a vector with only one point. If i have a vector (5,5) does normalizing give me a unit length vector based on the points (0,0) to (5,5). If not, where the hell is it getting its direction from.

Share on other sites
Yeah, usually assumed to have an origin of (0,0). (1,1) & (2,2) have same directions, different lengths. Translate the origin for it to actually be useful

Share on other sites
This idea of vectors as little arrows with a starting point and an ending point is really really bad. This is how I was introduced to vectors when I was in high school and it confused me for years. Thank god for college-level linear algebra.

Quick introduction to vectors: A vector space is a set of things that can be added, subtracted and scaled, and where these operations satisfy some basic properties that you would expect (look up a formal definition if you want; this is just an explanation).

The vector space we are interested in is that formed by triplets of real numbers, (x,y,z). You can add two triplets together, you can subtract them and you can scale a triplet by multiplying each component by the scale.

If you have questions about the relationship between points and vectors (which is a bit confusing), I can try to answer them.

Share on other sites
Vector, especially in game programming, can in fact mean two things:
- position
- direction & amplitude

In fact, the first one (position) is just a "point", but it all meets here and the terms are kinda overlapping.

In any case, we are talking always just about an array of numbers, typically 2 (for 2D) or 3 (for 3D). You'll also see 4 element vectors, those are important for matrix transformations, but that's a bit too complicated for now.

So, when working in 3D, you have an "array" of 3 values, for example:
(1,6,7)
and what it represents depends on you, on why did you create this vector and how are you using it.

a) It can be a position of some game object, then it means that the coordinates of the object are:
x = 1
y = 6
z = 7
This can also be called a "position vector".
While it is just a "point", it still can be imagined also as a vector in the meaning of the arrow we all remember from school. You just need to make the 0 point (0,0,0) the beginning and (1,6,7) the end of the arrow.

b) It could also be a vector defining for example velocity of some game object. In this case the individual components means velocities along the coordinate system axes:
velocity along x = 1
velocity along y = 6
velocity along z = 7
You could also draw the vector as an arrow now, because you know how big and at what angle the arrow will be. And you can place it anywhere, because the location of the vector doesn't matter. To make it clear, you would place it over the object that is moving with this velocity, to see where and how quickly will the object move. (The arrow now has a real meaning.)

-----------------

Now we will introduce another aspect of vectors and one can get confused very quickly, but there's so much to say about them and you fully understand them only when you know all this little aspects :)

You say vectors, as you understand them, require two points to define them. Yep, you need two points to draw an arrow. And a vector between two points is calculated as a substraction of those two points (the ending minus the beginning).
Let's have two points, A and B:
A = [0, 6, 3]
B = [4, 1, 2]
vector from B to A is
v = (-4, 5, 1)
(A minus B, component by component).
If you draw this on a paper and then move points A and B both equally, the vector between them will still look the same, it will just change position on your paper. But it will still look the same - so if it was a vector of velocity, the velocity would not change. So, if you move A and B both at the same time exactly that way to place B at 0,0,0, you would see that A is equal to -4,5,1 which is our vector v. Now you need just three numbers (not six) to describe the vector. Yes, you modified its location on your paper while doing this, but it doesn't matter.

Share on other sites
Quote:
 Original post by yokkotorroHi, Im a little bit stuck on vectors. As i understand vectors should have direction and length, therefore requiring two points (start and end).

Nope. Vectors are only one set of numbers that define a direction. They have an implied origin at 0. The length is the distance to 0.

Two points give you a line segment. A line segment can also be described by one point "start" and one vector "vec"(direction/length), where "end" is implied as start+vec.

Quote:
 My confusion comes in when it comes to normalizing. How can you normalize a vector with only one point. If i have a vector (5,5) does normalizing give me a unit length vector based on the points (0,0) to (5,5). If not, where the hell is it getting its direction from.

Yup. You normalize <5,5> by dividing by the length (root(50)) because the assumed origin is (0,0).

To specify stuff in most 3d systems you use 3 things: Vectors, Points, Matrices. A point and a vector are in fact different but look similar. You can't add points, but you can subtract them to get a vector. You can add and subtract vectors to get other vectors. You can add and subtract vectors from points to get other points.
Matrices are more advanced, but let you move and rotate your vectors and points. As well as there are other linear algebra transformations you can do with your vectors to get cool information from them, like dotproducts(useful for finding the angle between vectors) and crossproducts(used for many things, but can be used to tell if one direction is to the left/right of another).

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 9
• 13
• 85
• 11
• 10
• Forum Statistics

• Total Topics
632969
• Total Posts
3009599
• Who's Online (See full list)

There are no registered users currently online

×

Important Information

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!