• ### Announcements

#### Archived

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

# Help me understanding vectors.

## Recommended Posts

Erik23a86    122
Can anyone show me what the vectors of a triangle are with the co-ordinates (-3,-2), (-2,2), (-1,-1)? I just not know how the vectors a running and in wich direction they are pointing. I know how to calculate the vectors: Vector.x = Point1.x - Point2.x; Vector.y = Point1.y - Point2.y; If I do this I get a co-ordinate, but I don''t understand how this could be the correct vector. Please show me how it must be done (examples). Thanks. The One.

#### Share this post

##### Share on other sites
zander76    122
Hello,

I am not exactly sure what you are trying to get at. Are you trying to calculate the normal ( a perpendicular vector coming out of the surface, think tree on the ground ).

Ben

#### Share this post

##### Share on other sites
zander76    122
Hello Again

I figured I would try to explain a vector ( briefly ). First thing about a vector is that you really have to forget about the coordinate system. When you see a vector that is (1,1) you naturally think of a vertex (a point) with an arrow going from the origin. This is one way of representing a vector. Its a hard consept to grasp when you are confortable with coordinates and they look so much like them.

A vector defines nothing more then a length and a direction and has no location. So for the previously montioned vector <1,1> you assume it starts at (0,0) but you can have the same vector start at 4,4 and be the exact same vector.

So for lighting you usually have a normal (a vector pointing out from the surface) so take your pencil and put in on your desk (straight up of course).. now move it around but make sure the direction does not change. you can even go as far as lift it off you desk.

Your pencil is a vector, it didn't change size and the direction didn't change. So no matter were it was it still give you the same direction. Or more importantly it still give you the direction your desk is facing.

I hope that helps. Its really a difficult thing to grasp. Once you understand that they have no location and stop trying to define it then it will make sence.

Ben

[edited by - zander76 on January 6, 2004 12:18:14 PM]

#### Share this post

##### Share on other sites
Erik23a86    122
Thanks for the explanation, but how do I draw the vector of the triangle? How do I know where the vector starts and in wich direction it goes? Can you give me the calculation of a vector (and/or the calculation of the normal?) and maybe a picture of how I must imagine the vector of a triangle?

Thanks.

The One.

#### Share this post

##### Share on other sites
kiruagon    122
To calculate the normal of a triangle, u use the cross product. Let''s say your triangles has three angles, A, B, C.
To get the vectors vector1 and vector2 from these points you do :
vector1.x = A.x - B.x
vector1.y = A.y - B.y
vector1.z = A.z - B.z

vector2.x = B.x - C.x
vector2.y = B.y - C.y
vector2.z = B.z - C.z

Once you have these vectors you can do the cross product, which gives you the normal vector :

normal.x = vector1.y*vector2.z - vector1.z*vector2.y
normal.y = vector1.z*vector2.x - vector1.x*vector2.z
normal.z = vector1.x*vector2.y - vector1.y*vector2.x

Thx x,y,z are the coordinates in space

Hope this helps,

Kiruagon

#### Share this post

##### Share on other sites
kiruagon    122
Those two vectors are the vectors of the triangle, and that is what you wanted :-)

Kiruagon

#### Share this post

##### Share on other sites
Erik23a86    122
Tanks for your help, but how to get the vectors of a triangle if you only got the co-ordinates of the points of the triangle (without calculating the angles)? And how are the vectors running, are the parallel with the polygeon? How does a triangle with vectors look like? Can you draw it for me? :-)

You said that the x,y,z (of the normal) are the co-ordinates in space. But then you only have the co-ordinates of one point, you need at least two point to get the direction (of the normal)(because its a vector too).

Thanks.

The One.

#### Share this post

##### Share on other sites
zander76    122
Vectors are not real in the way you are thinking about them. Vectors don''t translate into a trangle and are not drawable. Let go of that. If you want to represent them (note I said represent, its a way of visualizing and has no practical part to it like what you are talking) you can draw them from the origin using a cartisan coordinate system (x,y). But really vectors are not definable in the way you are thinking. Try to think of a vector like wind, or velocity. These are the things vectors are used for.

