Welcome to the dimension of 3D graphics berk. Let's give you an overview so that you can start learning the real meat.
So what is 3D space, well, you're living in it berk! To give a position in 3D space, one must give all '3' coordinates. These coordinates are the x, y, and z coordinates. The third coordinate gives us depth. Let's take a look, shall we.
Now that you know how to define your position in 3D space, lets see if we can teach you how to find that position in the first place.
|Left Handed Coordinate System||Right Handed Coordinate System|
The special thing about this system is that the positive z-axis is pointing into the page. It's called the left handed coordinate system because if you take your left hand and roll it from x to y your thumb is pointing in the positive z direction. This system is mostly used in computer graphics.
The right handed system has it's positive z-axis pointed out from the paper. Mathmaticians and Physicsts like to used this system because it makes it easier to view diagrams. Therefore, this system is used mainly in in physics and mathematics.
The final 3D engine will use the left handed cooridnate system, but we'll probably use the right handed system to show diagrams - since it's nicer.
What are vectors you say? A vector is a special mathematical object which denotes both magnitude and direction. What that means berk, is that a vector has a length (magnitude) and a direction in which it points. When we use vectors they will always be denoted as lowercase bold letters (ie. u).
To get vectors from points all you have to do is subtract one point from the other.
Say we have the points p1 = (3,4,5) and p2 = (1,1,1) to change them into a vector we subtract them:
We use the results of these computations to get our vector <2,3,4>
This is vector u. Usually a vector is defined as
<x, y, z>, where x, y, and z denote the x, y, and z coordinates
(respectively). To find the length of a vector you can simply use the
length = sqrt(x2 + y2 + z2)
This is again vector u. To find the direction of a vector you
need to find the angles:
Actually this is exactly how you define cylindrical coordiates (r, q, f).
Vectors are very helpful in computer graphics, simplifyingsome of the complex manipulations. Since computer graphics deals with 2D and 3D points and a point is itself a vector it makes sense to make up a set of rules to manipulate vectors. So here they are.
Adding vectors isn't all that different from adding normal numbers, there are just more components to worry about
To add vectors algabraically, simply add each component to each other:
To add them graphically you simply put the two vectors head (arrow) to tail.
Subtracting vectors is almost the same as adding them.
To subtract vectors algebraically, simply subtract each component from other.
To subtract them graphically is also similar to adding. The difference is that you put both vectors with their heads (not arrows) at the origin and then draw the resultant vector from one head (arrow) to the other.
The scalar product of a vector is very simple. All a berk has to do is multiply each component of the vector by a scalar (magnitude but no direction) number. For example:
This helps you berks out a lot. Using this you can scale you objects. Things can shrink under a freeze ray, or get bigger like the little lady through the looking glass
Also, note what happens when you multiply by a negative number. Not only do you scale it, but it also flips it.
So we now how to multiply a vector by a scalar (magnitude but no direction) but what happens when we multiply a vector by another vector?
When you multiply each component in one vector by anotheryou are actually doing what is called the dot product. Another way to write the dot product is:
The interesting thing about this Dot Product is the cosine in the equation. With a little algebraic manipulation we get:
There's only one problem. How do you evaluate u.v? Well if you remember from before, the dot product is evaluated by multiplying each of the vector components by each other.
Now, the interesting property that the dot product has is when we only want to know
about what angle is between the two vectors (q). This is what
mathematicians have found:
If (u.v) is
The dot product becomes very important later in computer graphics - hidden surface removal and lighting calculations) so make sure you berks get it!
What if we want to find to find a vector which is normal (perpendicular) to two other vectors? Well berks, you'd have to use the cross product. Here's how it works:
|ux =||uy*vz - vy*uz||ux =||ux*vz - vx*uz|
|ux =||ux*vy - vx*uy|
So in this case the cross product would be:
So n = u.v = <-3,-6,-3>
In most cases, when you compute a normal vector it's normalized. To see how to do this, read on berks!
Unit vectors are vectors that have been normalized. What normalized? Well I'll tell ya!
Normalizing a vector means to manipulate the vector so that it's length is 1.0. How do we go about this? It's simple berk, all we have to do is divide each component of the vector by the vector's length. If you don't remember how to figure the length of a vector then go back and learn it.
First compute the length(magnitude) of the vector you want to normalize.
Say I want to normalize u = <1,2,3>, its length is: sqrt(14)
Then all you have to do is divide each component of the vector by it's length
Taking our previous example, I will divide each component by the length (14) and get
the normalized, or unit, vector:
And there we have a unit vector!