Skip to main content
GameDev.net gamedev.net
🔒 Locked

Difference Between Vector and Point?

Started by X Abstract X Jun 15, 2009 at 2:34 PM 14 replies 13.7k views
Original Post
X Abstract X
X Abstract X
I'm trying to implement the Separating Axis Theorem in my game but I don't really know much about vectors. So my question is how is a vector represented? Is it just a point?
MARS_999
MARS_999
Well no, and yes...

A vector in the sense of float array[3] yes its just a point, but a vector in math/physics isn't the same as a point.

Depending on the situation or topic at hand vector can stand for different ideas.

But for a point I just use a class vec3 data type and I understand that I am really looking at a x,y,z point. Some people make a Point class to keep confusion down...
bzroom
bzroom
They can both be stored in the same amount of space, in a general case. The usage is very different though.

If you have a transformation which includes translation and rotation, and you transform a vector by this transform, the translation portion of the transform will have no effect. Vectors cannot move in space, they are just a direction.

However, if you transform a point by the compound transform, the translation will most definitely have an effect. This is the important distinction.

If you're using 3d and homogenous coordinates, the vector and point will be stored with 4 elements, xyzw. If w == 0, the value stored is a vector, if w == 1, the value stored is a point. When you mulitply this vector/point by a 4x4 matrix, you'll notice that the w value scales the influence of the 4th vector in the matrix, the translation vector. A w value of zero means the translation vector has zero influence.

Or i'm insane.

Also note:

Vec4 a(1,1,1,1); //point
Vec4 b(3,3,3,1); //another point
Vec4 ab = b-a; //vector (2,2,2,0)
mouserSVK
mouserSVK
Well, you can imagine a vector to be something that points some way (in 2D it can be pointing for example straight from left to right) and it has a length. Vector, however, does not have a position. Length and direction are the only preferences of "vector". So, you could as well imagine a vector [3, 4] to be "an arrow" starting at [0,0] and ending at point [3, 4].

Point defines a position in plane / space. So it has NO "length" or "direction". In mathematics you can not perform e.g. sum of 2 points, but you can "translate" a point using a vector (that defines the direction and length of translation).

So if you have a point somewhere at [3, 2] and a vector that [2, 0] (which, when drawn, is pointing to the right and has a length of 2 units -- as if it was an arrow from [0, 0] to [2, 0]), you can translate a point [3, 2] using this vector to [5, 2]. ([3, 2] + [2, 0] = [3 + 2, 2 + 0] = [5, 2])

Vector defines how the point has been moved - in which direction and how far.
Numsgil
Numsgil
All points are vectors (meaning they are members of vector spaces, meaning they can be added and scaled).

But not all vectors are points. Some vectors are directions.

In the case of the SAT, you're projecting point vectors on to direction vectors.
[size=2]Darwinbots - [size=2]Artificial life simulation
mouserSVK
mouserSVK
Quote:
Original post by Numsgil
All points are vectors (meaning they are members of vector spaces, meaning they can be added and scaled).

But not all vectors are points. Some vectors are directions.


I disagree. Points and vectors are two different things. All vectors have directions and magnitude, that's what points do not have. All vectors are positionless (at least in mathematics and computer graphics, maybe not in physics). Position is THE ONLY property of points.

In computer graphics, usually an affine space is made of points P and vector space V, where some axioms are defined, such as:

Having a pair of points P and Q, there exists a unique vector v, such that:

v = P - Q

etc.

Thus P - Q is a vector, P + Q is nothing. But having vectors
u = P - Q
v = Q - R

u + v is a vector w = P - R


bzroom
bzroom
The issue here is that we are now confusing terms.

He was right in saying that points and directions are both vectors. A vector just being a sequence of numbers 2,3,5,10,2.5

How you interpret it is the important part, wether it be a point, or a direction. Directions are commonly refered to as vectors, which is what is causing a bit of confusion.

So my original post was comparing and contrasting points and directions, rather than points and vectors. But since "vector" is the common term for a directional vector, that is what i used.

To go along with Numsgil, you'll notice i stored both my points and "directions" in a type called "vector."
mouserSVK
mouserSVK
Well, but when talking in terms of "points" and "vectors" I think we all know that by "vectors" we mean free vectors as defined in geometry, not exactly algebraical vectors. But anyway, still, I disagree -- in algebra, vectors have certain properties. One of the properties is called length. How could you define a length of point? What is the dot product of 2 points? What is the projection of a point into another point?

