pan right p p
play

pan right P P Similarly, a pan up moves P down. 1 So, a pan of p - PDF document

Basic 2D Graphical Representations and Transformations Homogeneous Coordinates (2 Dimensional) A coordinate is a triple: x x xw = w w ( x , y ) y where y yw = = w w w w 0


  1. Basic 2D Graphical Representations and Transformations Homogeneous Coordinates (2 Dimensional) A coordinate is a triple: x x xw = � � w w � � ( x , y ) y where y yw = = w w � � w w 0 � � � � � x � � � � w is usually set to 1, so the point ( x , y ) y . = � � 1 � � � � Transformation Matrices x � � � � A transformation of a point P y can be represented as a 3 x 3 matrix T and the = � � 1 � � � � transformed point P t is given by P t = TP. Example: Translating a point by ( t x ,t y ). x t x 1 0 t + � � � � � � x x � � � � � � P y t T y where T 0 1 t = + = = t � y � � � � y � 1 1 0 0 1 � � � � � � � � � � � � If we pan right, then a point P moves left. pan right P P Similarly, a pan up moves P down. 1

  2. So, a pan of p in the x-direction and q in the y-direction gives a transformation matrix: 1 0 p � � � � � T 0 1 q = � � � 0 0 1 � � � � Zooming 0 x 0 � � � � � � � � � � � � Consider a line from 0 to y . If we zoom about the point 0 so that the line is twice as � � � � � � 1 1 1 � � � � � � � � � � � � 0 2 x � � � � � � � � big, then the line is from 0 to 2 y on the display. � � � � 1 1 � � � � � � � � x x � � � � � � � � If we zoom about the point y , then y doesn’t change on the display. But, the other end of � � � � 1 1 � � � � � � � � x x � � � � � � � � � the line moves so that the line is twice as long. So, the line is from y to y on the � � � � � 1 1 � � � � � � � � display. How do we represent this in matrix form? 0 2 0 0 � � � � � � � � Clearly, the zoom about 0 is a simple scale Z 0 2 0 and a general scale is = 2 � � � � 1 0 0 1 � � � � � � � � s 0 0 � � x � � S 0 s 0 = y � � 0 0 1 � � � � Now, a zoom about an arbitrary point P can be made by: • Translating P to the origin. • Zooming about the origin. • Translating the origin back to P. x 1 0 x 1 0 x � � � � � � � � � � � � � Note, for P y T origin 0 1 y and T back 0 1 y . = = � = � � � � � � 1 0 0 1 0 0 1 � � � � � � � � � � � � 2

  3. 1 0 x 1 0 x 1 0 0 � � � � � � � � � � � � � � 1 But, T T 0 1 y 0 1 y 0 1 0 . So, T T = � = = origin back origin back � � � � � � 0 0 1 0 0 1 0 0 1 � � � � � � � � � � � � Therefore, a zoom, Z , about P (where T p translates P to the origin) of a point Q is: • Translate, T p Q • Zoom, Z ( T p Q ) 1 1 • Translate back, T � ( Z ( T Q )) T � ZT Q = p p p p 1 Note, if we are zooming a scene, we can compute T p ZT � first, and then, apply it to all p points. Also, we don’t need to compute every point. We can compute a clipping rectangle by • Taking the current window edges as a rectangle, W , in the screen-coordinate system. 1 1 • Compute the inverse of the zoom about P, T Z T . � � p p 1 1 • Compute a clipping rectangle, W ' T Z T W . � � = p p • Objects outside of W are not on the display and don’t need to be transformed. ' In principle, all objects should be kept in a global coordinate system (world coordinates) and each viewport (window) should keep a current transformation matrix V . 1 1 1 Now, W ' T Z � T � V � W = p p 3

  4. Cohen-Sutherland Line Clipping We need an efficient way to clip a picture to the visible window. If one assumes that most objects are represented as collections of lines, then the Cohen-Sutherland line clipping algorithm is very efficient. Divide the world into a tick-tac-toe (crosses and noughts) board and assign binary bit codes according to the following diagram. Basically, each bit is a 1 if the region lays to the right, above, below, or to the left. Using the diagram, compute the bit codes for the points A and B on the line AB . Now for bit codes a and b from A and B respectively, if a | b = 0 then AB is entirely visible. if a & b ≠ 0 then AB is entirely invisible otherwise, split the line on a boundary of the visible area and recursively test each new line segment 1100 0100 0101 0000 1000 0001 Visible Region 1010 0010 0011 4

  5. Other Transformations Other common graphical transformations are also represented in this way. They include: Rotations: cos sin 0 � � � � � � sin cos 0 � � � � � 0 0 1 � � � � Reflections: 1 0 0 � � � � 0 1 0 about the x-axis � � � 0 0 1 � � � � 1 0 0 �� � � � 0 1 0 about the y-axis � � 0 0 1 � � � � 1 0 0 � � � � � 0 1 0 relative to the origin (about the z-axis) � � � 0 0 1 � � � � 0 1 0 � � � � 1 0 0 about the line x=y � � 0 0 1 � � � � These can, of course, be combined to reflect about arbitrary lines. For example, the reflection relative to an arbitrary point, P = ( x , y ) , would be obtained by translating it to the origin, reflecting relative to the origin and translating back. Or, 1 0 x 1 0 0 1 0 x 1 0 2 x � � � � � � � � � � � � � � � � � � � 0 1 y 0 1 0 0 1 y 0 1 2 y � � = � � � � � � � � � 0 0 1 0 0 1 0 0 1 0 0 1 � � � � � � � � � � � � � � � � Affine Transforms All of the above are examples of affine transforms. Affine transforms have the property: T ( P ( Q P ) TP ( TQ TP ) + � � = + � � They map the standard affine space of R 3 ( R 3 = ( x , y , z ) : z 1 ) into itself. � = The transformation matrices always have inverses. In fact, for a “zoom and pan” transform 5

  6. z 0 x 1 / z 0 x / z � � � � � � � � � 0 z y the inverse is 0 1 / z y / z . Which is fortunate because normally � � � � � 0 0 1 0 0 1 � � � � � � � � computing the inverse of a matrix is computationally expensive. This would mean that computing the clipping window would be expensive as well. Theorem: Combinations of rotations, translations, and scales have inverses. Note, that all are square matrices and have inverses. Let A and B be arbitrary rotations, translations, or scales and AB be an arbitrary combination. Then, A -1 and B -1 exist, and ( ) 1 1 1 1 1 1 1 ( AB )( B � A � ) ABB � A � A BB � A � AA � I = = = = So, B -1 A -1 is the inverse of AB and the inverse of the combination exists. 6

  7. Extensions to 3D Points are represented in the standard homogeneous vector space of R 4 . x � � � � y That is in the form � � . z � � � � 1 � � Similarly, transformations are 4 x 4 matrices. s 0 0 0 1 0 0 x � � � � � � � � 0 s 0 0 0 1 0 y � � � � Zoom ⇒ , Translate ⇒ 0 0 s 0 0 0 1 z � � � � � � � � 0 0 0 1 0 0 0 1 � � � � One Point Perspective Projection For simplicity, let’s assume that the z-axis goes through the center of the projection plane, is perpendicular to it, and z = 0 in the plane. Then, • The perspective transformation maps a world point, ( x,y,z ) along the line between it and the center of projection. (See the diagram.) • So, the point ( x,y,z ) is mapped to ( x p ,y p ) on the projection plan. 7

  8. We can write the projection line in parametric form as: x ' x xu = � y ' y yu = � z ' z ( z d ) u = � + where 0 � u 1 � if u =0, then ( ) ( ) x ' , y ' , z ' x , y , z . (The point is in the projection plane.) = if u =1, then ( ) ( ) x ' , y ' , z ' 0 , 0 , d . (The point is in the same z-plane as the projection point.) = Now, on the projection plane z ' = 0 . So, we can solve for u. 0 z ( z d ) u = � + z ( + z d ) u = u z /( z d ) = + and x p x xz /( z d ) x ( 1 z /( z d )) x (( z d z ) /( z d ) xd /( z d ) x /( z / d 1 ) = � + = � + = + � + = + = + y p y yz /( z d ) y ( 1 z /( z d )) y (( z d z ) /( z d ) yd /( z d ) y /( z / d 1 ) = � + = � + = + � + = + = + z 0 = p In matrix form this is: 1 /( z / d 1 ) 0 0 0 + � � � � 0 1 /( z / d 1 ) 0 0 + � � 0 0 0 0 � � � � 0 0 1 /( z d ) 1 /( z / d 1 ) + + � � Note, perspective projections may be 1, 2, or 3 point. The number of points is controlled by the orientation of the plane • Plane parallel to 2 principle axes ⇒ 1-point. • Plane parallel to 1 principle axis ⇒ 2-point. • Plane parallel to no principle axes ⇒ 3-point. 8

Recommend


More recommend