Sign in to follow this  

what a (math) vector is exactly?

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

hi, im a little confused about what the term vector means for a 2d game. is a vector just a Point, IE an x and y? but, im a little confused... does a vector mean an absolute position, ie, a players coordinates, OR, does it mean a relative position, ie a players velocity? or, (which i think it is), does it mean both inter-changibly? so should i give my objects a Vector position and Vector velocity members then? thanks in advance

Share this post


Link to post
Share on other sites
A vector is a direction and a magnitude. Velocity, acceleration, force, etc. are all vectors by defenition. Position is not a vector. However, even though a vector is not a point, it can be represented by an (x,y) position so vectors and points are usually used interchangeably in programming.

Share this post


Link to post
Share on other sites
It is intended to represent a direction and a magnitude, so a relative position would qualify. However, because a Point can be represented as a vector that starts from the origin, I typically just typedef a Point as a vector (despite the fact that not all vector operations really make sence for a point). This clarifies the distinction between vectors and points in my code and enhances readability. An alternative would be to redefine Point with all the necessary operations, but this involves duplication of code, and on occasion it is useful to treat a point as a vector from the origin (say to find the angle from a point to the ground in reference to the origin).

Share this post


Link to post
Share on other sites
A vector is something that has a direction and a length.

Position vectors are a convetional thing, you choose 1 point as origin and the vectors from the origin to any point are position vectors. Velocity is a vector quantity.

Share this post


Link to post
Share on other sites
Just to add further to what has been said in computer graphics we work generally work with something called affine space which has three entities scalars, points, and vectors, if you take the difference of two points you obtain a vector which has magnitude & direction, little diagram:

Point A Point B
. .


So B - A = Vector AB :

Point A Point B
. ----------------------> .
vector AB

Share this post


Link to post
Share on other sites
thanks for all the replies... this might sound pathetic, but im incredibly horrible at math. could you explain what you mean by "direction and magnitude"? IE, lets say that i make a vector represent a characters velocity, and hes moving to the left. his velocity vector would be

-5,0

so the magnitude is -5 and the direction is left?

also,
"However, because a Point can be represented as a vector that starts from the origin"

what does this mean? lets say my players position is currently (563,2301), are you saying this could be a vector since its really 563,2301 magnitude from the origin? is this what you mean?

the last thing that confused me was snk's post ^^^^. what is a scaler ? and why would the difference between 2 points be usefull exactly? wouldnt you need to "normalize" that value to get something usefull? i put it in quotes because im not even sure thats the right term, like i said im incredibly horrible at math.

thanks for anymore help!

Share this post


Link to post
Share on other sites
Quote:
Original post by graveyard filla
thanks for all the replies... this might sound pathetic, but im incredibly horrible at math. could you explain what you mean by "direction and magnitude"? IE, lets say that i make a vector represent a characters velocity, and hes moving to the left. his velocity vector would be

-5,0

so the magnitude is -5 and the direction is left?

No, magnitude is always positive. If his velocity vector is -5,0, then its direction is to the left and its magnitude is 5.
Quote:

also,
"However, because a Point can be represented as a vector that starts from the origin"

what does this mean? lets say my players position is currently (563,2301), are you saying this could be a vector since its really 563,2301 magnitude from the origin? is this what you mean?

If you start at the origin and travel towards (564,2301), then you have moved in a certain direction, and travelled a certain distance. That distance and direction is the vector that (564,2301) represents relative to the origin.
Quote:

the last thing that confused me was snk's post ^^^^. what is a scaler ? and why would the difference between 2 points be usefull exactly? wouldnt you need to "normalize" that value to get something usefull? i put it in quotes because im not even sure thats the right term, like i said im incredibly horrible at math.

A scalar is a number that's not a vector. It's a magnitude without a direction. And the difference between two points is often very useful. If you were to normalize that value you would get a vector representing the direction you would need to go to get from one point to the other but with a magnitude of one. Sometimes you might want to know how far apart they are as well, in which case you want to leave the magnitude intact.

Share this post


Link to post
Share on other sites
The direction of a component-wise (x,y[,z]) vector can be represented by drawing an arrow from the origin to the the coordinates of the vector on a graph. In this diagram, the length of the arrow is equivalent to the magnitude of the vector. By drawing in perpendicular lines, it should be obvious that the length of the arrow can be found via pythagoras' theorem (this is basically the same as the derivation of the distance formula).

