<<

3D Geometrical Transformations 3D Geometrical Transformations Foley & Van Dam, Chapter 5 • 3D representation • • Scaling, reflection • Shearing • Rotations about x, y and z axis • Composition of rotations • about an arbitrary axis • Transforming planes

3D Coordinate Systems Reminder: UxV Right-handed : z V T U

y VxU x Left-handed coordinate system: U u V nˆ U V sin T y xˆ yˆ zˆ ª u y v z  u z v y º « » U u V u x u y u z « u z v x  u x v z » v v v « u v  u v » z x y z ¬ x y y x ¼ x

3D Point Representation 3D Geometrical Transformations

• A 3D point P is represented in homogeneous • In , 3D affine coordinates by a 4-dimensional vector: transformations are represented by 4x4 matrices: x ª º ª a b c t x º « » y « d e f t » P « » « y » « z » « » « g h i t z » ¬ 1 ¼ « » ¬ 0 0 0 1 ¼ •As for 2D points: •A point transformation is performed: ª x º ª D x º « y » « y » ª x ' º ª a b c t x º ª x º « » « D » p { « y '» « d e f t » « y » « z » « D z » « » « y » « » « » « » 1 « z ' » « g h i t z » « z » ¬ ¼ ¬ D ¼ « » « » « » ¬ 1 ¼ ¬ 0 0 0 1 ¼ ¬ 1 ¼ 3D Translation 3D Scaling

ª a 0 0 0 º ª x º ª x ' º ª ax º P in translated to P' by: « 0 b 0 0 » « y » « y '» « by » « » « » « » « » « » « » « » « » ª 1 0 0 t x º ª x º ª x ' º ª x  t x º 0 0 c 0 z z ' cz « » « » « » « » « » « » « » « » 0 1 0 t y y y ' y  t ¬ 0 0 0 1 ¼ ¬ 1 ¼ ¬ 1 ¼ ¬ 1 ¼ « » « » « » « y » « 0 0 1 t z » « z » « z ' » « z  t z » « » « » « » « » ¬ 0 0 0 1 ¼ ¬ 1 ¼ ¬ 1 ¼ ¬ 1 ¼ Or S P P '

Or: T P P ' z z z

y y y x x x  1 1 S P ' P Inverse: T  P ' P

3D Reflection 3D Shearing

• A reflection through the xy : • Shearing: ª 1 a b 0 º ª x º ª x  ay  bz º « c 1 d 0 » « y » « cx  y  dz » ª 1 0 0 0 º ª x º ª x º « » « » « » « e f 1 0 » « z » « ex  fy  z » « 0 1 0 0 » « y » « y » « » « » « » « » « » « » ¬ 0 0 0 1 ¼ ¬ 1 ¼ ¬ 1 ¼ « 0 0  1 0 » « z » «  z » « » « » « » ¬ 0 0 0 1 ¼ ¬ 1 ¼ ¬ 1 ¼ • Change in each coordinate is a linear combination of all three • Transforms a cube into a general parallelepiped •Reflections through the xz and the yz planes are defined similarly

3D Rotation 3D Rotation

• To generate a rotation in 3D we have to • Counterclockwise rotation about x-axis specify: ª x ' º ª 1 0 0 0 º ª x º « y '» « 0 cos T  sin T 0 » « y » – axis of rotation (2 d.o.f.) « » « » « » « z ' » « 0 sin T cos T 0 » « z » « » « » « » – amount of rotation (1 d.o.f.) ¬ 1 ¼ ¬ 0 0 0 1 ¼ ¬ 1 ¼ •Note, the axis passes through the p ' R x (T ) p y z

z y x x 3D Rotation 3D Rotation

• Counterclockwise rotation about y-axis • Counterclockwise rotation about z-axis ª x ' º ª cos T 0  sin T 0 º ª x º ª x ' º ª cos ș  sin ș 0 0 º ª x º « » « » « » y ' sin cos 0 0 y y ' 0 1 0 0 y « » « ș ș » « » « » « » « » « z ' » 0 0 1 0 « z » « z ' » « sin T 0 cos T 0 » « z » « » « » « » « » ¬« 1 ¼» ¬« 0 0 0 1 ¼» ¬« 1 ¼» ¬ 1 ¼ ¬ 0 0 0 1 ¼ ¬ 1 ¼ p ' R z (T ) p p ' R y (T ) p z z

y y x x

Composite Rotation Change of Coordinates

• Rx, Ry, and Rz, can perform any rotation • Problem: Given the XYZ orthonormal coordinate about an axis passing through the origin system, find a transformation M, that maps a representation in XYZ into a representation in the orthonormal system UVW, with the same origin •Inverse rotation: •The M transforms the UVW vectors to the XYZ vectors z p R 1 (T ) p' R(T ) p' R T (T )

