810 likes | 945 Views
H331: Computer Graphics. http://www.cs.kuleuven.ac.be/~graphics/H331/ Philip Dutré Department of Computer Science Wednesday, March 3. Today. Transformations of Objects Perspective Viewing Book: Chapter 5, 7. Transformations. Last week: window-to-viewport transformation
E N D
H331: Computer Graphics http://www.cs.kuleuven.ac.be/~graphics/H331/Philip Dutré Department of Computer Science Wednesday, March 3
Today • Transformations of Objects • Perspective Viewing • Book: Chapter 5, 7
Transformations • Last week: window-to-viewport transformation • But … we also want to transform objects in 2D and 3D.
Coordinate systems: 2D & 3D Y Z Y X Y X Left-handed Z X Right-handed
3D Vectors • 3 scalars to describe vector • Add: a+b • Subtract: a-b b a b a
3D Vectors • Linear combination (s and t scalars) c = s.a + t.b • Affine: s + t = 1 • Convex: s, t >= 0
3D Vectors b c Convex combinations a
3D Vectors • Length: |a| = sqrt(ax*ax+ay*ay+az*az) • Dot-product (inner product): a.b = ax*bx + ay*by + az*bz
3D Vectors • Angle between 2 vectors • b.c = |b||c|cos(f) cos(f) = b.c / |b||c| b f a
3D Vectors • Cross-product (outer product) a x b = (ay*bz - az*by, az*bx - ax*bz, ax*by - ay*bx ) Area = |a x b| b a x b a
Homogeneous coordinates • Points: (x y z 1) • Vectors: (x y z 0) • Why?Points and vectors can now be mixed in operations • Key concept in computer graphics
Homogeneous coordinates • E.g. subtraction:(* * * 1) – (* * * 1) = (* * * 0) • E.g. addition(* * * 1) + (* * * 0) = (* * * 1) • Affine linear combinations of points produce another point
Why are transformations useful? • Define objects only once, then transform to compose bigger objects • Translations, rotations, scaling, …
Why are transformations useful? • Define motif, then construct object from motif Use 8 times
Why are transformations useful? • Move camera around
Why are transformations useful? • Computer animation • Translate / rotate / warp object over time
2D transformations • Each point can be expressed in a coordinate system: P = Pxi + Pyj + origin P (Px, Py,1) j Homogeneous coordinates origin i
2D Transformations • Q = T(P) • Affine transformation: coordinates of Q are linear combination of coordinates of P
Affine 2D Transformations translation rotation scaling shear
2D Translation Y Y (Qx, Qy,1) Tx Ty (Px, Py,1) X X
2D Scaling Y Y (Qx, Qy,1) (Px, Py,1) X X
2D Rotation Y (Qx, Qy,1) (Px, Py,1) R R + f X
2D Shear Y Y (Qx, Qy,1) (Px, Py,1) X X
Composing transformations • Rotate over 30 degrees • Translate Matrix multiply
Composite transformations • Order is important!!! Y Y Y rotate translate X X X Y Y Y rotate translate X X X
Composite transformations • E.g. Rotating about point • Standard rotation is about origin • Translate rotation centre to origin • Rotate around origin • Translate origin back to rotation centre
Composite transformations Y R X Y X Y Y X X R Tx -Ty Ty -Tx X
Window to viewport: revisited • Window to viewport transformation can also be expressed as 2D transform!!! Object Coordinate System Screen Coordinate System viewport window
Properties of 2D transforms • Affine transformations preserve affine linear combinations
Properties of 2D transforms • Affine transformations preserve lines and planes • Line:
Properties of 2D transforms • Parallellism of lines and planes is preserved • Parallel lines:
Other properties • Relative ratios are preserved • Areas:
3D affine transformations • Same idea, but 4x4 matrices
3D Translation Z Z Y Y TZ TY X X TX
3D Scaling Z Z Y Y SY SZ X X SX
3D Rotation around X-axis Z Z qx Y Y X X
3D Rotation around Y-axis Z Z qy Y Y X X
3D Rotation around Z-axis Z Z Y Y qz X X
Composite 3D transformations • Same ideas as 2D • E.g. rotation around arbitrary axis u • 2 rotations such that u is aligned with x-axis • X-rotation over desired angle • Undo the two rotations to restore u to original direction
Properties of 3D transformations • Preservation of affine linear combinations • Preservation of lines and planes • Parallelism of lines and planes is preserved • Columns reveal transformed coordinate frame • Ratios are preserved • Volumes are scaled by |detM|
Changing coordinate systems • Different way of thinking about coordinate transforms • More natural: • Objects are modeled in their own coordinate system • What are the coordinates of the the transformed object in the world coordinate system?
Changing coordinate systems World coordinate system Object coordinate systems
Transform of coordinate system • origin = (0 0 1); i = (1 0 0); j = (0 1 0)
Transform of coordinate system m2 m1 m3 j origin i
Changing coordinate systems j’ i’ o’=M.origin i’ = M.i j’ = M.j o’ j origin i M transforms (origin, i, j) to (o’, i’, j’)
Changing coordinate systems j’ P b d i’ P = (c,d,1) in (o’, i’, j’) c o’ j origin a i What are the coordinates (a,b,1) of P in (origin, i, j)?
Changing coordinate systems j’ P b d i’ c o’ j origin a i