For a vector v:

magnitude = sqrt (v.x2+v.y2)

or, for 3D

magnitude = sqrt (v.x2+v.y2+v.z2)

or, in some implementations you may see it as

magnitude = sqrt (dot(v,v))

This last example is equivalent to the other two, but it requires less maintenance.

There are some good articles here on Vectors. You should check them out.

Share this post


Link to post
Share on other sites
(Not an useful post, mainly ramblings...)

Vectors are objects that have the following properties:

- They can be multiplied by a number, which gives you another vector.
- They can be added together, which also gives you vectors.

They are widely used to represent movement, either as a velocity (movement per time step) or as overall movement (from A to B).

Two common misconceptions are:
* A vector has a dimension. This is wrong: the notion of "dimension" is applied to a set of vectors, and is the number of vectors you need in order to be able to describe all the vectors in that set (that is, the number of coordinates to describe objects in that set). [For instance, what is the dimension of the polynomial 2X+3?] HOWEVER, when programming, you create a "vector" type to describe vectors from a set, and so the "2D" in "vector2D" means you will use this object to describe vectors from a 2D plane.
* A vector has a direction and a magnitude. While vectors can have a magnitude (for most useful purposes in game programming, they have one, and standard euclidean distance is used), not all have a direction. The 0 vector, for instance, has nothing that can be defined as "a" direction. And while you could define "direction" for a n-th degree polynomial or a continuous function (which are vectors), it wouldn't really make sense, would it?

However, to describe lines, planes and points, vectors are not enough. This is why the concept of affine space was introduced. An affine space contains a special object, which could be called the center, or the origin. It serves as an absolute reference for everything affine.

Once the origin is there, points are defined as being equivalent of vectors, but only in some ways:

- A point contains a vector, that defines it entirely. That vector is the "movement" that allowes you to move from the Origin to that point.
- However, unlike vectors, you do not add points together. You also cannot multiply points by something.
- You can "substract" two points from each other. The result of this operation is the vector that allows you to move from one point to the other: A-B is the vector that moves from B to A. By using vector addition rules, it is also the vector that defines A, minus the vector that defines B.

Also, an affine space introduces distance. The distance between A and B is the magnitude of B-A (or A-B). This is useful if you want to check for a collision, for instance.

