geometry objects & transformation transformation.pdf · basic geometric elements •geometry...

143
Geometry Objects & Transformation Teacher: A.prof. Chengying Gao(高成英) E-mail: [email protected] School of Data and Computer Science Computer Graphics

Upload: others

Post on 19-Aug-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Geometry Objects & Transformation

Teacher: A.prof. Chengying Gao(高成英)

E-mail: [email protected]

School of Data and Computer Science

Computer Graphics

Page 2: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Outline

• Geometry

• Representation

• Transformation

• Transformation in OpenGL

2Computer Graphics

Page 3: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Basic geometric elements

• Geometry study the relationship among objects in N-dimensional

space

• In computer graphic, we mainly focus on objects in 2D & 3D space.

• Hoping to get a minimum set of geometric shapes and we can

construct complex object base on it.

• Three basic geometric elements

• Scalar

• Vector

• Point

3Computer Graphics

Page 4: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Scalar

• Scalar can be defined as a member of collection

• Collection has two operation (addition and multiplication).

• They comply with some basic arithmetic axioms

(associativity law, commutatively law, inverse)

• real numbers, complex numbers, and rational functions.

• Scalar doesn’t have geometric properties

4Computer Graphics

Page 5: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Vector

• Definition: vector is a line having the two properties

• Direction

• Length: |v|

• Examples:

• Power

• Speed

• Directed line segment

5Computer Graphics

Page 6: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Vector operations

6Computer Graphics

• Each vector has an inverse– Same length but different directions

• Each vector can be multiplied by a scalar

• A zero vector– Length is 0, direction is uncertain

• Sum of two vectors is a vector– Triangle law

Page 7: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Inner product(Dot product)

7Computer Graphics

Page 8: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Orthonormal Vector

8Computer Graphics

Page 9: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Orthonormal Vector

9Computer Graphics

Page 10: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Coordinates and Vectors

10Computer Graphics

Page 11: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Dot product between two vectors

11Computer Graphics

Page 12: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Dot product: some applications in CG

• Find angle between two vectors (e.g. cosine of angle

between light source and surface for shading)

• Finding projection of one vector on another (e.g.

coordinates of point in arbitrary coordinate system)

• Advantage: can be computed easily in Cartesian

components

12Computer Graphics

Page 13: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Cross Product

13Computer Graphics

Page 14: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Cross Product

14Computer Graphics

Page 15: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Normals

15Computer Graphics

• Each plane has a vector n perpendicular to itself

• If a plane is determined with a point and twovectors

• we can get n by the following equation

Page 16: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Linear space

• The most important mathematical space is the (linear)

vector space.

• Two basic geometric elements:

• scalar, vector

• Operation

• Scalar multiplication:

• Vector addition:

16Computer Graphics

Page 17: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Linear combination

• Given n vectors v1, v2, …, vn and n scalar a1, a2, …, an,then

is also a vector, called the linear combination of thisset of vectors.

• Irrelevant with coordiante

Page 18: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Vectors have no positions

18Computer Graphics

Page 19: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Point

• Position in space

• Use uppercase letters

• Operational between points and vectors

• Subtraction with two points, we can get a vector

• Addition with a point and a vector, we get a point

19Computer Graphics

Page 20: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Affine space

• Space constructed by points and vectors

• Operational:

• Vector + Vector = Vector

• Scalar x Vector = Vector

• Point + Vector = Point

• Scalar + Scalar = Scalar

20Computer Graphics

Page 21: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Linear combination of points

• Fixed coordinate system, given two points, what is P1+ P2?• P1 is origin, P1 + P2 = P2

• P1 and P2 are symmetric on origin, P1 + P2 = origin

• The Positions of P1, P2 are relevant with coordiante

• Combination coefficients have limitations• When , linear combination of points is a

point

• = point + vector = point

Page 22: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Affine convex combination

22Computer Graphics

Page 23: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Convex Hull

• The minimum convex contains P1, P2, …, Pn

• Can use the “Shrink” method to get it

23Computer Graphics

Page 24: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Line

• All points comply with the following form

24Computer Graphics

Page 25: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Parametric form

25Computer Graphics

Page 26: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Rays and segments

26Computer Graphics

Page 27: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Linear interpolation

27Computer Graphics

Page 28: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Polygon deformation

• Given two lines with the same number of vertices, we can get a

smooth transition from the first to the second polyline

28Computer Graphics

Page 29: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Man to Woman

29Computer Graphics

Page 30: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Celebrity Face

30Computer Graphics

Page 31: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Curve and Surface

