Archived

This topic is now archived and is closed to further replies.

Erik23a86

Almost understand Vectors

Recommended Posts

I still have a problem with vectors. If I have a 2d triangle, like the picture below, how do I calculate the vector between 2 points and how does it look like in the picture (and how to draw the vector in the picture)? Thanks. The One.

Share this post


Link to post
Share on other sites
If you want to find the vector between two points, let''s say A and B, you simply take the coordinates of A and subtract them from B (B - A). Then you have a vector. I read the other post and you seem to be confused as to what vectors are and how to use them. A vector DOES NOT HAVE A POSITION. So if you want to represent each side of the triangle as a vector, you can have each vector start at the origin and have them extend from there in the appropriate direction (you can essentially treat the coefficients of i and j as the (x,y) position). Or you can very well leave it in the same triangle formation (just make sure you know which direction each vector is pointing in).

Share this post


Link to post
Share on other sites
I think some of your confusion (and my confusion at times, too) stems from the fact that we often see in code Coordinates stored in Vector objects. 3D Coordinates (x,y,z) represent a position in 3D space ( or 2D being (x,y) ). Vectors, which also have x,y,z components, specify a direction in 3D space. Knowing that, think of this:

Given two points:

Point a = { -2, 3 )
Point b = ( -4, 0 )

Vector ab = (b.x - a.x), (b.y - a.y)

Vector ab now points from a to b, but it is simply a measure of the distance/direction between them. If you were at point a, then adding ab to a would give you b.

Vectors are often used for things like forces, where the position in the world is not of importance, it is simply the strength of the force and the direction it points that matters.

To simplify things in your head, try using two data types: A structure or class that is a Point and a structure or a class that is a Vector. They will both have the same number of components (x,y or x,y,z) but they mean different things. Later on you''ll want to stick with just a Vector even when representing a position because of the maths you may need to do on points and vectors together, but if you are just starting out it might make sense to keep them seperate.

As for how you would draw the vector:

Given that Point A = -2,3 and Point B = -4, 0 then vector AB would be equal to the line you have from -2,3 to -4,0, pointing ''down and to the left'' as you have it there, but it would have no location in space since it would be equal to (-2, 3), which is just chance that it equals point A (-2,3) since -4 - -2 = -2 and 0 - 3 = 3. It would just be a vector of direction/distance in 2D space.

Taking Point A = -2,3 and Point C = 1,-1 then vector AC would be 3, -4.


Hope that helps and I havn''t goofed in my descriptions.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
As an addendum,

let us take coordinates (x,y,z) -> (2,1,3)

When discussing coordinates or vertices, you''d refer to it as a point with co-ordinate (2,1,3).

When discussing vectors the vector from (0,0,0) to (2,1,3) would simply be represented as <2,1,3>

Coordinate = (2,1,3)
Vector = <2,1,3>

That''s more of a clear-up with regards to notational differences

_vizual_

Share this post


Link to post
Share on other sites
So if I understand it correctly, the vector between the points (1,-1) and (-2,3) is a vector with a origin of (0,0) and an end of <-3,4>. Like in the picture.





Is this correct?
And the only reason vectors are used for example in collision detection, is because it simplifys it.

Thanks.

The One.

Share this post


Link to post
Share on other sites
The vector doesn''t start at the origin. It doesn''t start ANYWHERE BECAUSE VECTORS DON''T HAVE A POSITION. However it is often convenient to have vectors start at the origin when you are drawing these things out.

Vectors are used in collision detection because it simplifies a lot of things as vectors have components (i, j, k) that can be used to break down the collision into easy to handle directions. Also things like motion are easily expressed using vectors.

When dealing with light, vectors are again useful because it is easy to calculate reflections using vectors, since the light has direction and it has magnitude (brightness).

Share this post


Link to post
Share on other sites
When drawing a vector from A to B you usally draw a vector starting at A and ending at B. But it is the same as the vector starting at 0 and ending at B-A, ore anything like that. As mentioned before, the vector is independent of the coordinate system, but one often gives it a meaning according to the context.

Share this post


Link to post
Share on other sites
But is the vector correct, if it starts from the origin? And if vectors don''t have positions how must I interpret the x,y,z. I thought they where coordinates. And in order to get a direction you need a second point, the origin (0,0,0).
If you have a vector of 2 point, what does the vector say about the 2 points? What does the vector say about the polygon(s)?

Thanks.

The One.

Share this post


Link to post
Share on other sites
You can think of vectors as a 'slide' if you like, from one position to another. In your example with the triangle, take these (x, y) pairs:

(-4, 0) as point A
(-2, 3) as point B

vector AB is the movement from A to B, as others have described (I'm just trying to provide an analogy to aid understanding).

So, if you start at A and go to B, you go 2 up along the X axis and 3 up along the Y axis. Thus, your vector from A to B, AB is (2, 3).
Mathematically, this is as Sphet said, just subtract the source from the destination to get the vector.

To draw it, you can put a line describing the vector with the arrow in the middle of the line (this is useful for cases where you just want to add it to a line already there). Put it where the vector is, i.e. you don't need to start it at the origin, start it where the vector starts (point A) and finish it where the vector ends (at point B). No tricks.

Also, as others have said, a vector is magnitude and direction, it doesn't really have a starting position inherent in it's value - you define it really by saying "this is a vector from point A to B" if you say that, it becomes obvious that it starts where A is.
You can apply the vector to something with a position, though, (something like a particle, to make it move, for example).

Hope that has rationalised a few things for you.

-Mezz

[edited by - Mezz on January 7, 2004 6:05:33 PM]

Share this post


Link to post
Share on other sites
(x, y, z) tells you the direction and the magnitude. Starting from ANY point, go x along the x-axis, y along tha y-Axis and z along the z-Axis.

Share this post


Link to post
Share on other sites
Your problem is that you are looking at the components of a vector as coordinates. This is why I prefer to write i, j, k instead of x, y, z. In any case, think about it this way, if I told you to walk 5 miles north, would you ask me "Where is 5 miles north?" No. It doesn''t have a position, it''s simply a magnitude and a direction. Got it?

Share this post


Link to post
Share on other sites
I think I understand it. A vector discribes a ''path'' how to go from for example point A to Point B.

Many thanks to all. You were very helpfull.

Thanks.

The One.

Share this post


Link to post
Share on other sites