See also this paper.

Wikipedia entry on vector space states that:

A vector space is a mathematical structure formed by a collection of vectors: objects that may be added together and multiplied ("scaled") by numbers, called scalars in this context.

I, again, ask: what is A + B or a*A, where A, B are points and a is a scalar?

Also notice chapter with description of vector space axioms. Are you sure these definitions apply for points?
bzroom
bzroom
Most libraries dont care to make the difference, though there is very obviously one. If you dont want to use the + operator (or lenght member) on points, then dont. But that's not enough justification to make its own type IMO. Look at shading languages, there's no Point type. Surely those people understand the difference.

It really all just depends on how padentic you want to be, but i think the general idea has been transfered adequately.

Generally they're stored in the same type, it is only the interpretation/use that is important.
Cornstalks
Cornstalks
A point is a vector, but a vector is not necessarily a point*. Sounds a little confusing, so I'll try to clarify. There are many different ways to represent points and vectors. In 3D space, it is common to represent points in the following ways: Cartesian Coordinates (x, y, z), Cylindrical Coordinates (r, θ, z), or Spherical Coordinates (ρ, θ, φ). All of those notations have something in common: they tell you a magnitude and a direction (a vector). In Cartesian coordinates, each component tells you the magnitude and direction to travel along each axis. In cylindrical coordinates, you are given a magnitude and direction for the xy plane, and then an additional magnitude and direction from the third component for the z-axis. In spherical coordinates, you are simply given a magnitude and direction. It should be obvious that these are simply vectors.

While you can represent vectors in the exact same way as a point, the implications of a vector are not the same as a point. As mouserSVK said, vectors are positionless (yes, even in physics, sidenote: while I agree position is the only property of points, position holds direction and magnitude information, meaning it's a vector), whereas points have a notion of position.

*Ok, now something that totally flips my argument. A point is actually a 0-dimensional object, whereas a vector is not an object, but an element of vector space. Taking that definition, a point != a vector. The reason I said a point is a vector is because representation wise it is (you represent a point with a vector), but mathmatically a point is technically not a vector.

Anyway, for your original question X Abstract X, yes, you can (usually, though it depends on exactly what you're doing (in your case I'd say yes, you can)) have vectors and points be the exact same thing. All it really needs to be is a simple object storing x, y, and z (if you need it) components really. Personally, I like to think of it as representing the points as vectors, and not as representing vectors as points.
Numsgil
Numsgil
Quote:

One of the properties is called length. How could you define a length of point? What is the dot product of 2 points? What is the projection of a point into another point?


You can define those properties quite easily. Doesn't necessarily mean that they have any sort of real world meaning... Math doesn't always have to mean anything, especially when you're dealing with abstract algebra.

Quote:

what is A + B or a*A, where A, B are points and a is a scalar?


Again, quite easy. Doesn't mean it has to make sense. Just that cartesian points are elements of a vector space.

If you extend into the realm of homogenous vectors, things get even more interesting. A + B is essentially the point midway between A and B. A - B is a direction vector from B to A. a * A = A since it scales the w component, which unscales all the other components right back.

But that's all a bit more than the OP wants, prolly.
[size=2]Darwinbots - [size=2]Artificial life simulation
mouserSVK
mouserSVK
In terms of affine algebra (used also in computer graphics), point and vector are two different things.
As also Eberly in his book (3D Game Engine Architecture) states, point is transformed differently than vector (because of that distinction of point and vector in affine algebra). Vector is transformed as 2 points, not as one.

(P' = RS.P + T as the equation for point and
V' = RS.V as the equation for vector)

It is true, that in homogeneous vectors world, point P and vector V can be expressed using the same expression - but there still IS a difference in w component and so it doesn't necessarily mean that these two things are the same.

However, while believing that there is clear difference between a point and a vector, still, these two can be defined using the same information. I was just trying to emphasize the difference between two terms ;) I think they are different, but I completely agree that vectors can define points. (But scaling a point, performing cross or dot products on points, .. still sounds weird to me).

I absolutely agree that in practice, one can live with "Vector" object which can hold also information on point (it can be a vector, that, when applied to point at the origin, produces another point -- uniquely represented by this vector). I also never made "Point" class, since Vector is enough to "capture" the portion of points ;)
MaulingMonkey
MaulingMonkey
One can represent a point with a vector describing it's position relative to the origin of the coordinate system within which it is defined. Not only in theory -- in practice, this is how we treat them!

