#### Archived

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

# Vectors and such

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

## Recommended Posts

This is probably a fairly newbish question, but I have read tutorials, and articles that attempt to explain vectors and matrices and the math behind them, and I can''t seem to grasp the concept. I must have fallen asleep in geometry and trig. Anyways can anybody explain what a vector is and how it''s used? How is it applied to an object or what not in 3D? Also matrices have got me quite confused, like how are they used in transformations and things of that nature. When I picture a scene I just picture 3D objects or even 2D, where does all the vectors and matrices come into play. Thanks ahead of time for any help.

##### Share on other sites
Mathematically defined, a vector is kind of like a line segment, but with a direction. It possesses three attributes: an origin (start point), a direction, and a magnitude (length). As you can probably tell, you can deduce the termination point of a vector with those three attributes. Since this is the case, in 3d graphics, we often represent a vector as simply the termination point and assume an origin of zero. If you wish to change the vector''s origin, you simply add it to a point that defines the origin you wish to set it to.

Since vectors in 3d graphics are really just three values (x, y, and z), they can be thought of as a 3x1 matrix; using matrix multiplication with a 4x4 matrix, then, you can perform operations on this 3x1 matrix such as translating, rotating, or scaling it and combinations of these thereof. Remember that matrix multiplication is not commutative: i.e., the order you multiply in will change the effect (if you translate before scaling, for instance, your origin of scaling will be different than if you scale and then translate). Since you can multiply several matrices to obtain a transformation, you can multiply your various transformation matrices together (also called "concatenating"), which results in a matrix that performs all the translations you multiplied into it in one go.

I hope that wasn''t too much...I really suggest reading a few articles on the topic, it helps a lot.

##### Share on other sites
quote:
Original post by Escherial
Mathematically defined, a vector is kind of like a line segment, but with a direction. It possesses three attributes: an origin (start point), a direction, and a magnitude (length)...

This is not quite correct because it is assuming a lot.

In the most basic sense, a vector is a "quantity" with one or more "dimensions". Ok, that is mumbo jumbo and maybe not even correct (strictly speaking). How about an example: a 3-dimensional vector is a "quantity" with 3 elements, commonly (but not always) designated as x, y, and z.

Vectors are used for many many many different things. In geometry and computer graphics, the most common usage is to treat each element of the vector as an offset along a dimension. For example, (1,2,3) means an offset of 1 unit in the X dimension, 2 units in the Y dimension, and 3 units in the Z dimension. This is usually visualized as an arrow whose length along each dimension is the corresponding element in the vector.

If the vector is not associated with any particular location, then it can be thought of as a direction with a length. No matter where that arrow starts, it always points is the same direction and it always has the same length.

If a vector is associated with a location, then it can be thought of as a location (that is in the specified direction and at the specified distance). The location that the vector is associated with is usually called the vector''s "origin", and is not actually part of the vector.

If the vector''s origin is the Origin of the space, then the vector specifies an "absolute" location, otherwise it specifies a "relative" location (relative to the vector''s origin). If the vector (1,2,3) is used as an absolute location (meaning that the vector''s origin is at the Origin), it specifies a location that is 1 unit from the Origin in the X dimension, 2 units from the Origin in the Y dimension, and 3 units from the Origin in the Z dimension.

So there you go. That is what a vector is. The only thing left is to remember which vectors are used as directions and which are used as locations. For example, "Normal" vectors specify direction and never a location. You might see them with their origin at a particular location but that is just for convenience and clarity.

Matrices

Matrices are (without getting too abstract and esoteric) simply tables of values. There are certain operations on matrices and/or vectors that have useful results. There is nothing magic or special about those operations or the elements of a matrix(other than their usefulness and the significance applied by the system).

##### Share on other sites
booya .......... *

...................................................

##### Share on other sites
Vectors aren''t really covered in high school geometry and trig, and really the only place they are covered in high school is possibly a little in pre-calc or calc.

