Archived

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

The maths behind 3D

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

Ok, I have been looking for a few weeks now, reading tutorials and trying to understand the maths behind 3d. I have read the 3D Black Hole tutorial, I have read the primers and stuff on this site.. but I think I have a problem.. I am stupid. I can''t understand them and don''t want to go further into them into matrices and everything because I don''t understand the vector stuff. I know that a vector has two values and defines direction and magnitude (??) Thats about all I can understand.. The tutorials all seem to move onto dot products and vector addition and subtraction before I fully understand them. What I need is a practical, simple example of what vectors are, how they apply to 3d and quite simply somewhere to start. I don''t want to even attempt to understand Direct3D or OGL until I know the simple maths stuff.. I never did this stuff in school, and it has been 7 years since I even looked at equations and stuff so what I am asking is quite simply HELP! This is not a school project.. this is a simple personal goal.. and its annoying me.. I need to understand it but don''t know how to gain my understanding. I assure you all I have read tutorial after tutorial on this and I can''t find anything.. i have scoured google and ask and altavista to try and find something to explain it to me.. please help.. I feel really dumb! =*= If things seem bad, think that they can get a whole load worse, and they don''t seem so bad anymore =*=

Share this post


Link to post
Share on other sites
Vectors are just a representation of a point in three dimensions (because obviously, we live in a 3D world)

You can describe any point in 3D space with 3 coordinates, and they are normally called x, y, and z. When you sit in front of your computer, imagine it this way:

Take the lower left corner of your monitor: that is your x=0, y=0, z=0 point, or as a vector (0,0,0).
Now look to the bottom right of the monitor. Depending how large your monitor is, it''s going to be about 15" to the right (which is the positive x axis). So that point is (15,0,0)

The top left point is along the positive y axis, some odd 12" or so. So that point is (0,12,0).

Now comes the first important step - what is the coordinate of the top right corner? Well, it''s 15 to the right and 12 to the top, or (15, 12, 0). But we can get that from a simple addition as well:
(0,12,0) + (15, 0, 0) = (15, 12, 0) (in an addition, you add every component separately)

When you look at the back of the monitor then, you go along the positive z axis, and you may end up at a point (0, 0, 17) (bottom left in the rear) or (15, 12, 17) (top right in the rear)

It''s hard to describe it in words, but I hope you got some idea now. Transformation through matrices is a lot harder to grasp...

Share this post


Link to post
Share on other sites
I thought vertices represented a point in 3d space.. now I am really confused.. I get the explanation, I can understand that we work in 3 dimensions, I just can''t understand how the points work.. I can''t understand the basics..

=*=
If things seem bad, think that they can get a whole load worse, and they don''t seem so bad anymore

=*=

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you might think about getting out a basic maths or physics book from a library. They will prolly explain it better than a website or tutorial thing. Don''t know any of the top of my head...

Share this post


Link to post
Share on other sites
I''ll have another crack at trying to explain it in a different way.

A point in 3d space is defined by 3 values, as you know: (x, y, z)

A vector in 3d space is also defined by 3 values: (x, y, z)

You''re probably thinking, well what is so great about vectors then, they''re exactly the same as points. Well, going from your definiton, vectors actually don''t define just a point in 3d space, they define a direction and magnitude. To explain this:

Take the point (1, 1, 0). Draw it on a piece of paper or something.

Now draw a line between (0,0,0) and this point (1,1,0) and draw an arrow head pointing to (1,1,0).

(1,1,0) is the point, the vector is this line with the arrowhead.

See the vector is pointing in a direction. It''s magnitude is the length of the line. (calculated by the distance formula between the points (1,1,0) and (0,0,0)).

Because the vector is this line, we can do a lot of meaningful operations on them. For example rotating the vector by 45 degrees will make it point straight up the y axis. It doesn''t make any sense to rotate a point, it will still lie at the same spot.

I hope that helps a bit. I didn''t do an vector math in school, so when i started to learn it by myself i remember having the trouble with what was the difference between a point and a vector, what do vectors do, all that stuff.

If u understand the above, then the next best step is probably to start learning about some operations like vector addition and subtraction. Even if u don''t fully get what i''ve written, then drawing the operations out on paper as you learn them may help to visualise vectors and understand them more and more.

