Graphics Slides 02

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Graphics Slides 02 as PDF for free.

More details

  • Words: 1,486
  • Pages: 6
Interactive Computer Graphics

Planar Polyhedra These are three dimensional objects whose faces are all planar polygons often called facets.

Lecture 2: 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 we will require a mixture of numerical and topological data. Numerical Data

Wire frame models simply include points and lines. In order to draw a 3D wire frame model we must first convert the points to a 2D representation. Then we can use simple drawing primitives to draw them.

Actual 3D coordinates of vertices, etc.

The conversion from 3D into 2D is a form of projection.

Topological Data Details of what is connected to what

Graphics Lecture 2: Slide 3

Graphics Lecture 2: Slide 4

Planar Projection Plane of Projection

Non Linear Projections 3D Object

Vi

Sphere Cone etc

or to use curved projectors, for example to produce lens effects.

Viewpoint

Projector

Graphics Lecture 2: Slide 5

In general it is possible to project onto any surface:

Projection of Vi

However we will only consider planar linear projections. Graphics Lecture 2: Slide 6

1

Normal Orthographic Projection

Orthographic Projection onto z=0

This is the simplest form of projection, and effective in many cases.

y V z

The viewpoint is at z = -∞ The plane of projection is z=0 so All projectors have direction d = [0,0,-1] Graphics Lecture 2: Slide 7

