2d geometric transformations
play

2D Geometric Transformations Question : How do we represent a - PDF document

2D Geometric Transformations (Chapter 5 in FVD) 1 2D Geometric Transformations Question : How do we represent a geometric object in the plane? Answer : For now, assume that objects consist of points and lines. A point is represented


  1. 2D Geometric Transformations (Chapter 5 in FVD) 1 2D Geometric Transformations • Question : How do we represent a geometric object in the plane? • Answer : For now, assume that objects consist of points and lines. A point is represented by its Cartesian coordinates: ( x,y ). • Question : How do we transform a geometric object in the plane? • Answer : Let ( A,B ) be a straight line segment and T a general 2D transformation: T transforms ( A,B ) into another straight line segment ( A’,B’ ), where A’=TA and B’=TB . 2

  2. Translation • Translate (a,b): (x,y) (x+a,y+b) Translate(2,4) 3 Scale • Scale (a,b): (x,y) (ax,by) Scale (2,3) Scale (2,3) 4

  3. • How can we scale an object without moving its origin (lower left corner)? Translate(-1,-1) Scale(2,3) Translate(1,1) 5 Reflection Scale(-1,1) Scale(1,-1) 6

  4. Rotation • Rotate( θ): (x,y) (x cos( θ )+y sin( θ ), -x sin( θ )+y cos( θ )) Rotate(90) Rotate(90) 7 • How can we rotate an object without moving its origin (lower left corner)? Translate(-1,-1) Translate(1,1) Rotate(90) 8

  5. Shear • Shear (a,b): (x,y) (x+ay,y+bx) Shear(1,0) Shear(0,2) 9 Composition of Transformations • Rigid transformation: – Translation + Rotation (distance preserving). • Similarity transformation: – Translation + Rotation + uniform Scale (angle preserving). • Affine transformation: – Translation + Rotation + Scale + Shear (parallelism preserving). • All above transformations are groups where Rigid ⊂ Similarity ⊂ Affine. 10

  6. Matrix Notation • Let’s treat a point ( x,y ) as a 2x1 matrix (a column vector):   x     y • What happens when this vector is multiplied by a 2x2 matrix? +       a b x ax by =       +       c d y cx dy 11 2D Transformations • 2D object is represented by points and lines that join them. • Transformations can be applied only to the the points defining the lines. • A point ( x,y ) is represented by a 2x1 column vector, and we can represent 2D transformations using 2x2 matrices:       x ' a b x =        '   d    12

  7. Scale • Scale(a,b): ( x,y ) ( ax,by )       a 0 x ax =             0 b y by • If a or b are negative, we get reflection. 13 Reflection • Reflection through the y axis: −  1 0     0 1 • Reflection through the x axis:   1 0   − 1   0 • Reflection through y=x :   0 1     1 0 • Reflection through y=-x : −   0 1   −   1 0 14

  8. Shear, Rotation • Shear(a,b): (x,y) (x+ay,y+bx) +       1 a x x ay =       +       b 1 y y bx • Rotate( θ ): (x,y) ( x cos θ + y sin θ , - x sin θ + y cos θ ) θ θ θ + θ       cos sin x x cos y sin =       − − + θ θ θ θ       sin cos y x sin y cos 15 Composition of Transformations • A sequence of transformations can be collapsed into a single matrix:     x x [ ][ ][ ] [ ] = A B C D         y y • Note: order of transformations is important! ( otherwise - commutative groups ) translate rotate rotate translate 16

  9. Translation +     x x a → • Translation(a,b):     +     y y b • Problem : Cannot represent translation using 2x2 matrices. • Solution : Homogeneous Coordinates 17 Homogeneous Coordinates • Homogeneous Coordinates is a mapping from R n to R n+1 : → = x y X Y W tx ty t ( , ) ( , , ) ( , , ) • Note: ( tx,ty,t ) all correspond to the same non-homogeneous point ( x,y ). E.g. (2,3,1) ≡ (6,9,3). • Inverse mapping:   X Y →   ( X , Y , W ) ,   W W 18

  10. Translation • Translate(a,b):      +  1 0 a x x a       = + 0 1 b y y b              0 0 1   1   1  • Affine transformation now have the following form:   a b e   c d f      0 0 1  19 Geometric Interpretation W Y (X,Y,W) 1 y x (X,Y,1) X • A 2D point is mapped to a line (ray) in 3D. The non-homogeneous points are obtained by projecting the rays onto the plane Z=1. 20

  11. • Example: Rotation about an arbitrary point: (x 0 ,y 0 ) θ • Actions: – Translate the coordinates so that the origin is at (x 0 ,y 0 ). – Rotate by θ . – Translate back. θ − θ −         1 0 x cos sin 0 1 0 x x 0 0         θ θ − = 0 1 y sin cos 0 0 1 y y         0 0                 0 0 1 0 0 1 0 0 1 1 θ − θ − θ + θ     cos sin x ( 1 cos ) y sin x 0 0     = θ θ − θ − θ sin cos y ( 1 cos ) x sin y     0 0         0 0 1 1 21 • Another example: Reflection about an Arbitrary Line: p 2 p 1 L=p 1 +t (p 2 -p 1 )=t p 2 +(1-t) p 1 • Actions: – Translate the coordinates so that P 1 is at the origin. – Rotate so that L aligns with the x- axis. – Reflect about the x-axis. – Rotate back. – Translate back. 22

  12. Viewing in 2D (Chapter 6 in FVD) World Coordinate Device Coordinate Window Viewport Object in World g n i p p a m D 2 : D 3 2D:2D mapping Device Coordinates World Coordinates • Objects are given in world coordinates . • The world is viewed through a world- coordinate window . • The WC window is mapped onto a device coordinate viewport . 23 Viewing in 2D (cont.) Maximum range of screen Window coordinates Viewport World Coordinates Screen Coordinates (Device Coordinates) Window to Viewport Transformation 24

  13. Window to Viewport Transformation (x max ,y max ) (u max ,v max ) (x min ,y min ) (u min ,v min ) Window in Window Window Translated to World translated scaled to viewport position in Coordinates to origin viewport size. screen coordinates. u max -u min v max -v min M wv = T(u min ,v min ) S( , ) T(-x min ,-y min ) x max -x min y max -y min u max -u min 0 0 1 0 u min 1 0 -x min x max -x min v max -v min = 0 1 v min 0 0 0 1 -y min y max -y min 0 0 1 0 0 1 0 0 1 u max -u min u max -u min 0 x max -x min (-x min ) + u min x max -x min v max -v min v max -v min = 0 y max -y min (-y min ) + v min y max -y min 0 0 1 25

Recommend


More recommend