I have no idea what you are talking about when you say a vector of a triagle. A vector is an arrow. Perhaps you are thinking of a vertex (a point in space) then you can draw something using them.

Can you explain what you are trying to do, and try not to use the word vector. Like I said above a vector is a very confusing thing to get at first, since its undefinable in the logic you are following but thats not just you everybody has problems with this when they first start looking at them.

Ben

#### Share this post

##### Share on other sites
Erik23a86    122
I try to make ''make'' collision detection. I found a tutorial on that subject on www.gametutorials.com (RayPlaneCollision). I try to understand what they are doing and how it works. But the problem is that I have got a hard time understanding there vector class and what they are doing.
They have got a triangle with the points {-1, 0, 0}, {1,0,0}, {0,1,0}. They have a class that returns a vector between two points.

CVector3 Vector(CVector3 vPoint1, CVector3 vPoint2)
{
CVector3 vVector = {0};
vVector.x = vPoint1.x - vPoint2.x; vVector.y = vPoint1.y - vPoint2.y; vVector.z = vPoint1.z - vPoint2.z;
return vVector;
}

The problem is that I don''t onderstand what they are doing. If you ''run'' this function you get a point (vector) with x,y,z values. What is this for point? Are the x,y,z value,
co-ordinates? Don''t you need two points to get a direction?
I don''t know how to visualise the vectors, I don''t know what I''m working with.

Thanks.

The One.

#### Share this post

##### Share on other sites
Guest Anonymous Poster
quote:
Original post by Erik23a86
CVector3 Vector(CVector3 vPoint1, CVector3 vPoint2)
{
CVector3 vVector = {0};
vVector.x = vPoint1.x - vPoint2.x; vVector.y = vPoint1.y - vPoint2.y; vVector.z = vPoint1.z - vPoint2.z;
return vVector;
}

The problem is that I don''t onderstand what they are doing. If you ''run'' this function you get a point (vector) with x,y,z values. What is this for point? Are the x,y,z value,
co-ordinates? Don''t you need two points to get a direction?
I don''t know how to visualise the vectors, I don''t know what I''m working with.

If you let A be a vector from point1 -> point2, this function
returns a vertex (point3). If we let B be a vector from point1 -> point3 it will be in the opposite direction of A.

#### Share this post

##### Share on other sites
Erik23a86    122
A vector has a x,y,z value. But what does the x represent and what does the y represent and what does the z represent?

Thanks.

The One.

#### Share this post

##### Share on other sites
Guest Anonymous Poster
quote:
Original post by Erik23a86
A vector has a x,y,z value. But what does the x represent and what does the y represent and what does the z represent?

Thanks.

The One.

The vector V then is assumned to be the vector with it''s tail at (0,0,0) and it''s head at (x,y,z).

#### Share this post

##### Share on other sites
Guest Anonymous Poster
Try reading some of this:

http://mathforum.org/~klotz/Vectors/vectors.html

In your case for a triangle:

an example is three VERTEX''s?(sp?) with vertices

[0,0,0], [5,10,0], [10,0,0]

#### Share this post

##### Share on other sites
Erik23a86    122
How can (for example) that a triangle has a vector? What does the vector say about the triangle (or the points)? And why can the normal and collision be calculated with vectors?

Thanks.

The One.

#### Share this post

##### Share on other sites
Fidelio66    164
A triangle has 3 corner points.
A vector is a direction. This is usually expressed as a point, and the direction is then along the line through the origin (0,0) or (0,0,0) and the point.
In 3D programming this is often thrown together and everything is called a vertex, used for both points and directions. If you are confused about which vertors a triangle has then maybe you are confusing the two.

#### Share this post

##### Share on other sites
Erik23a86    122
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?

Thanks.

The One.

#### Share this post

##### Share on other sites
Erik23a86    122
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.