Share this post


Link to post
Share on other sites
that's because a vector means more than one thing, position vectors and just plain vectors. A postio vector obviously is a point in space refering to a certain point in space, say 0,0,0 which is 0i+0j+0k in vector format. A standard vector is the directiony thingy. we'll take a point in space as P whihc is say 1i+1j+1k. the vector OA o being the origin is 1i+1j+1k as its the distance travelled from O to P. the magintude of the vector is the size of the vector. In 2d for example :

whoops they aren;t happy with ASCII art

and can be calculated using pythagarous(spl??) mag^2=i^2+j^2.


oh just to clarify there are several types of coordinate systems, two ones we are concerened with, cartesian and vector(and parametric but no one care about that ) cartesian is in(x,y,z) whilst vector is usually taken in the form (i+j+k)

[edited by - Foobat on November 19, 2002 10:21:04 AM]

[edited by - Foobat on November 19, 2002 10:24:28 AM]

Share this post


Link to post
Share on other sites
Sorry to be pedantic but that tutorial is wrong

"All vectors must start at the origin (0,0,0)"

which is in correct for example you have 2 position vectors A and B with position vectors 1i+1j+1k and 4i+4j+4k respectively. The vector AB clearly does start not from the origin. the vecotr AB is AO+OB. seee....


[edited by - Foobat on November 19, 2002 10:46:19 AM]

Share this post


Link to post
Share on other sites
Ill have a go at explaining vectors. Basically the vectors used in 3D rendering math are called cartecian vectors. Which means a vector can be defined by a x,y,z. So your probably thinking this is a point, to explain the diffrence ill give an example.
imagine the point <0,0,1>
and the vector <0,0,1>

the point is an actual point in space ( duh ), but the vector is actully pointing down the z-axis ( into the screen )so thats it direction. Its magnitude is is of 1.

Ok you know what a vector is now, ill show you the way I think of them. Now were gonna go to 2D to explain this. Let say you have the point <5,9> . You can draw a line to that point to show the vector. You relize that 5 means 5 points across the x-axis & 9 points up the y - axis. Draw lines from this point and you''ll have a triangle. when you hear right-angle triangle you should think trignometry & pythagoras theorem. By making it a triangle you can rotate the vector by doing this:
rember
sin=opposite/hypotenuse, cos=adjacent/hypotenuse
hypotenuse^2 = a^2 + b^2 // Pythag theroem

therfor the hypotenuse for the <5,9> vector is:
=sqrt( 5^2 + 9^2 )
=sqrt( 25 + 81 )
=10.3

if you look back at the triangle I asked you to make that actully gives the magnitude of the vector. Now that you know the magnitude/hypotenuse you can rotate the vector using trig:
NewX=cos(RotationAngle)*10.3
NewY=sin(RotationAngle)*10.3

and that will rotate it anyway you want. The only other thing left is translation which is a simple:
NewX=x+translationX;
NewY=y+translationY;

Moving to 3D is just adding another dimension. If you ever get stuck take the equation down to 2D (ignore Z). If your stuck on that try 1D(ignore Y).

I hope this helped. I know it was alot. It would really be much better with pictures. If you really don''t get it I could write a little 1 page tutorial with pictures , but have a go at it. What I recon you should do is try make a 2D engine which just invovles having rendering 2D shapes rotating them and translating them.

WizHarD

Share this post


Link to post
Share on other sites
Right.. forgive me if I am really not getting this.. And you guys have been more help than I ever could of wished for so far. Thank-you, very much appreciated, all of you.

If I have a point,

4,4 and there is another point 10,6

the vector there is 6,2 , yes? because the vector, if relative to 4,4 would be the movement? Do I understand that correctly. The other values are vertices. So, being able to work out the length of the vector

sqrt(6 * 6 + 2 * 2)

What does that help me with? How does knowing how to manipulate that help me? What can getting the length of the vector help me with? I suppose I am just asking because I think that by asking questions you learn. And you guys all know what you are talking about. Thanks very much for the assistance.

=*=
If things seem bad, think that they can get a whole load worse, and they don''t seem so bad anymore