u=(ux,uy,uz) y x

v=(vx,vy,vz)

Change of Coordinates Change of Coordinates

• Solution: M is rotation matrix whose rows • Let's check the transformation of U under M: are U,V, and W: ª u x u y u z 0 º ª u x º ªºuuuxyz0 « v v v 0 » « u » MU « x y z » y «»vvv0 w w w 0 « u » M «»xyz « x y z » « z » « » « 1 » «»wwwxyz0 ¬ 0 0 0 1 ¼ ¬ ¼ «» ¬¼0001 2 2 2 ª u x  u y  u z º ª 1 º • Note: the inverse transformation is the « » 0 0 « » X : « 0 » « 0 » « » « 1 » ª u x v x w x 0 º ¬ 1 ¼ ¬ ¼  1 T « u y v y w y 0 » M M « » • Similarly, V goes into Y, and W goes into Z « u z v z w z 0 » ¬« 0 0 0 1 ¼» Change of Coordinates Rotation About an Arbitrary Axis

• Let's check the transformation of the X axis • Axis of rotation can be located at any point: -1 under M : 6 d.o.f. (we must specify 2 points p1 and p2)

u v w 0 u • The idea: make the axis coincident with ª 1 º ª x x x º ª 1 º ª x º « » « »  1 « 0 » u y v y w y 0 « 0 » u y M 0 « » 0 « » U one of the coordinate axes (z axis), rotate by « » u z v z w z 0 « » u z « 1 » « » « 1 » « » ¬ ¼ ¬« 0 0 0 1 ¼» ¬ ¼ ¬« 1 ¼» T, and then transform back z p p 2 • Similarly, Y goes into V, and Z goes into W 1

y x

Rotation About an Arbitrary Axis Rotation About an Arbitrary Axis

§ 1 0 0  x 1 · y ¨ 0 1 0  y ¸ y Step1: T ¨ 1 ¸ step 3 • 0 0 1 z p p ¨  1 ¸ 1 2 p p1 ¨ 0 0 0 1 ¸ 2 x © ¹ x § u u u 0 · z ¨ x y z ¸ Initial z Rotate the Object v v v 0 • Step 2: M ¨ x y z ¸ Around the z Axis ¨ w x w y w z 0 ¸ ¨ ¸ y y © 0 0 0 1 ¹ p1 step 1 p1 step 4 § cos ș sin ș 0 0 · p2 ¨ ¸ p2 • Step 3: R  sin ș cos ș 0 0 ¨ 0 0 1 0 ¸ x x ¨ ¸ z z © 0 0 0 1 ¹ Translate p to the Origin Rotate the Axis to the 1 § u x v x w x 0 · original ¨ u v w 0 ¸ • Step 4: M  1 ¨ y y y ¸ ¨ u v w 0 ¸ ¨ z z z ¸ y y © 0 0 0 1 ¹ § 1 0 0 x · step 2 p1 step 5 p ¨ 1 ¸ p1 2  1 0 1 0 y • Step 5: T ¨ 1 ¸ ¨ 0 0 1 z 1 ¸ x ¨ ¸ z p2 x © 0 0 0 1 ¹ z Translate to the  1  1 Rotate p2 onto the z Axis • Composition: Original Position P c T M R M T P

Rotation About Arbitrary Axis Transforming Planes • Constructing an orthonormal system along the rotation axis: • Plane representation: – A vector W parallel to the rotation axis: – By three non-collinear points s – By implicit : ªºx s p 2  p 1 ; w s «»y Ax By Cz D >@ A B C D «» 0 – A vector V to W: «»z «» § 0 · ¬¼1 ¨ ¸ ª A B C º a « 1» a w u ¨ 0 ¸ ; v ¬ D D D ¼ ¨ ¸ a © 1 ¹ P1 – A vector U forming a right-handed orthogonal system P2 with W and V: u v w >@x y z 1 u P0 Transforming Planes Transforming Planes

• One way to transform a plane is by transforming • Note that: ªºx any three non-collinear points on the plane «»y >@ABC DTT 1 «» 0 «»z • Another way is to transform the plane equation: «» Given a transformation T such that ¬¼1 T [x, y, z, 1] = [x', y', z', 1] • Thus, the transformation that we should apply to the plane equation is: find [A',B',C',D'], such that: ªºx ' «»y ' ABCDcccc ABCDT1 >@ABC''' D ' «» 0 > @ > @ «»z ' «» ¬¼1