While points may be conceptually distinct from vectors, all the common operations upon them are operations on that vector representation. Translation, rotation, scaling -- be it for movement of objects or translation into the coordinate system of the screen for rendering -- it's all standard vector math.
mouserSVK
mouserSVK
Quote:
Original post by MaulingMonkey
One can represent a point with a vector describing it's position relative to the origin of the coordinate system within which it is defined. Not only in theory -- in practice, this is how we treat them!


Agreed!

Quote:
While points may be conceptually distinct from vectors, all the common operations upon them are operations on that vector representation. Translation, rotation, scaling -- be it for movement of objects or translation into the coordinate system of the screen for rendering -- it's all standard vector math.


Yes, but because we are treating points using their vector representation.

(And this is only possible because we have an origin, note that it would not be possible in an affine space, and lets not forget, that homogeneous coordinates treat vectors and points differently, so do the affine transformations -- performed a lot in comp. graphics. E.g. when performing affine transformation such as translation, a point IS translated most usually to some other point in given space, but translation of vectors is identity.)

I fully understand and agree with the fact that we can use vector representation of points. Just don't forget they are (sometimes) used to express different things.
zulumathabo
zulumathabo
I am new here and I apologize as I still trying to familiarize myself with this great forum. I am only a few hours old here. Lol! I got attracted to this great question posted by X Abstract X and a various people who provided great answers. I am impressed that there is a lot of knowledge and expertise in this forum and in that fashion we can all learn from one another. It’s the greatest thing to see good folks taking their time to contribute great idea to this forum. Kudos to you all.

It’s my observation that bzroom gave an excellent answer with an example about the difference between a vector and a point. I just want to inject another approach by borrowing from Calculus with the hope this will somewhat brighten the light bulbs on this important topic if anything. Calculus has an interesting thing about delta i.e. delta x or delta y or simply dx or dy. All this means is a change of x or y with respect to a variable. If I have a variable x = 4 and variable x2 = 3 then my delta is x - x2 = +1 or if I am going opposite direction then I have x2 – x = -1. In either case we get the same number 1 but with different signs. The signs define direction i.e. -1 is going backward (reversing) whereas +1 is going forward (advancing). The sign is critical because it tells us the direction whereas the number 1 is the magnitude of the delta.

Now taking this to the points i.e. A(6,2) and B(5,4). What is missing in these points is their displacement vector v. If I am lost at position A and I need to get to position B then I have no way of getting there unless with the help of a displacement vector. Since my destination is B then my displacement vector v = B – A = (5-6,4-2) = (-1,2) and thus we have v(-1,2). V has two attributes i.e. direction and magnitude which are not part of A or B. In other words using Calculus concepts, while points only contain position without direction or magnitude, the vector is positionless but contains direction and magnitude. We can think of a vector as a single dimension array of delta values usually using a column matrix as opposed to a row matrix. You need two points in order to define or create a vector but you don’t need a vector to define a point.

Why do we need this? If you are working on a graphics application and you want to scroll images in response to the user input, the most common sense approach would be to accept points from the user’s mouse and move the image accordingly but this falls flat in its face. You must provide the vector so that you can move the image correctly.

Thanks for reading my posting. You guys are great and keep on doing this.
Hope this helps.
Cheers.
Daerax
Daerax
Quote:
Original post by mouserSVK
Also notice chapter with description of vector space axioms. Are you sure these definitions apply for points?


As is the case of many things built in an ad hoc manner, the matter is obscured.

A point means different things in different contexts. vectors or even a function could be points for example, say where the elements of the sets which satisfy the axiom of a topological space are vectors of functions.

Much simpler, consider a Field. A field is a vector space, hence its elements are vectors. The reals are a field. The points on a real line are elements of the real line. There the points are vectors.

Now when Computer Graphics programmers say point and use them with vectors what they are actually leveraging is a one to one correspondence between the points on a geometric plane (not vectors) and position vectors in a vector space defined over some field.

But then in an affine space (where 3D games exist?) the notion of a position becomes undefined since the notion of an origin is lost. The one-one correspondence between points and vectors can no longer be had and we can no longer simply treat points as vectors or call them vectors and must be distinguished.

Topic Locked

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

Sign in to reply to this topic.