Top Banner
January 23, 2003 Frank Pfenning Carnegie Mellon University http://www.cs.cmu.edu/~fp/courses/graphics/ Vector Spaces Affine and Euclidean Spaces Frames Homogeneous Coordinates Transformation Matrices [Angel, Ch. 4] Vector Spaces Affine and Euclidean Spaces Frames Homogeneous Coordinates Transformation Matrices [Angel, Ch. 4] Transformations Transformations 15-462 Computer Graphics I Lecture 4
36

Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

Oct 09, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

January 23, 2003Frank PfenningCarnegie Mellon University

http://www.cs.cmu.edu/~fp/courses/graphics/

Vector SpacesAffine and Euclidean SpacesFramesHomogeneous CoordinatesTransformation Matrices

[Angel, Ch. 4]

Vector SpacesAffine and Euclidean SpacesFramesHomogeneous CoordinatesTransformation Matrices

[Angel, Ch. 4]

TransformationsTransformations

15-462 Computer Graphics ILecture 4

Page 2: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 2

Geometric Objects and OperationsGeometric Objects and Operations

• Primitive types: scalars, vectors, points• Primitive operations: dot product, cross product• Representations: coordinate systems, frames• Implementations: matrices, homogeneous coor.• Transformations: rotation, scaling, translation• Composition of transformations• OpenGL transformation matrices

Page 3: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 3

ScalarsScalars

• Scalars α, β, γ from scalar field• Operations α+β, α ¢ β, 0, 1, -α, ( )-1

• “Expected” laws apply• Examples: rationals or reals with addition and

multiplication

Page 4: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 4

VectorsVectors

• Vectors u, v, w from vector space• Includes scalar field• Vector addition u + v• Zero vector 0• Scalar multiplication α v

Page 5: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 5

PointsPoints

• Points P, Q, R from affine space• Includes vector space• Point-point subtraction v = P – Q• Define also P = v + Q

Page 6: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 6

Euclidean SpaceEuclidean Space

• Assume vector space over real numbers• Dot product: α = u ¢ v• 0 ¢ 0 = 0• u, v are orthogonal if u ¢ v = 0• |v|2 = v ¢ v defines |v|, the length of v• Generally work in an affine Euclidean space

Page 7: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 7

Geometric InterpretationsGeometric Interpretations

• Lines and line segments• Convexity• Dot product and projections• Cross product and normal vectors• Planes

Page 8: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 8

Lines and Line SegmentsLines and Line Segments

• Parametric form of line: P(α) = P0 + α d

• Line segment between Q and R:P(α) = (1-α) Q + α R for 0 · α · 1

Page 9: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 9

Convex HullConvex Hull

• Convex hull defined by

P = α1 P1 + L + αn Pnfor a1 + L + an = 1and 0 · ai · 1, i = 1, ..., n

Page 10: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 10

ProjectionProjection

• Dot product projects one vector onto other

u ¢ v = |u| |v| cos(θ)

Page 11: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 11

Normal VectorNormal Vector

• Cross product defines normal vector

• Right-hand rule

u £ v = n|u £ v| = |u| |v| |sin(θ)|

Page 12: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 12

PlanePlane

• Plane defined by point P0 and vectors u and v• u and v cannot be parallel• Parametric form: T(α, β) = P0 + α u + β v• Let n = u £ v be the normal• Then n ¢ (P – P0) = 0 iff P lies in plane

Page 13: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 13

OutlineOutline

• Vector Spaces• Affine and Euclidean Spaces• Frames• Homogeneous Coordinates• Transformation Matrices• OpenGL Transformation Matrices

Page 14: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 14

Coordinate SystemsCoordinate Systems

• Let v1, v2, v3 be three linearly independent vectors in a 3-dimensional vector space

• Can write any vector w as

for scalars α1, α2, α3

• In matrix notation:

w = α1 v1 + α2 v2 + α3 v3

Page 15: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 15

FramesFrames

• Frame = coordinate system + origin P0

• Any point P = P0 + α1 v1 + α2 v2 + α3 v3

• Useful in with homogenous coordinates

Page 16: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 16

Changes of Coordinate SystemChanges of Coordinate System

• Bases {u1, u2, u3} and {v1, v2, v3}• Express basis vectors ui in terms of vj

• Represent in matrix form

Page 17: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 17

Map to RepresentationsMap to Representations

• w = α1 v1 + α2 v2 + α3 v3 , aT = [α1 α2 α3]• w = β1 u1 + β2 u2 + β3 u3 , bT = [β1 β2 β3]

• So a = MT b and b = (MT)-1 a• Suffices for rotation and scaling, not translation

Page 18: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 18

OutlineOutline