Two common misconceptions about points:
* I can add points together. Addition is not defined for points (neither is multiplying by a number. You could define these operations yourself, but they don't make much sense. Applying transforms to points (translation, rotation, scaling, and many others), however, does.
* A point is a vector. Again, no. Sure, a point is defined by a vector, but don't forget that behind the scenes, it is also defined by the definition of the origin. Maybe you could decide to store the origin of the point along with the position vector, to allow for multiple origins? This happens quite often in physics, for instance, where the vector corresponding to a point depends on the origin you choose.

Food for thought:
Not all games use euclidean magnitudes for vectors. Some tile-based games use manhattan, or "1", distance (ie x+y magnitude), others use "infinite" distance (ie max(x,y)). Euclidean magnitude is the "2" distance.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
(Not an useful post, mainly ramblings...)

Vectors are objects that have the following properties:

- They can be multiplied by a number, which gives you another vector.
- They can be added together, which also gives you vectors.

They are widely used to represent movement, either as a velocity (movement per time step) or as overall movement (from A to B).

Two common misconceptions are:
...


* A vector has a direction and a magnitude.


That a misconception? What sources have you which state this? Vector Analysis was developed mostly by physicists and to say that what is taught in the physics books of the highest regard is a misconception is highly improper. How can the creators of a concept misconceive it?

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

A vector is simply a quantity which can be described with a magnitude and a direction. For example, the players speed is not a vector because it is not possesed of a direction (you could only represent it with a float or int etc.). The players velocity is, however, a vector, since it will have a direction (you can go v.x and v.y etc.). The players position is a vector because it is defined in terms of x and y and thus has a direction. The magnitude of this vector would be the distance of the player from the origin. So for velocity the vector points in the direction of motion and gives the amoiunt of this change. For position the vector points to some location a certain distance away from the origin. A vector is not a point, a vector can point at a point however.

So if the player is at Point (10,10) then it can be said that a vector exists which points from the origin at him or her.

_____________
|\
| \
| _\/
| (10,10)
|

Vectors can also be posessed of different (local) coordinate systems. For example the velocity vector (in one timestep) can be thought of to have an origin in the Players position and point to a point speed (per time step) distance away. This is a loose explanation but gets the point across, I hope.


__________
|\ _ (13,7)
| \ /\ <-------Velocity Vector, Say it is (3 ,-3) Points at players new position, so northeast key..
| _\/
| (10,10)
|

Share this post


Link to post
Share on other sites
I didn't say vectors never had a direction, since it is quite natural to introduce a direction for vectors in the "usual" 2D and 3D spaces.

However, vectors are not restricted to their initial field of application (physics), as many objects in mathematics also have the same properies as the vectors used in physics, and as such are called vectors too (not to say that IMHO, much more work is done in mathematics using vectors, than is in physics).

What is the direction of x -> sqrt(x)? Of 2X+3? Of the linear rotation of angle pi in the plane? Of a system of linear homogenous equations? Of the solutions of a differential homogenous equation? Of a complex number?

Sure, you can define direction mathematically, regardless of the actual nature of the vectors you are considering, and in the case of 2D and 3D spaces this definition will overlap with the intuitive definition of direction, and that's good. For all the purposes of most physics books, all the vectors they will explicitly use impicitly have a direction. But this doesn't mean that in many other cases this definition will be counter-intuitive. Returning to one of my examples above, do the complex numbers 1 and i have the same direction? No, if you consider C as a R-vectorial space, yes, if you consider C as a C-vectorial space. Or, if you prefer an example from physics, when representing electromagnetic waves, are we using C-vectorial spaces, or R-vectorial spaces? Both.

My point is not to bash renowned physics books. On the other hand, I don't see why a physics book would delve into the specifics of mathematical vectors. In almost all cases in physics, a vector has a direction. Now, in math/computer science, not all vectors have a direction (and by this, I mean an acceptable, intuitive one, not a purely mathematical one).

Besides, the direction/length way of representing vectors has always had a problem with representing 0, which leads me to say that "direction" isn't very clearly defined for 0. If you don't move, what direction do you move in?

EDIT: I also find it quite humorous that you state vectors have a direction and magnitude, and then proceed to thoroughly avoid the direction/magnitude representation of vectors and use Cartesian coordinates instead. The direction/magnitude of a vector in 2D is usually (Angle,mangnitude), in 3D (Angle,Angle,Magnitude). "Seeing" direction and magnitude in an (x,y,z) vector is awkward.

Share this post


Link to post
Share on other sites
ToohrVyk has a point. For most game programmer applications, you never touch anything more than the simplified direction and magnitude. However, the OP did ask what a vector is exactly. And although he did not know what that implies, he should get it.
True, the simple approach is enough for a lot of applications, but if he asks for it, he should get the whole story. And although you can always have an isomorphism into a simple X^n (let X be a suitable field, or however you call that in English), talking about angles and magnitude is possible but sometimes useless. You can canonically represent the polynom 3x^2 + 4x + 1 as the vector (3, 4, 1), but it does not make much sense to talk about those concepts. And what do you do in those cases where the dimension is infinite? For example the vector space of continuous functions over the real numbers? Unless you add in a scalar product, you can't talk about angle and magnitude, and even if you have one, the resulting interpretations for angle and magnitude are not always too helpful and intuitive.

Talking about angle and magnitude surely helps for a lot of purposes and is enough for some applications. But the mathematical definition of vectors works completely differently and allows for a lot of abstraction (which you need in those other not so simple cases). It's too much work (and too messy in pure text) to properly introduce all those concepts needed, but they should be mentioned.

Share this post


Link to post
Share on other sites
I concede that in mathematics a vector need not posses a magnitude or direction as when I looked up the mathematical definition it was not defined so but rather as an element of vector space. I do not agree however, that it is a misconception that a vector has an angle or a magnitude because in physics, they do.

This is simply a case of colliding terminology. Here is an extreme example; in math a product is the result of a set of multiplication operations. In chemistry a product is the result of a chemical reaction. If I were to go to a chemistry forum and ask what a product was and someone were to say that it is a common misconception that a product needs to be a substance because in mathematics the product can simply be a number, would that be appropriate? No, because in chemistry a product is defined as something different than it is in math.

It goes to follow that since most all the applications of vectors in game programming are of the type used by engineers that the physics definition be given. If I am learning English and I were to ask what H is, you do not tell me that it is a symbol for the element hydrogen, now do you? Ofcourse not, your post was outside the scope of graveyard filla's question, it more likely than not causes confusion.

Quote:
Original post by ToohrVyk
Or, if you prefer an example from physics, when representing electromagnetic waves, are we using C-vectorial spaces, or R-vectorial spaces? Both.


Indeed waves are represented in the complex plane in physics but that it is simply because the calculations are far simpler to perform than if the waves were left in their trigonometric form. As for the representation of the implied results in reality, either the real or complex parts suffice. Also, there is a clashing of concepts in how you relate complex representation and electromagnetic waves. Light, an electromagnetic wave, is a physical phenemenom defined in terms of its (the) appropriate units. I'll note also that electormagnetic waves are possesed of a wave vector, which have direction and magnitude.

Quote:
Original post by ToohrVyk
EDIT: I also find it quite humorous that you state vectors have a direction and magnitude, and then proceed to thoroughly avoid the direction/magnitude representation of vectors and use Cartesian coordinates instead.


I purposely worked in cartesian coordinates because I am aware of the rpg graveyard filla is working on and describing vectors in that manner would be the most relevant course. The diagrams do, however, show vectors with magnitudes and directions in a visual format. Asides, representing and manipulating vectors in polar or spherical coordinates requires a bit of mental acrobatics as you are well aware. The simplest way to define a vector (especially to a game programmer) is if a quantity can be broken down to its unit components (x and y) then it is a vector.

Anyway coming from a mostly physics background I had never run into a definition of a vector that did not define it in terms of magnitude and direction nor seen an application of it in which such was not the case. I thus found it difficult to envision a vector as anything otherwise, I am therefore thankful for your expanding the scope of my knowledge of vectors and extending it to different domains. But I still think your definition was too hardcore for graveyard filla's needs.

-------A vector is:---
In physics a vector is a quantity posseed of both a magnitude and direction.

In math, an element of a Vector Space (a set of finite points on which certain mathematical operations can be performed)*.

*feel free to clean this up.

Share this post


Link to post
Share on other sites
Quote:
Original post by Daerax
your post was outside the scope of graveyard filla's question


Quote:
Topic subject by graveyard filla
what a (math) vector is exactly?


I did my best to answer the "math" part of his question. And even then, I marked my post as "ramblings" once I realized it might not be that useful to someone just wanting to use the classic 2D vectors.

Quote:

-------A vector is:---
In math, an element of a Vector Space


As stated above, a Vector Space is defined by (commutative, associative) addition of vectors and (associative) multiplication by scalars in the base body.

EDIT: aside from this whole discussion, I'd like to know what the direction of the 0 vector is considered to be, in physics.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
Quote:
Original post by Daerax
your post was outside the scope of graveyard filla's question


Quote:
Topic subject by graveyard filla
what a (math) vector is exactly?


I did my best to answer the "math" part of his question. And even then, I marked my post as "ramblings" once I realized it might not be that useful to someone just wanting to use the classic 2D vectors.



...

I guess... he sort of asked for that didn't he?... Hmm, I guess the saying be careful what you wish for would do nicely here.

Share this post


Link to post
Share on other sites
wow, well, thanks everyone for your help. firstly, i didnt really understand most of your guys replies towards the end. sorry but im mathmatically retarded.... i only know some basic algabra and statistics, seeing as my major is CIS, im in the middle of taking the last math class ill ever have to take, which is statistics. also, ive never taken a physics class in my life.

anyway, thanks again everyone. when i said what is a (math) vector, i didnt know that a vector was a physics thing and not a math thing (in game programming). i only put (math) there so people wouldnt think i was talking about the std::vector. sorry for the confusion.

thanks a lot for all your guys help!

Share this post


Link to post
Share on other sites

This topic is 4853 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this