Tuesday, August 21, 2012

2D & 3D Transformations

2d transform composition

  • the order we perform multiple transforms can matter
    • eg. translate + scale can differ from scale + translate
    • eg. rotate + translate can differ from translate + rotate
    • eg. rotate + scale can differ from scale + rotate (when scale_x differs from scale_y)
  • When does M1 + M2 = M2 + M1?

 M1

 M2

 translate

translate

scale

scale

rotate

rotate

scale (sx = sy)

rotate

  • To prove commutativity (or lack thereof), show that the composed transformation matrices are the same (or different).


Combined form for 2d Transforms

    |  r11  r12  tx  |  M = |  r21  r22  ty  |      |   0    0    1  |
  • upper 2 by 2 submatrix is a composite rotation & scale matrix;
    • t1 and t2 are composed translations
  • precise form of matrix expressions depends upon order of transforms


Coordinate systems: Local and Global

  • With no transformations, there is one global coordinate system in which objects are drawn.
  • When you apply any transformation, this is equivalent to changing the coordinate system. You are defining a local coordinate system within the global system.
  • For example, if you set the scale to 0.5, and then draw a box, that box's coordinate system is 0.5 relative to the global coordinate system.
  • Thinking of transformations as changing the coordinate systems is very useful conceptually, since in most scenes, objects transforms are defined relative to one, but the objects themselves are drawn without regard to the transforms applied to them. This is most easily imagined as if they had differing coordinate systems.


2d transforms: OpenGL implementation

  • OpenGL is immediate mode: graphics operations are applied 'instantly'
    • in terms of transformations, the user gives a rotate, translate, or scale command, and the matrix multiplication represented by that transform is immediately applied to a global transformation matrix
    • In other words, a 4 by 4 matrix of floating point values is maintained. It changes each time a single transformation is done. However, all the individual transformations used to derive these numeric values are not retained.


2d transforms: OpenGL

  • OpenGL transformation commands set up a 4 by 4 transformation matrix, in the way shown on previous overheads
    • Can use glGet(GL_MODELVIEW_MATRIX) to retrieve this matrix, and glLoadMatrix to replace it with your own matrix.
  • we haven't talked about 3d transforms; however, note that homogeneous 3d transformation matrix is 4 by 4; 2D uses subset of it.
  • glRotate{fd} (TYPE angle, TYPE x, TYPE y, TYPE z)
    • TYPE is f or d
    • rotates the current transformation matrix counterclockwise 'angle' degrees about a ray from the origin through the point (x, y, z)
    • eg. glRotatef(45.0, 0.0, 0.0, 1.0) rotates 45 degrees about the z-axis
  • glTranslate {fd} (TYPE x, y, z)
    • translates by the amounts x, y, z
    • note: glTranslatef(): empty argument is the identity matrix
  • glScale {fd} (TYPE x, y, z)
    • applies x, y, z scaling factors
    • eg. glScalef(2.0, -0.5, 1.0)


OpenGL: Order of transformation operations

  • When giving OpenGLtransformation commands, they are applied in the inverse order you give them.
glScaled(1.0, 1.0, 3.0);  glRotatef(45.0, 0.0, 1.0, 0.0);  glTranslatef(3.0, 2.0, 0.0);  draw_my_triangle();
  • the transformations occur in the reverse order
    • This is done to reflect the algebraic order of the matrix transforms: 
      S * R * T * P = S * (R * (T * P) )


2D Transformation inversions

T(dx, dy) * T(-dx, -dy) = 1

R( A) * R(- A) = 1

S(sx, sy) * S( 1/sx, 1/sy) = 1

To invert a sequence of transforms P' = M * P = (Tr1 * Tr2 * ... * TrK) * P

M^(-1) * P = (Tr1 * Tr2 * ... * TrK)^(-1) * P = TrK^(-1) * ... * Tr2^(-1) * Tr1^(-1) * P

  • note how matrix/vector notation is useful here!


OpenGL: Saving and restoring contexts

  • Previously mentioned that OpenGL does not save individual transformations.
    • Implies that application program must retain all the individual transformations, if one ever wants to "undo" them!
  • glPushmatrix(), glPopmatrix(): save and restore transformation matrices
    • you essentially modify & use top matrix on the stack
    • initialize to identity matrix with: glLoadIdentity()
    • Using glPushmatrix() lets you save your current local coordinate system, by copying top (current) transformation matrix onto top of stack.
    • Subsequent transformations manipulate top matrix in stack.
      --> Transformations compound and accumulate into one general transformation.
    • glPopmatrix() then reverts back to previous local coordinate system.
      • Equivalent to applying the inversions of all the transforms done in the meantime.
  • Extremely useful when rendering hierarchical scenes