=*=

Share this post


Link to post
Share on other sites
If you have 2 position vectors and you wanted to know their distance from each other, you could subtract them and calculate the resulting vectors length.

If you have one vector represent where something is going and how fast it''s going, the length of that vector it the speed.

If you want a vector to have a length of one (making it a unit vector), you can divide it by it''s length.

If you want to make a vector a certin length, you can divide by it''s length and multiply it by the length you want.

Share this post


Link to post
Share on other sites
I don''t mean to be rude, but how exactly does that help me? I am trying to understand.. is my idea of the vectors correct or am I drifting off the mark? Thanks for the replies though, I think that this is helping me..

=*=
If things seem bad, think that they can get a whole load worse, and they don''t seem so bad anymore

=*=

Share this post


Link to post
Share on other sites
well, if your not really sure on 3D as someone else mentioned start in 2D. That way you can get the hang on vectors. WEll to name one use of vectors you can show the speed and direction(or velocity to all physics kids out there) of say... a space ship, so every time the animation loop completes a cycle it''ll draw the ship at the new location according to the vector. and you can work out lots of fun stuff like acceleration... okay i''m starting to sound a bit sad now.......

Share this post


Link to post
Share on other sites
Right.. ok.. I know I need to start in 2d.. and I really feel stupid. But can anybody give me any practical examples. I have never felt this stupid. but if anyone can help me out I would be much appreciative.

The flipcode tut confused the hell out of me. I can't see the practical use of Vectors.. and I don't know if I am getting stuck on them unnecessarily. But can someone say tell me how I use a vector etc.. to move a shape on screen. in 2d.. would be great. Thanks.

=*=
If things seem bad, think that they can get a whole load worse, and they don't seem so bad anymore

=*=

[edited by - hammerstein_02 on November 19, 2002 2:39:32 PM]

Share this post


Link to post
Share on other sites
Okay well someone already mentioned displaying velocity with it, so we''ll stick with that. In 2D:

Say we have an object at (2,0) with a velocity vector (1,2). It could have gotten this velocity vector because we hard coded it in there, or it collided with something, but that doesn''t matter, the point is you don''t have to magically derive it or anything.

So, in the game, we get to this object for processing and (we''ll forget about time-based movement for simplicity) we update it''s new position like this:

position += velocity -> (2,0) += (1,2) = (3,2)

So, in a sense we''re saying this object movies 1 unit on the positive x axis and 2 units up the positive y axis each frame. If you like the velocity vector is just a short little line pointing outward from the object, showing where it''s head. The length of the line is essentially the object''s speed (because the longer the line when we do the += it will move further) and the where the object is heading is simply where the vector is pointing.

If you''re now understanding vectors but can''t really see the uses for them then you just have to start reading up on operations on vectors and then you can start to read some things on how to use them. I guess you just have to trust us that they do have uses and keep ploughing through the operations and stuff

Share this post


Link to post
Share on other sites
Ok, let me give it a try.
In physics, forces are vectors. What does that mean: it mean that a force has a SENSE (direction) and an intensity.
If you can''t understand 2D vectors, try with 1D vectors
An 1D vector is something like this (graphical representation)
-------->
or
<--------

So, it goes to left or right. Now, the number of ''-'' in it denotes it''s intensity.
--> has a smaller intenisty than ----------->

Now, if you want to combine two vectors: -----> and <--- you will get -->
If you add ---> and ----> you get ------->
I hope you understand what I meant...

Share this post


Link to post
Share on other sites
Okay... I might be really unusual here.. I''m a girl and yes I''m into programming too.. I don''t quite understand the vector concepts relevance in 3D. Here''s a lil bit of my background, I''ve taken 5 years of Physics, and the Advanced Placement, Calculus Based Physics.. I think where I''m having a problem is relating the physics aspect of vectors to computer generated ones.. In Physics we don''t have vectors that are "3D" per say.. if anyone can explain how to get my head from Physics to Computers I''d gladly appreciate that.

"Promise to remember that you''''re braver than you believe, stronger than you seem, and smarter than you think....and remember that I''''ll always be with you...even when I''''m not."
-Christopher Robin to Pooh