• Curve is single parameter

defined geometry with form

P(a), the function is non-linear.

• Surface is define with P(a, b),

the function is non-linear.

• linear function is plane &

polygon

31Computer Graphics

Page 32: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Plane

• A plane is determined by a point with two vectors or three

points

32Computer Graphics

Page 33: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Triangle

33Computer Graphics

Page 34: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Outline

• Geometry

• Representation

• Transformation

• Transformation in OpenGL

34Computer Graphics

Page 35: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Representation

• Until now we have only discussed the geometric objects,

without using any reference frame, for example, the coordinate

system

• Requires a reference point and the frame to contact with

objects in the physical world

• Position: Where is a point?(if there is not frame, we can not

answer it)

• World coordinate system

35Computer Graphics

Page 36: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Coordinate

36Computer Graphics

Page 37: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Example

37Computer Graphics

• Note that the above statement is relative to a particular basis

• Eg: OpenGL represents a vector with respect to the world

coordinate system, it is necessary to transform to the camera

coordinate system .

Page 38: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Coordinate

38Computer Graphics

Page 39: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Frame

• Coordinate system is insufficient to represent points.

• We need an origin to construct a frame. The origin and the

basis vectors determine a frame (标架).

39Computer Graphics

Page 40: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Representation in frame

40Computer Graphics

Page 41: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Point and Vector confusion

41Computer Graphics

Page 42: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Unified representation

42Computer Graphics

Page 43: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Homogeneous coordinate

43Computer Graphics

Page 44: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Homogeneous coordinate and CG

• Homogeneous coordinates is the key to all computer

graphics systems

• All standard transform (rotate, zoom) can be applied to 4 ×4 matrix multiplication

• Hardware pipeline system can be applied to the four-

dimensional representation

• For the orthogonal projection, you can ensure vector by w =

0, ensure point by w = 1

• For perspective projection, the need for special treatment:

perspective division

44Computer Graphics

Page 45: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Coordinate transformation

45Computer Graphics

Page 46: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Use 1st Basis to represent 2nd

46Computer Graphics

Page 47: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Matrix form

47Computer Graphics

Page 48: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Changing the frame

• Perform similar operation to homogeneous coordinate

• Consider frame

• Any vector or point can be represented by one of them

48Computer Graphics

Page 49: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

One Frame represent another

49Computer Graphics

Page 50: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

One Frame represent another

50Computer Graphics

• where now M is the 4 × 4 matrix

• M is called the matrix representation of the change of

frames.

Page 51: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

One Frame represent another

• We can also use M to compute the changes in the

representations directly.

• Suppose that a and b are the homogeneous coordinate

representations either of two points or of two vectors in

the two frames. Then

• Hence:

51Computer Graphics

Page 52: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

One Frame represent another

52Computer Graphics

Page 53: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Transform representation

53Computer Graphics

Page 54: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Advantages of affine transformation

• All of the affine transformation remain linearity

• The most important is that all affine transformations can be

represented as matrix multiplications in homogeneous

coordinates.

• The uniform representation of all affine transformations makes

carrying out successive transformations far easier than in three-

dimensional space.

• modern hardware implements homogeneous coordinate

operations directly, using parallelism to achieve high-speed

calculations.

54Computer Graphics

Page 55: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Movement of the camera

55Computer Graphics

Page 56: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Outline

• Geometry

• Representation

• Transformation

• Transformation in OpenGL

56Computer Graphics

Page 57: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

General transformation

• The so-called transformation is to map points to other points,

the vectors are mapped to other vectors

57Computer Graphics

Page 58: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Linear Transformations

58Computer Graphics

Page 59: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Affine Transformations

59Computer Graphics

Page 60: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Affine transformation

• Maintaining collinearity

• Many important physical feature of transformation

• Rigid transformation: rotation, translation(Only alter position

and Orientation)

• Other affine transformations(Scaling, shear) will alter object’s

shape.

• In CG world,we just need to change the line of the two

endpoints, and the system automatically after the conversion

to draw the line between the two endpoints.

60Computer Graphics

Page 61: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Why we need transformation?

• Procedures to compute new positions of objects

• Used to modify objects or to transform (map) from one coordinate system to another coordinate system

61Computer Graphics

Page 62: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Function 1

• Construct scenes

62Computer Graphics

Page 63: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Function 1

• Construct 3D scene

63Computer Graphics

Page 64: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Function 1

• Snowflake structure

64Computer Graphics

Page 65: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Function 2

• The designer may want to view object from different angles of

