?Modem and Sound Compound? ?2D Graphics Compound? ?The Inn? ?The Object Class? ?Rendering? ?Universal Transformations? ?Object Hiding and Backsurface Removal? ?Clipping and Final Rendering? ?Speed?

# 3D Fundamentals

Welcome to the dimension of 3D graphics berk. Let's give you an overview so that you can start learning the real meat.

### Intro to 3D Space

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.

2D Coordinates 0,0 0,4 4,0 4,4 0,0,0 0,4,0 0,4,4 4,4,4

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.

Right and Left Hand Coordinate Systems
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.

### Vectors and Vector Operations

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).

#### How to get Vectors from Points

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:

• 3 - 1 = 2
• 4 - 1 = 3
• 5 - 1 = 4

We use the results of these computations to get our vector <2,3,4>

#### Magnitude

 This is vector u. Usually a vector is defined as , 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 distance formula: length = sqrt(x2 + y2 + z2)

#### Direction

 This is again vector u. To find the direction of a vector you need to find the angles: q = tan (z / sqrt(x^2 + y^2)) f = tan (x / z) 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:

• <x1, y1, z1> + <x2, y2, z2> = <x1+x2, y1+y2, z1 + z2>
• <1,2,3> + <6,8,10> = <7,10,13>
• <5,8,9> + <6,8,10> = <11,16,19>
• <24,-45,12> + <6,8,10> = <30,-39,22>
• <-1,-2,-6> + <6,8,10> = <5,6,4>

To add them graphically you simply put the two vectors head (arrow) to tail.

Even though these are 2d Vectors (for simplicity), it also works with 3D Vectors

#### Vector Subtraction

Subtracting vectors is almost the same as adding them.

Subtracting them algebraically:

To subtract vectors algebraically, simply subtract each component from other.

• <x1, y1, z1> - <x2, y2, z2> = <x1-x2, y1-y2, z1 - z2>
• <1,2,3> - <6,8, 10> = <-5,-6,-7>
• <5,8,9> - <6,8,10> = <-1,0,-1>
• <24,-45,12> - <6,8,10> = <18,-53,2>
• <-1,-2,-6> - <6,8,10> = <-7,-10,-16>

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.

Again, even though these picture are of 2D vectors (for simplicity), it will still work in 3D

#### Scalar Product

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:

• S*u = S * <ux,uy,uz>
• 3*<1,2,3> = <3,6,9,>
• 4*<1,2,3> = <4,8,12>
• 12*<1,2,3> = <12,24,36>
• -1*<1,2,3> = <-1,-2,-3>

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.

#### Dot Product

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?

• <2,4,6> . <4,7,-1> = <4,28,-6>

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:

u.b = |u|*|v| * cos q

The interesting thing about this Dot Product is the cosine in the equation. With a little algebraic manipulation we get:

 q = u.v -------- |u|*|v|

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.

• <ux;uy,uz> . <vx,vy,vz> = <ux*vx,uy*vy, uz*vz>
• <2,4,6> . <4,7,-1> = <8,28,-6>
• <5,6,1> . <5,3,7> = <25,18,7>
• <-8,9,-4> . <5,5,5> = <-40,45,-20>

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

• > 0, then the angle between u and v is acute (less than 90 degrees)
• < 0, then the angle between u and v is obtuse (more than 90 degrees)
• = 0, then u and v are perpendicular

The dot product becomes very important later in computer graphics - hidden surface removal and lighting calculations) so make sure you berks get it!

#### Cross Product

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, say you have two 3D vectors
X Y Z
u 1 2 3
v 4 5 6

So in this case the cross product would be:

• nx = 2*6 - 3*5 = 12 - 15 = -3
• ny = 1*6 - 3*4 = 6 - 12 = -6
• nz = 1*5 - 2*4 = 5 - 8 = -3

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

Unit vectors are vectors that have been normalized. What normalized? Well I'll tell ya!

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:

u = <1/sqrt(14),2/sqrt(14),3/sqrt(14)> = <.26726,.53452.80178>

And there we have a unit vector!

### Matrices and Matrix Operations

Matrices and Matrix Operations

### Coordinate Systems: Local, World, & Camera

Coordinate Systems

Transformations

Projections

Clipping

### Hidden Surface & Object removal

Hidden surface and object removal

Lighting

### The Graphics Pipeline

The Graphics Pipeline

Web Page Created by: Brad Loos
Created: July 30, 1997