Interactive Computer Graphics Planar Polyhedra
These are three dimensional objects whose faces are Lecture 2: all planar polygons often called facets.
Three Dimensional objects, Projection and Transformations
Graphics Lecture 2: Slide 1 Graphics Lecture 2: Slide 2
Representing Planar Polygons Projections of Wire Frame Models
In order to represent planar polygons in the computer Wire frame models simply include points and lines. we will require a mixture of numerical and topological data. In order to draw a 3D wire frame model we must first convert the points to a 2D representation. Then we Numerical Data can use simple drawing primitives to draw them. Actual 3D coordinates of vertices, etc. The conversion from 3D into 2D is a form of Topological Data projection. Details of what is connected to what
Graphics Lecture 2: Slide 3 Graphics Lecture 2: Slide 4
Planar Projection Non Linear Projections
3D Object In general it is possible to project onto any surface: Plane of Projection Sphere Cone Vi etc or to use curved projectors, for example to produce Viewpoint lens effects.
Projection of Vi However we will only consider planar linear Projector projections.
Graphics Lecture 2: Slide 5 Graphics Lecture 2: Slide 6
1 Normal Orthographic Projection Orthographic Projection onto z=0
This is the simplest form of projection, and effective y in many cases. V z The viewpoint is at z = -∞ The plane of projection is z=0
Projector so V + µ d x (d=[0,0,-1) All projectors have direction d = [0,0,-1]
Graphics Lecture 2: Slide 7 Graphics Lecture 2: Slide 8
Calculating an Orthographic Projection Orthographic Projection of a Cube
Projector Equation: P = V + µ d
Substitute d = [0,0,-1] Looking at a Face General View Yields cartesian form Px = Vx + 0 Py = Vy + 0 Pz = Vz - µ The projection plane is z=0 so the projected
coordinate is Looking at a vertex [Vx,Vy,0] ie we simply take the 3D x and y components of the vertex
Graphics Lecture 2: Slide 9 Graphics Lecture 2: Slide 10
Perspective Projection Canonical Form for Perspective Projection
Orthographic projection is fine in cases where we are Y Projected point not worried about depth (ie most objects are at the Scene same distance from the viewer). Projector Z
However for close work (particularly computer Plane of Projection games) it will not do. (z=f)
Instead we use perspective projection f
X Viewpoint Graphics Lecture 2: Slide 11 Graphics Lecture 2: Slide 12
2 Calculating Perspective Projection Perspective Projection of a Cube
Projector Equation: 7 P = µ V (all projectors go through the origin) At the projected point Pz=f Looking at a Face General View
µp = Pz/Vz = f/Vz Px = µp Vx and Py = µp Vy Thus Looking at a vertex Px = f Vx/Vz and Py = f Vy/Vz
The constant µp is sometimes called the fore- shortenting factor
Graphics Lecture 2: Slide 13 Graphics Lecture 2: Slide 14
Problem Break The Need for Transformations
Given that the viewpoint is at the origin, and the Graphics scenes are defined in one co-ordinate system viewing plane is at z=5: What point on the viewplane corresponds to the 3D vertex {10,10,10} in We want to be able to draw a graphics scene from any a. Perspective projection angle b. Orthographic projection
To draw a graphics scene we need the viewpoint to be Perspective x'= f x/z = 5 and y' = f y/z = 5 the origin and the z axis to be the direction of view. Orthographic x' = 10 and y' =10 Hence we need to be able to transform the coordinates of a graphics scene.
Graphics Lecture 2: Slide 15 Graphics Lecture 2: Slide 16
Transformation of viewpoint Matrix transformations of points
To transform points we use matrix multiplications. Y Viewpoint X Y For example to make an object at the origin twice as Z big we could use: Z [x',y',z'] = 2 0 0 x 020 y X 002 z Coordinate System for definition Coordinate System for viewing yields
x' = 2x y' = 2y z' = 2z Graphics Lecture 2: Slide 17 Graphics Lecture 2: Slide 18
3 Translation by Matrix multiplication Honogenous Coordinates
Many of our transformations will require translation The answer is to use homogenous coordinates of the points. For example if we want to move all the points two units along the x axis we would require: [x', y', z', 1] = [ x, y, z, 1] 1 0 0 0 0100 0010 x’ = x + 2 2001 y’ = y z’ = z
But how can we do this with a matrix?
Graphics Lecture 2: Slide 19 Graphics Lecture 2: Slide 20
General Homogenous Coordinates Affine Transformations
In most cases the last ordinate will be 1, but in general Affine transformations are those that preserve parallel we can consider it a scale factor. lines.
Thus: Most transformations we require are affine, the most important being: [x, y, z, s] is equivalent to [x/s, y/s, z/s] Scaling Translating Homogenous Cartesian Rotating Other more complex transforms will be built from these three.
Graphics Lecture 2: Slide 21 Graphics Lecture 2: Slide 22
Translation Inverting a translation
Since we know what transformation matrices do, we can write down their inversions directly
[ x, y, z, 1] 1 0 0 0 = [x+tx, y+ty, z+tz, 1 ] 0100 For example: 0010 tx ty tz 1 1000has inversion1 0 00 0100 0 1 00 0010 0 0 10 tx ty tz 1 -tx -ty -tz 1
Graphics Lecture 2: Slide 23 Graphics Lecture 2: Slide 24
4 Scaling Inverting scaling
[x, y, z, 1] sx 0 0 0 = [sx*x, sy*y, sz*z, 1] sx 0 0 0 has inversion 1/sx 0 0 0 0sy00 0sy00 0 1/sy0 0 00sz0 00sz0 0 0 1/sz0 0001 0001 0 0 0 1
Graphics Lecture 2: Slide 25 Graphics Lecture 2: Slide 26
Combining transformations Combined transformations
Suppose we want to make an object at the origin We multiply out the transformation matrices first, twice as big and then move it to a point [5, 5, 20]. then transform the points
The transformation is a scaling followed by a translation: [x',y',z',1] = [x, y, z, 1]2000 0200 0020 [x',y',z',1] = [x, y, z, 1] 2 0 0 0 1 0 0 0 55201 0200 010 0 0020 001 0 0001 55201
Graphics Lecture 2: Slide 27 Graphics Lecture 2: Slide 28
Transformations are not commutative The order of transformations is significant
The order in which transformations are applied Graphics Scene Y Y Translate matters: (Square at origin) Y x:=x+1 X X Scale x:=x*2 In general X
Y Y T * S is not the same as S * T Translate Scale x:=x+1 x:=x*2 X X
Graphics Lecture 2: Slide 29 Graphics Lecture 2: Slide 30
5 Rotation Rotation Matrices
To define a rotation we need an axis.
Rx = 1 0 0 0 Ry = Cos(θ) 0 -Sin(θ) 0 The simplest rotations are about the Cartesian axes 0 Cos(θ)Sin(θ) 00100 0 -Sin(θ)Cos(θ) 0 Sin(θ) 0 Cos(θ) 0 0001 0001
eg Rz = Cos(θ)Sin(θ) 00 -Sin(θ)Cos(θ) 00 0010 Rx - Rotate about the X axis 0001 Ry - Rotate about the Y axis Rz - Rotate about the Z axis
Graphics Lecture 2: Slide 31 Graphics Lecture 2: Slide 32
Y Deriving Rz [X', Y'] Signs of Rotations
Rotate by θ Rotations have a direction. r
r [X,Y] The following rule applies to the matrix formulations θ given in the notes: φ X Rotation is clockwise when viewed from the positive [X,Y] = [r Cosφ, r Sinφ] side of the axis [X',Y'] = [ r Cos(θ+φ) , r Sin(θ+φ) ] = [ r Cosφ Cosθ - rSinφ Sinθ, rSinφCosθ + rCosφSinθ ] = [ X Cosθ -Y Sinθ, YCosθ + XSinθ] = [ X Y ] Cosθ Sinθ -Sinθ Cosθ
Graphics Lecture 2: Slide 33 Graphics Lecture 2: Slide 34
Inverting Rotation Inverting Rz
Inverting a rotation by an angle θ is equivalent to rotating through an angle of -θ, now
Cos(-θ) = Cos(θ) Cos(θ)Sin(θ) 00has inversionCos(θ)-Sin(θ) 00 -Sin(θ)Cos(θ) 00 Sin(θ)Cos(θ) 00 0010 0010 0001 0001 and
Sin(-θ) = -Sin(θ)
Graphics Lecture 2: Slide 35 Graphics Lecture 2: Slide 36
6