the same scene, then he can:

• the object is fixed, the position of the camera is transformed

65Computer Graphics

Page 66: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Function 3

• In computer animation, in the adjacent frames, the position of

several objects move relative to each other.

• This is done by translating and rotating the local coordinate system.

66Computer Graphics

Page 67: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Pipeline

67Computer Graphics

Page 68: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Translation

• Put a point to a new position

• Determined by a vector d

• Three free degrees

• P’ = P + d

68Computer Graphics

Page 69: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Translation of objects

• Translate all points of an object along the same vector.

69Computer Graphics

Before After

Page 70: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Representation of Translation

• Homogeneous coordinates in a frame

• Then p’ = p + d or

70Computer Graphics

注意:这个表达式是四维的,而且表示的是:

点 = 点 + 向量

Page 71: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Translation matrix

• Using a 4 × 4 homogeneous coordinates matrix T to represents

the translation

• p’ = Tp

• This form is more easily achieved, because all the affine

transformation can be used in this kind of form

71Computer Graphics

Page 72: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

2D rotation

72Computer Graphics

Page 73: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

2D rotation

• Consider θ degrees rotation about the origin

73Computer Graphics

cos(A+B) = cosAcosB-sinAsinB

sin(A+B) = sinAcosB+cosAsinB

y

x

y

x

cossin

sincos

'

'

Page 74: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Simple Rotate

74Computer Graphics

Page 75: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Simple Rotate

75Computer Graphics

Page 76: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Simple Rotate

76Computer Graphics

Page 77: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Simple Rotate

77Computer Graphics

Page 78: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

3D rotation

• Several special conditions:

• Respectively rotatable around the x, y, z-axis

• Rotate along the general axis through the origin

• Rotate along a general axis except the origin

78Computer Graphics

Page 79: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

3D rotation around Z-axis

79Computer Graphics

Page 80: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

3D rotation around Z-axis

80Computer Graphics

Page 81: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

3D rotation around X-axis

81Computer Graphics

Page 82: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

3D rotation around X-axis

82Computer Graphics

Page 83: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

3D rotation around Y-axis

83Computer Graphics

Page 84: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

3D rotation around Y-axis

84Computer Graphics

Page 85: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Rotate along the general axis through the origin

• Can be decomposed as the combination of rotation on x, y, z

axis

• Note that the rotation order can not be exchanged

85Computer Graphics

Page 86: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Rotate around a fixed point except origin

• Move the fixed point to origin

• Rotate

• Move the fixed point back to its initial place

86Computer Graphics

Page 87: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

• P rotates to P’ with respect to the axis by

y

z

P

P’

x

Rotation surrounding a general axis

• Given axis defined by two points(已知旋转轴):

• We derive the rotation matrix by composition

Page 88: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

(2) Rotate surrounding z-axis by

Three steps (三步骤)

y

z

x

l

y

z

x

l

y

z

x

l

(1) Transform l such that it overlaps with z-axis

(3) Reverse transform

Page 89: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Step 1

(1) Transform l such that it overlaps with z-axis: can be decomposedthree step again

(1a) Translate such that l passes through the origin

(1b) Rotate surrounding x-axis such that l locate on the ZOX plane

(1c) Rotate around y-axis such that l locate on the ZOX plane

Page 90: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

y

z

x

P

P’

(1a) Translation to P1

y

z

P

P’

x

Page 91: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

1b) Rotate by surrounding X-axis

y

z

x

角应当是l在YOZ平面

的投影与z轴的夹角。因此:

Page 92: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

y

z

x

1c) Rotate by surrounding y-axis

这个 角应当是l旋转到ZOX

平面后与Z轴的夹角。因此:

Page 93: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

y

z

x

Step 2:

Rotate by in terms of z-axis

Page 94: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Use reverse transformation to derive final

transformation

Step 3:

Page 95: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Scaling

95Computer Graphics

• Scale along each coordinate (origin is fixed point)

Page 96: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Matrix Notations for Transformations

96Computer Graphics

Page 97: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Matrix Representations and Homogeneous Coordinates

97Computer Graphics

Page 98: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Inverses in 3D!

98Computer Graphics

Transformation Matrix Inverse

Scaling

Rotation

Translation

Page 99: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Composite transformation