• Vector Spaces• Affine and Euclidean Spaces• Frames• Homogeneous Coordinates• Transformation Matrices• OpenGL Transformation Matrices

Page 19: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 19

Linear TransformationsLinear Transformations

• 3 £ 3 matrices represent linear transformations

• Can represent rotation, scaling, and reflection• Cannot represent translation• a and b represent vectors, not points

a = M b

Page 20: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 20

Homogeneous CoordinatesHomogeneous Coordinates

• In affine space, P = α1 v1 + α2 v2 + α3 v3 + P0

• Define 0 ¢ P = 0, 1 ¢ P = P• Then

• Point p = [α1 α2 α3 1]T

• Vector w = δ1 v1 + δ2 v2 + δ3 v3

• Homogeneous coords: a = [δ1 δ2 δ3 0]T

Page 21: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 21

Translation of FrameTranslation of Frame

• Express frame (u1, u2, u3, P0) in (v1, v2, v3, Q0)

• Then

Page 22: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 22

Homogeneous Coordinates SummaryHomogeneous Coordinates Summary

• Points [α1 α2 α3 1]T

• Vectors [δ1 δ2 δ3 0]T

• Change of frame

Page 23: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 23

OutlineOutline

• Vector Spaces• Affine and Euclidean Spaces• Frames• Homogeneous Coordinates• Transformation Matrices• OpenGL Transformation Matrices

Page 24: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 24

Affine TransformationsAffine Transformations

• Translation• Rotation• Scaling• Any composition of the above• Express in homogeneous coordinates• Need 4 £ 4 matrices• Later: projective transformations• Also expressible as 4 £ 4 matrices!

Page 25: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 25

TranslationTranslation

• p’ = p + d where d = [αx αy αz 0]T

• p = [x y z 1]T

• p’ = [x’ y’ z’ 1]T

• x’ = x+αx, y’ = y+αy, z’ = z+αz

• Express in matrix form p’ = T p and solve for T

Page 26: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 26

ScalingScaling

• x’ = βx x• y’ = βy y• z’ = βz z• Express as p’ = S p and solve for S

Page 27: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 27

Rotation in 2 DimensionsRotation in 2 Dimensions

• Rotation by θ about the origin• x’ = x cos θ – y sin θ• y’ = x sin θ + y cos θ• Express in matrix form

• Note determinant is 1

Page 28: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 28

Rotation in 3 DimensionsRotation in 3 Dimensions

• Decompose into rotations about x, y, z axes

Page 29: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 29

Compose by Matrix MultiplicationCompose by Matrix Multiplication

• R = Rz Ry Rx

• Applied from right to left• R p = (Rz Ry Rx) p = Rz (Ry (Rx p))• “Postmultiplication” in OpenGL

Page 30: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 30

Rotation About a Fixed Point Rotation About a Fixed Point

• First, translate to the origin• Second, rotate about the origin• Third, translate back• To rotate by θ about z around pf

M = T(pf) Rz(θ) T(-pf) = ...

Page 31: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 31

Deriving Transformation MatricesDeriving Transformation Matrices

• Other examples: see [Angel, Ch. 4.8]• See also Assignment 2 when it is out• Hint: manipulate matrices, but remember

geometric intuition

Page 32: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 32

OutlineOutline

• Vector Spaces• Affine and Euclidean Spaces• Frames• Homogeneous Coordinates• Transformation Matrices• OpenGL Transformation Matrices

Page 33: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 33

Current Transformation MatrixCurrent Transformation Matrix

• Model-view matrix (usually affine)• Projection matrix (usually not affine)

• Manipulated separately

glMatrixMode (GL_MODELVIEW);glMatrixMode (GL_PROJECTION);

Page 34: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 34

Manipulating the Current MatrixManipulating the Current Matrix

• Load or postmultiply

• Library functions to compute matrices

• Recall: last transformation is applied first!

glLoadIdentity();glLoadMatrixf(*m);glMultMatrixf(*m);

glTranslatef(dx, dy, dz);glRotatef(angle, vx, vy, vz);glScalef(sx, sy, sz);

Page 35: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 35

SummarySummary

• Vector Spaces• Affine and Euclidean Spaces• Frames• Homogeneous Coordinates• Transformation Matrices• OpenGL Transformation Matrices

Page 36: Transformations - Carnegie Mellon School of Computer Sciencefp/courses/graphics/pdf-color/04... · 2003. 1. 23. · TransformationsTransformations 15-462 Computer Graphics I Lecture

01/23/2003 15-462 Graphics I 36

OpenGL Tutors by Nate RobinsOpenGL Tutors by Nate Robins

• Run under Windows• Available at

http://www.xmission.com/~nate/tutors.html• Example: Transformation tutor