Share this post


Link to post
Share on other sites
You may want to post a seperate question about physics in the physics forum.

I''ve never taken a real physics class (sophmore in highschool :\), but...

I''m pretty sure you have 2 dimensional vectors in physics. The only difference between a 2d and 3d vector is the extra dimension. But it is the same as the difference between a point in 2D and 3D. Any operation you would do on a 2d vector, you can do on a 3d vector, you just add an extra variable/coordinate into the equations.

Theres a book called something like "Physics for Game Developers". It uses pretty advanced math (calculus and such) but it doesn''t get too detailed with examples. You may want to flip through it at your local bookstore (if they have it) and you might see something click


||--------------------------||
Black Hole Productions
http://bhp.e-chrono.net/
Resident expert on stuff
max621@barrysworld.com
||--------------------------||

Share this post


Link to post
Share on other sites
ok, this has been a long hard battle.. but I think I am starting to come round. Thank-you everyone for your most patient replies. I am working on the idea of 2d to understand.. and now I am trying to apply to games and shapes etc before I really understand what it is, but here goes.

A vector with regards to 2d space and games would be the difference between the X,Y coords of two points. So,

* (10,10)



* (4,4)

(6,6) would be my vector.. right?

So what relevance would this have to me? How do I use this practically. I think it is the only way I can understand what the hell this means.. Appreciated.

=*=
If things seem bad, think that they can get a whole load worse, and they don''t seem so bad anymore

=*=

Share this post


Link to post
Share on other sites
quote:
Original post by Foobat
Sorry to be pedantic but that tutorial is wrong

"All vectors must start at the origin (0,0,0)"

which is in correct for example you have 2 position vectors A and B with position vectors 1i+1j+1k and 4i+4j+4k respectively. The vector AB clearly does start not from the origin. the vecotr AB is AO+OB. seee....


[edited by - Foobat on November 19, 2002 10:46:19 AM]


Actually it is right. If you have your vectors A = (1,1,1) and B = (4,4,4) and you add them, you get a new vector C = (5,5,5). The direction of C is from the origin to (5,5,5). If you subtract them you get D = (-3,-3,-3). The direction of D is, again, from the origin to (-3,-3,-3).

No matter what operation you do to vectors, a vector''s direction is always defined as being from the origin.

Share this post


Link to post
Share on other sites
let me give a try in explaining what a vector is:

First, let me tell you the way I (and some books) define vectors and points:
Points: A (x, y, z) // with ( and ) brackets
Vectors: A // with < and > brackets

Vectors represent direction. From a point to another point. While points represent...a point. Points just tell you positions.

Now, suppose we are at the origin (0,0); let's work in 2D first. And there is another point at (5,4). If we draw an arrow, from (0,0) to (5,4), the arrow we are drawing is a vector. and it's value is <5,4>.

Now, let's say we are at (1,1), and we draw an arrow to (6,5). The vector is <5,4>. It's the same vector since the value is the same. For 3D, just add the z component, you are in 3D.

Now, how do we find the length of vector, that is, we drew an arrow and we want to know the length of the arrow.

We do this by sqrt(x^2 + y^2), in 2D. In 3D, it's sqrt(x^2 + y^2 + z^2). Why do we care about the length of it? In some cases, math/physics/programming etc, we need to know the length of vectors to obtain other useful information.

What does a vector do with 3D programming? A lot! One of the examples is to tell a polygon surface to where it faces (hint: direction, *where* it faces), so that the engine can apply appropriate lighting for that face. If you can grab the basics of vectors, read more from books and you will discover more and more useful stuff you can do in 3D with vectors.

For matrices...for some reasons, vectors and matrices just work pretty well together. Matrices help some vectors operations.


My compiler generates one error message: "does not compile."

[edited by - alnite on November 19, 2002 6:56:31 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by alnite
First, let me tell you the way I (and some books) define vectors and points:
Points: A (x, y, z) // with ( and ) brackets
Vectors: A // with < and > brackets



stupid HTML tags. anyway, vectors are x,y,z with < and > brackets




My compiler generates one error message: "does not compile."

Share this post


Link to post
Share on other sites