• Often want to combine transforms(E.g. first scale by 2, then

rotate by 45 degrees

• Advantage of matrix formulation: All still a matrix

• Because many vertices have the same transformation, the price to

construct matrix M = ABCD is small

• The difficulty is how to construct a transformation matrix to

meet the requirements in accordance with the requirements of

the application

99Computer Graphics

Page 100: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Matrix Composition

• matrices are convenient, efficient way to represent series of transformations• hardware matrix multiply

• From the mathematical point of view, the following representation is equivalent:matrix multiplication is associative• p′ = (T*(R*(S*p)))

• p′ = (T*R*S)*p

• procedure• correctly order your matrices!

• multiply matrices together

• result is one matrix, multiply vertices by this matrix

• all vertices easily transformed with one matrix multiply

Page 101: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Matrix Multiplication is Not Commutative (不可交换)

101Computer Graphics

Transformation sequence is not commutative

Page 102: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Matrix Multiplication is Not Commutative

102Computer Graphics

Page 103: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Matrix Multiplication is Not Commutative

103Computer Graphics

Page 104: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Properties of Transformations

104Computer Graphics

Page 105: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

105

Transforming Geometric Objects

• lines, polygons made up of vertices• transform the vertices

• interpolate between

• does this work for everything? no!• normals are trickier

Page 106: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

106

Computing Normals

• normal• direction specifying orientation of polygon

• W = 0 means direction with homogeneous coords

• W = 1 for points of object vertices

• used for lighting• must be normalized to unit length

• can compute if not supplied with object

N

1P2P

3P)()( 1312 PPPPN

N

Assume vertices ordered CCW when viewed from visible side of polygon

Page 107: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

107

Transforming Normals

• so if points transformed by matrix M, can we just transform normal vector by M too?• translations OK: w = 0 means unaffected

• rotations OK

• uniform scaling OK

• these all maintain direction

010000

'

'

'

333231

232221

131211

z

y

x

Tmmm

Tmmm

Tmmm

z

y

x

z

y

x

Page 108: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

108

Transforming Normals

• nonuniform scaling does not work

• x- y =0 plane • line x = y

• normal: [1,-1,0] • direction of line x = -y

• (ignore normalization for now)

Page 109: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

109

Transforming Normals

• apply nonuniform scale: stretch along x by 2• new plane x = 2y

• normal is direction of line x = -2y or x+2y=0

• transformed normal: [2,-1,0]

• not perpendicular to plane!

• should be direction of 2x = -y

2

1

0

0

2 0 0 0

0 1 0 0

0 0 1 0

0 0 0 1

1

1

0

0

Page 110: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

110

Planes and Normals

• plane is all points perpendicular to normal• (with dot product)

• (matrix multiply requires transpose)

• Implicit form: plane =

N P 0

NT P 0

w

z

y

x

P

d

c

b

a

N ,

ax by cz d

Page 111: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

111

MPP 'P

N QNN '

NTP 0 if QT

M I

0'' PN T

0)()( MPQN T

0MPQN TT

IMQT

Q M1 T

given M,what should Q be?

stay perpendicular

substitute from above

thus the normal to any surface can be transformed by the inverse transpose of

the modelling transformation

Finding Correct Normal Transform

• transform a plane

(AB)T BTAT

Page 112: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Outline

• Geometry

• Representation

• Transformation

• Transformation in OpenGL

112Computer Graphics

Page 113: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Programing Transformations

113Computer Graphics

Page 114: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Current Transformation Matrix (CTM)

• CTM is a 4x4 homogenous coordinate matrix. It is also part

of the states. It will be altered by a set of functions and

applied to all vertex through pipeline.

• CTM is determined via application.

114Computer Graphics

Vertex Vertex

Page 115: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Change the CTM

115Computer Graphics

Page 116: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Rotation around a fixed point

• Start from Identity: C I

• Move the fixed point to origin: C CT

• Rotate: C CR

• Move the point back: C CT-1

• Result: C = TRT-1

• Every transformation corresponds to a function of OpenGL.

116Computer Graphics

Page 117: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

CTM in OpenGL

• There is a model-view matrix and a projection matrix in

the pipeline of OpenGL.

• The combination of these two matrices is CTM in OpenGL.

117Computer Graphics

Page 118: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Using OpenGL Matrices

118Computer Graphics

• Use the following function to specify which matrix you

are changing:

• glMatrixMode(whichMatrix): whichMatrix = GL_PROJECTION |

GL_MODELVIEW

• To guarantee a “fresh start”, use glLoadIdentity();

• Loads the identity matrix into the active matrix

Page 119: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Using OpenGL Matrices

119Computer Graphics

Page 120: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Matrix Stacks

• In many cases we need to preserve the transformation matrix in order to use them later

• Traversing the hierarchical data structure

• When execute the display list, avoid to change the state

• advantages• no need to compute inverse matrices all the time• avoids incremental changes to coordinate systems

• accumulation of numerical errors

• practical issues• in graphics hardware, depth of matrix stacks is limited

• (typically 16 for model/view and about 4 for projective matrix)

Page 121: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Matrix Stacks

• challenge of avoiding unnecessary computation• using inverse to return to origin

• computing incremental T1 -> T2

Object coordinates

World coordinates

T1(x)T2(x)

T3(x)

Page 122: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Matrix Stacks

Page 123: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Matrix Stacks

Page 124: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Matrix Stacks

Page 125: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Matrix in OpenGL

125Computer Graphics

Page 126: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Matrix Stacks

glPushMatrix()

glPopMatrix()

A

B

C

A

B

C

A

B

C

C

glScale3f(2,2,2)

D = C scale(2,2,2) trans(1,0,0)

A

B

C

D

DrawSquare()

glTranslate3f(1,0,0)

DrawSquare()

glPushMatrix()

glPopMatrix()

Page 127: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Building the arm

127Computer Graphics

Page 128: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Building the arm

128Computer Graphics

Page 129: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Hierarchical Transformations

129Computer Graphics

Page 130: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Hierarchical Transformations

130Computer Graphics

Page 131: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Transformation Hierarchy Example

4

15 3

2

x

y

glTranslate3f(x,y,0);glRotatef( ,0,0,1);DrawBody();glPushMatrix();

glTranslate3f(0,7,0);DrawHead();

glPopMatrix();glPushMatrix();

glTranslate(2.5,5.5,0);glRotatef( ,0,0,1);DrawUArm();glTranslate(0,-3.5,0);glRotatef( ,0,0,1);DrawLArm();

glPopMatrix();... (draw other arm)

1

2

3

Page 132: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

132

Monkeys!

Page 133: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

133

Monkeys!

Page 134: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

134

Giraffes!

Page 135: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

135

Giraffes!

Page 136: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

136

Kangaroos!

Page 137: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Quaternions(四元数)

• Quaternions were invented by Hamilton, W. R. , a Ireland mathematicians

• Quaternions are an extension of complex numbers that provide an alternative method for describing and manipulating rotations.

• Less intuitive than our original approach, quaternions provide advantages for animation and hardware implementation of rotation.

Page 138: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

• In three dimensions, the problem is more difficult because to specify a rotation about the origin we need to specify both a direction (a vector) and the amount of rotation (a scalar)

• One solution is to use a representation that consists of both a vector and a scalar. Usually, this representation is written as the quaternion

where q = (q1, q2, q3). The operations among quaternions

are based on the use of three “complex” numbers i, j, and k

with the properties

These numbers are analogous to the unit vectors in three

dimensions, and we can write q as:

Quaternions

Page 139: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

• the quaternion a、b are given by :

• quaternion addition and multiplication

Operational Rule of Quaternions

• a magnitude for quaternions in the normal manner as

• the inverse of a quaternion

Page 140: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Quaternions and Rotation

• Suppose that we use the vector part of a quaternion to represent a point in space

Thus, the components of p = (x, y, z) give the location of the point.

• Consider the quaternion:

where v has unit length. We can then show that the quaternion

r is a unit quaternion (|r| = 1), and therefore

Page 141: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Quaternions and Rotation

• If we consider the quaternion product of the quaternion p that represents a point with r, we obtain the new quaternion

and thus p’ is the representation of a point. What is less

obvious is that p’ is the result of rotating the point p by θ

degrees about the vector v.

Page 142: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

• Because we get the same result, the quaternion product formed from r and p is an alternate to transformation matrices as a representation of rotation with a fixed point of the origin about an arbitrary axis.

• If we count operations, quaternions are faster and have been built into both hardware and software implementations.

• In addition to the efficiency of using quaternions instead of rotation matrices, quaternions can be interpolated to obtain smooth sequences of rotations for animation.

Quaternions and Rotation

Page 143: Geometry Objects & Transformation Transformation.pdf · Basic geometric elements •Geometry study the relationship among objects in N-dimensional space •In computer graphic, we

Interface

• A major problem of interactive computer graphics is how to use

the equipment of the two-dimensional (such as a mouse) to

control three-dimensional objects.

• Alternative ways

• Virtual track ball(虚拟跟踪球)

• three–dimensional input device : spaceball(空间球)

• Using Areas of the Screen: According to the different state of the

mouse button, the use of the distance to the center of control

angle, position, and zooming

143Computer Graphics