Projector V+µd (d=[0,0,-1)

x

Graphics Lecture 2: Slide 8

Calculating an Orthographic Projection

Orthographic Projection of a Cube

Projector Equation: P=V+µd

Substitute d = [0,0,-1] Yields cartesian form Px = Vx + 0 Py = Vy + 0

Looking at a Face

General View

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

Perspective Projection Orthographic projection is fine in cases where we are not worried about depth (ie most objects are at the same distance from the viewer).

Graphics Lecture 2: Slide 10

Canonical Form for Perspective Projection Y

Projected point Scene

Projector

Z

However for close work (particularly computer games) it will not do.

Plane of Projection (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 µp = Pz/Vz = f/Vz Px = µp Vx and Py = µp Vy Thus

General View

Looking at a Face

Looking at a vertex

Px = f Vx/Vz and Py = f Vy/Vz

The constant µp is sometimes called the foreshortenting 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 viewing plane is at z=5: What point on the viewplane corresponds to the 3D vertex {10,10,10} in

Graphics scenes are defined in one co-ordinate system We want to be able to draw a graphics scene from any angle

a. Perspective projection b. Orthographic projection

Perspective

To draw a graphics scene we need the viewpoint to be the origin and the z axis to be the direction of view.

x'= f x/z = 5 and y' = f y/z = 5

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

Viewpoint

Matrix transformations of points

X

Y Z Z

Y

To transform points we use matrix multiplications. For example to make an object at the origin twice as big we could use: [x',y',z'] =

X Coordinate System for definition

2 0 0

0 2 0

0 0 2

x y z

Coordinate System for viewing

yields x' = 2x Graphics Lecture 2: Slide 17

y' = 2y

z' = 2z

Graphics Lecture 2: Slide 18

3

Translation by Matrix multiplication Many of our transformations will require translation of the points. For example if we want to move all the points two units along the x axis we would require:

Honogenous Coordinates The answer is to use homogenous coordinates

[x', y', z', 1] =

[ x, y, z, 1]

x’ = x + 2 y’ = y z’ = z

1 0 0 2

0 1 0 0

0 0 1 0

0 0 0 1

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 we can consider it a scale factor.

Affine transformations are those that preserve parallel lines.

Thus:

Most transformations we require are affine, the most important being: Scaling Translating Rotating

[x, y, z, s] is equivalent to [x/s, y/s, z/s] Homogenous Cartesian

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]

Graphics Lecture 2: Slide 23

1 0 0 tx

0 1 0 ty

0 0 1 tz

0 0 0 1

=

[x+tx, y+ty, z+tz, 1 ]

For example: 1 0 0 tx

0 1 0 ty

0 0 1 tz

0 0 0 1

has inversion

1 0 0 -tx

0 1 0 -ty

0 0 1 -tz

0 0 0 1

Graphics Lecture 2: Slide 24

4

Scaling

[x, y, z, 1]

Inverting scaling

sx 0 0 0

0 sy 0 0

0 0 sz 0

0 0 0 1

=

[sx*x, sy*y, sz*z, 1]

sx 0 0 0

Graphics Lecture 2: Slide 25

0 sy 0 0

has inversion

1/sx 0 0 0

0 1/sy 0 0

0 0 1/sz 0

0 0 0 1

Combined transformations

Suppose we want to make an object at the origin twice as big and then move it to a point [5, 5, 20].

We multiply out the transformation matrices first, then transform the points

The transformation is a scaling followed by a translation: [x, y, z, 1]

2 0 0 0

0 2 0 0

0 0 2 0

0 0 0 1

1 0 0 5

0 1 0 5

[x',y',z',1] = 0 0 1 20

Graphics Lecture 2: Slide 27

Transformations are not commutative The order in which transformations are applied matters: In general T * S is not the same as S * T

[x, y, z, 1]

2 0 0 5

0 0 0 1

0 2 0 5

0 0 2 20

0 0 0 1

Graphics Lecture 2: Slide 28

The order of transformations is significant Y

Graphics Scene (Square at origin)

X

Y

Translate x:=x+1

Y

X

Scale x:=x*2

X

Y

Y Scale x:=x*2

Translate

x:=x+1

Graphics Lecture 2: Slide 29

0 0 0 1

Graphics Lecture 2: Slide 26

Combining transformations

[x',y',z',1] =

0 0 sz 0

X

X

Graphics Lecture 2: Slide 30

5

Rotation

Rotation Matrices

To define a rotation we need an axis. The simplest rotations are about the Cartesian axes eg

Rx =

1 0 0 0

0 Cos(θ) -Sin(θ) 0

0 Sin(θ) Cos(θ) 0

0 0 0 1

Rz =

Cos(θ) -Sin(θ) 0 0

Sin(θ) Cos(θ) 0 0

0 0 1 0

0 0 0 1

Rx - Rotate about the X axis Ry - Rotate about the Y axis Rz - Rotate about the Z axis Graphics Lecture 2: Slide 31

Deriving Rz

Ry =

Cos(θ) 0 Sin(θ) 0

0 1 0 0

0 0 0 1

-Sin(θ) 0 Cos(θ) 0

Graphics Lecture 2: Slide 32

Y

Signs of Rotations

[X', Y'] Rotate by θ

Rotations have a direction.

r θ

r

The following rule applies to the matrix formulations given in the notes:

[X,Y]

φ

X [X,Y] = [r Cosφ, r Sinφ] [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

Inverting Rotation

Rotation is clockwise when viewed from the positive side of the axis

Graphics Lecture 2: Slide 34

Inverting Rz

Inverting a rotation by an angle θ is equivalent to rotating through an angle of -θ, now Cos(-θ) = Cos(θ) and

Cos(θ) -Sin(θ) 0 0

Sin(θ) Cos(θ) 0 0

0 0 1 0

0 0 0 1

has inversion

Cos(θ) Sin(θ) 0 0

-Sin(θ) Cos(θ) 0 0

0 0 1 0

0 0 0 1

Sin(-θ) = -Sin(θ)

Graphics Lecture 2: Slide 35

Graphics Lecture 2: Slide 36

6

Related Documents

Graphics Slides 02
November 2019 8
Graphics Slides 07
November 2019 11
Graphics Slides 13
November 2019 12
Graphics Slides 06
November 2019 10
Graphics Slides 01
November 2019 9
Graphics Slides 08
November 2019 12