OpenGL Matrix Modes

  • OpenGL has separate transformation matrices for different graphics features
  • glMatrixMode(GLenum mode), where mode is one of:
    • GL_MODELVIEW - for manipulating model in scene (stack of them for glPushMatrix)
    • GL_PROJECTION - perspective orientation
    • GL_TEXTURE - texture map orientation
  • Make sure you specify glMatrixMode(GL_MODELVIEW) before proceeding with model transformations
  • Likewise, specify glMatrixMode(GL_PROJECTION) when you set up your perspective view (in later topic)
  • glLoadIdentity(): loads a 4-by-4 identity matrix into the current matrix (whatever mode you're in)
    • always initialize with the identity; don't presume it is loaded for you
  • Example 2D OpenGL program: Sierpinski Triangles and example output (level=7).
  • Here's the output when transformations in wrong order.


Properties of affine transformation matrix M

  • lines are preserved (ie. lines remain lines after transform)
  • parallelism is preserved
  • proportional distances are preserved
    • eg. if point P is a fraction F between points A and B before, it will remain so after the transform
  • the change in area of any object transformed is:
    • (area after transform) / (area before transform) = |determinant M |


2D transforms: Shear transformations ("shearing")

 

       | 1  a  0 |            | 1  0  0 |  SHx =  | 0  1  0 |     SHy =  | b  1  0 |         | 0  0  1 |            | 0  0  1 |    x' = x + ay             x' = x  y' = y                  y' = bx + y
  • ... a proportional change in x as a function of y (and vice versa)


3D Transforms

  • 3D space: add a Z coordinate (X, Y, Z)
    • 3D homogeneous coordinates: 4 dimensions
  • Text and OpenGL use a Right-handed rotation system: grab the Z axis with right hand, and curl fingers from +ve X axis to +ve Y axis: thumb points out at you, which is direction of +ve Z axis
    • implies that +ve Z axis points at you when facing the screen with +ve Y pointing up and +ve X pointing right


3D transforms

  • All transformations directly extend to 3D
  • Translation:
               | 1 0 0 dx |  T(dx,dy,dz) =  | 0 1 0 dy |                 | 0 0 1 dz |                 | 0 0 0 1  |
  • Scaling:
               | sx  0  0  0 |  S(sx,sy,sz) =  |  0 sy  0  0 |                 |  0  0 sz  0 |                 |  0  0  0  1 |
  • Rotation:
        | 1      0        0   0 |  Rx(A) = | 0  cos A   -sin A   0 |          | 0  sin A    cos A   0 |          | 0      0        0   1 |             | cos A   0   sin A   0 |  Ry(A) = |     0   1       0   0 |          | -sin A  0   cos A   0 |          |     0   0       0   1 |            | cos A  -sin A   0   0 |  Rz(A) = | sin A   cos A   0   0 |          |     0       0   1   0 |          |     0       0   0   1 |

3d transforms

  • 2D rotations is given by Z axis rotation matrix
  • Note that rotation matrix about Y axis uses "different' signs
    • reason: when you look down Y axis, you have this:

z' = z cos A - x sin A

x' = z sin A + x cos A (as before)

--> but when you put these in matrix form, the X and Z are in reversed order, hence the sign change

  • All these transformation matrices have inverses similar to 2D case


3D transforms

  • composing 3D transforms works same as 2D: write each transformation matrix in the order the transformation sequence is done
    • translation & rotations on same axes are additive, while scaling is multiplicative
    • however, note that rotations on different axis are NOT commutative!
  • general transform:
    | r11  r12  r13  tx |  M = | r21  r22  r23  ty |      | r31  r32  r33  tz |      |   0    0    0   1 |
  • one trick: inverse of the top-left 3 x 3 submatrix: transpose it
    | r11  r12  r13 |  R = | r21  r22  r23 |      | r31  r32  r33 |                            |  r11  -r21  r13 |  R^(-1) = (1/Det R)* | -r12  r22  -r32 |                      |  r31  -r23  r33 |


3D transform properties

  • lines are preserved
  • parallelism is preserved
  • proportional distances are preserved
  • (volume after transformation) / (volume before) = | det M |


Non-affine transform: Fish-eye (angle halver)


Non-affine transforms: inversion in a unit circle

  • Map point P to inverse of its distance from origin
  • circles and lines that do not pass through origin map into circles
  • Derivation:
    • sin(A) = X/(|P|)
    • so: X' = 1/(|P|) sin(A) = (1/(|P|))*(X/(|P|)) = X / (|P|^2)
    • Q = 1/(|P|^2) * P
    • X' = 1/(|P|^2) * X
    • Y' = 1/(|P|^2) * Y

Hackerx Sasi
Don't ever give up.
Even when it seems impossible,
Something will always
pull you through.
The hardest times get even
worse when you lose hope.
As long as you believe you can do it, You can.

But When you give up,
You lose !
I DONT GIVE UP.....!!!

with regards
prem sasi kumar arivukalanjiam

No comments:

Post a Comment

Slider

Image Slider By engineerportal.blogspot.in The slide is a linking image  Welcome to Engineer Portal... #htmlcaption

Tamil Short Film Laptaap

Tamil Short Film Laptaap
Laptapp

Labels

About Blogging (1) Advance Data Structure (2) ADVANCED COMPUTER ARCHITECTURE (4) Advanced Database (4) ADVANCED DATABASE TECHNOLOGY (4) ADVANCED JAVA PROGRAMMING (1) ADVANCED OPERATING SYSTEMS (3) ADVANCED OPERATING SYSTEMS LAB (2) Agriculture and Technology (1) Analag and Digital Communication (1) Android (1) Applet (1) ARTIFICIAL INTELLIGENCE (3) aspiration 2020 (3) assignment cse (12) AT (1) AT - key (1) Attacker World (6) Basic Electrical Engineering (1) C (1) C Aptitude (20) C Program (87) C# AND .NET FRAMEWORK (11) C++ (1) Calculator (1) Chemistry (1) Cloud Computing Lab (1) Compiler Design (8) Computer Graphics Lab (31) COMPUTER GRAPHICS LABORATORY (1) COMPUTER GRAPHICS Theory (1) COMPUTER NETWORKS (3) computer organisation and architecture (1) Course Plan (2) Cricket (1) cryptography and network security (3) CS 810 (2) cse syllabus (29) Cyberoam (1) Data Mining Techniques (5) Data structures (3) DATA WAREHOUSING AND DATA MINING (4) DATABASE MANAGEMENT SYSTEMS (8) DBMS Lab (11) Design and Analysis Algorithm CS 41 (1) Design and Management of Computer Networks (2) Development in Transportation (1) Digital Principles and System Design (1) Digital Signal Processing (15) DISCRETE MATHEMATICS (1) dos box (1) Download (1) ebooks (11) electronic circuits and electron devices (1) Embedded Software Development (4) Embedded systems lab (4) Embedded systems theory (1) Engineer Portal (1) ENGINEERING ECONOMICS AND FINANCIAL ACCOUNTING (5) ENGINEERING PHYSICS (1) english lab (7) Entertainment (1) Facebook (2) fact (31) FUNDAMENTALS OF COMPUTING AND PROGRAMMING (3) Gate (3) General (3) gitlab (1) Global warming (1) GRAPH THEORY (1) Grid Computing (11) hacking (4) HIGH SPEED NETWORKS (1) Horizon (1) III year (1) INFORMATION SECURITY (1) Installation (1) INTELLECTUAL PROPERTY RIGHTS (IPR) (1) Internal Test (13) internet programming lab (20) IPL (1) Java (38) java lab (1) Java Programs (28) jdbc (1) jsp (1) KNOWLEDGE MANAGEMENT (1) lab syllabus (4) MATHEMATICS (3) Mechanical Engineering (1) Microprocessor and Microcontroller (1) Microprocessor and Microcontroller lab (11) migration (1) Mini Projects (1) MOBILE AND PERVASIVE COMPUTING (15) MOBILE COMPUTING (1) Multicore Architecute (1) MULTICORE PROGRAMMING (2) Multiprocessor Programming (2) NANOTECHNOLOGY (1) NATURAL LANGUAGE PROCESSING (1) NETWORK PROGRAMMING AND MANAGEMENT (1) NETWORKPROGNMGMNT (1) networks lab (16) News (14) Nova (1) NUMERICAL METHODS (2) Object Oriented Programming (1) ooad lab (6) ooad theory (9) OPEN SOURCE LAB (22) openGL (10) Openstack (1) Operating System CS45 (2) operating systems lab (20) other (4) parallel computing (1) parallel processing (1) PARALLEL PROGRAMMING (1) Parallel Programming Paradigms (4) Perl (1) Placement (3) Placement - Interview Questions (64) PRINCIPLES OF COMMUNICATION (1) PROBABILITY AND QUEUING THEORY (3) PROGRAMMING PARADIGMS (1) Python (3) Question Bank (1) question of the day (8) Question Paper (13) Question Paper and Answer Key (3) Railway Airport and Harbor (1) REAL TIME SYSTEMS (1) RESOURCE MANAGEMENT TECHNIQUES (1) results (3) semester 4 (5) semester 5 (1) Semester 6 (5) SERVICE ORIENTED ARCHITECTURE (1) Skill Test (1) software (1) Software Engineering (4) SOFTWARE TESTING (1) Structural Analysis (1) syllabus (34) SYSTEM SOFTWARE (1) system software lab (2) SYSTEMS MODELING AND SIMULATION (1) Tansat (2) Tansat 2011 (1) Tansat 2013 (1) TCP/IP DESIGN AND IMPLEMENTATION (1) TECHNICAL ENGLISH (7) Technology and National Security (1) Theory of Computation (3) Thought for the Day (1) Timetable (4) tips (4) Topic Notes (7) tot (1) TOTAL QUALITY MANAGEMENT (4) tutorial (8) Ubuntu LTS 12.04 (1) Unit Wise Notes (1) University Question Paper (1) UNIX INTERNALS (1) UNIX Lab (21) USER INTERFACE DESIGN (3) VIDEO TUTORIALS (1) Virtual Instrumentation Lab (1) Visual Programming (2) Web Technology (11) WIRELESS NETWORKS (1)

LinkWithin