Mathematically, vectors are things that you can linearly combine to get a vector(if u and v are vectors and a and b are scalars, you can do something like au + bv = a vector) and that their product is a vector ( u * v = a vector).

For most purposes, such as computer graphics, a vector is just a bunch of numbers, for example (2.3 7.1 -3.7 1) is a four dimensional vector.

A vector (x y z) can be viewed as representing a point in a three dimensional space. (x y) could be a point in two dimensional space. In this way, the vertices of 3d models can be thought of as vectors.

Now if you have some models specified with their vertices as vectors like this and you want to place them in a scene, you need a way to move them around, resize them, etc. Everything done with computer graphics (well, with the exception of the perspective...) is done with linear transformations. Linear transformations can rotate and scale the space the vectors occupy (but they can''t translate it, that isn''t a linear transformation). To translate the space (move objects from side to side) we change to what''s called homogeneous coordinates, where instead of (x y z) we now have (x y z 1).

All linear transformations can be represented with a matrix. There is a rule for multiplying matrices and vectors (actually just a rule for multiplying matrices, vectors are like really thin matrices).

A 4 by 4 matrix might look something like this:

2 0 0 1
0 2 0 0
0 0 2 0
0 0 0 1

This matrix can actually be used to scale a homogeneous vector to twice its size and translate it one unit along the x axis in the positive direction. Hmmm...this is a complicated subject...first, here''s how vectors are multiplied:

(a b c) * (d e f) = ad + be + cf

so the product of two vectors (called the dot product, the multiplication symbol is really a dot, not an asterisk) is a scalar (a single number).

Now think of the matrix as being 4 rows. The product of the matrix and the vector is a vector. Each element of that vector is a row of the matrix multiplied by the vector. Oh, and these vectors I''ve been talking about are really column vectors... (x y z 1) would be written as

x
y
z
1

now if we do the product of that matrix and that vector...

2 0 0 1 x 2x + 0y + 0z + 1*1
0 2 0 0 * y = 0x + 2y + 0z + 0*1
0 0 2 0 z 0x + 0y + 2z + 0*1
0 0 0 1 1 0x + 0y + 0z + 1*1

so the result is (2x+1 2y 2z 1)

Anyway this stuff is a big topic, and I probably haven''t done much of a job explaining it...

##### Share on other sites
And that matrix multiplication got mangled...I''ll try again...

2 0 0 1     x   2x + 0y + 0z + 1*10 2 0 0  *  y = 0x + 2y + 0z + 0*10 0 2 0     z   0x + 0y + 2z + 0*10 0 0 1     1   0x + 0y + 0z + 1*1

##### Share on other sites
Open any linear algebra book (for exemple,"Schaum''s Outline of Beginning Linear Algebra"). Study from books, not from internet articles.

//--SEGA--RULES--

##### Share on other sites
For questions like this, always check MathWorld first. They have formal definitions for everything

Cédric

##### Share on other sites
Thanks for all the help guys. I actually do remember some of the stuff from my math classes, dot product, adding vectors etc. Also I remember covering them slightly in physics. I kind of get what they are, but I guess I'm really curious as to how they're applied to lighting and things of that nature. ie When somebody says that normalizing a vector is used in lighting, or the cross product is used in collision detection. I know how to normalize a vector, and find the cross product of two vectors. Just as an example how would I use that?

[edited by - boohillie on May 29, 2003 11:22:39 AM]

##### Share on other sites
Well, the cross-product can find a vector perpendicular to the two vectors multiplied. And since three points represents a plane, you can change two of these points to vectors relative to the third point (I use point to mean an absolute vector). Then, after you cross multiply the two vectors, you have a vector perpendicular to the plane. This vector is called a normal line and can be VERY useful for collision detection.

--------------------------------------
I am the master of stories.....
If only I could just write them down...

1. 1
2. 2
Rutin
22
3. 3
JoeJ
18
4. 4
5. 5

• 17
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631726
• Total Posts
3001910
×