Docsity

Transforms, Essays (high school) of Art

Toggle sidebar
bg1
CSC418 / CSCD18 / CSC2504 Transformations
3 Transformations
3.1 2D Transformations
Given a point cloud, polygon, or sampled parametric curve, we can use transformations for several
purposes:
1. Change coordinate frames (world, window, viewport, device, etc).
2. Compose objects of simple parts with local scale/position/orientation of one part defined
with regard to other parts. For example, for articulated objects.
3. Use deformation to create new shapes.
4. Useful for animation.
There are three basic classes of transformations:
1. Rigid body - Preserves distance and angles.
•Examples: translation and rotation.
2. Conformal - Preserves angles.
•Examples: translation, rotation, and uniform scaling.
3. Affine - Preserves parallelism. Lines remain lines.
•Examples: translation, rotation, scaling, shear, and reflection.
Examples of transformations:
•Translation by vector ~
t:¯p1= ¯p0+~
t.
•Rotation counterclockwise by θ:¯p1=cos(θ)−sin(θ)
sin(θ) cos(θ)¯p0.
Copyright c
2005 David Fleet and Aaron Hertzmann 10
pf3
pf4
pf5
pf8

Partial preview of the text

Download Transforms and more Essays (high school) Art in PDF only on Docsity!

3 Transformations

3.1 2D Transformations

Given a point cloud, polygon, or sampled parametric curve, we can use transformations for several purposes:

  1. Change coordinate frames (world, window, viewport, device, etc).
  2. Compose objects of simple parts with local scale/position/orientation of one part defined with regard to other parts. For example, for articulated objects.
  3. Use deformation to create new shapes.
  4. Useful for animation.

There are three basic classes of transformations:

  1. Rigid body - Preserves distance and angles.
    • Examples: translation and rotation.
  2. Conformal - Preserves angles.
    • Examples: translation, rotation, and uniform scaling.
  3. Affine - Preserves parallelism. Lines remain lines.
    • Examples: translation, rotation, scaling, shear, and reflection.

Examples of transformations:

  • Translation by vector ~t: p¯ 1 = ¯p 0 + ~t.
  • Rotation counterclockwise by θ: p¯ 1 =

[

cos(θ) − sin(θ) sin(θ) cos(θ)

]

p ¯ 0.

  • Uniform scaling by scalar a: p¯ 1 =

[

a 0 0 a

]

p ¯ 0.

  • Nonuniform scaling by a and b: p¯ 1 =

[

a 0 0 b

]

p ¯ 0.

  • Shear by scalar h: p¯ 1 =

[

1 h 0 1

]

p ¯ 0.

  • Reflection about the y-axis: p¯ 1 =

[

]

p ¯ 0.

3.2 Affine Transformations

An affine transformation takes a point p¯ to q¯ according to q¯ = F (¯p) = Ap¯ + ~t, a linear transfor- mation followed by a translation. You should understand the following proofs.

  • A composition of affine transformations is still affine.

Proof: Let F 1 (¯p) = A 1 p¯ + ~t 1 and F 2 (¯p) = A 2 p¯ + ~t 2. Then,

F (¯p) = F 2 (F 1 (¯p)) = A 2 (A 1 p¯ + ~t 1 ) + ~t 2 = A 2 A 1 p¯ + (A 2 ~t 1 + ~t 2 ).

Letting A = A 2 A 1 and ~t = A 2 ~t 1 + ~t 2 , we have F (¯p) = Ap¯ + ~t, and this is an affine transformation.

3.3 Homogeneous Coordinates

Homogeneous coordinates are another way to represent points to simplify the way in which we express affine transformations. Normally, bookkeeping would become tedious when affine trans- formations of the form Ap¯ + ~t are composed. With homogeneous coordinates, affine transforma- tions become matrices, and composition of transformations is as simple as matrix multiplication. In future sections of the course we exploit this in much more powerful ways.

With homogeneous coordinates, a point p¯ is augmented with a 1, to form pˆ =

[

p¯ 1

]

All points (αp, α¯ ) represent the same point p¯ for real α 6 = 0.

Given pˆ in homogeneous coordinates, to get p¯, we divide pˆ by its last component and discard the last component.

Example: The homogeneous points (2, 4 , 2) and (1, 2 , 1) both represent the Cartesian point (1, 2). It’s the orientation of pˆ that matters, not its length.

Many transformations become linear in homogeneous coordinates, including affine transforma- tions: [ qx qy

]

[

a b c d

] [

px py

]

[

tx ty

]

[

a b tx c d ty

]

px py 1

[

A ~t

]

pˆ

To produce qˆ rather than q¯, we can add a row to the matrix:

q ˆ =

[

A ~t ~ 0 T^1

]

p ˆ =

a b tx c d ty 0 0 1

p.ˆ

This is linear! Bookkeeping becomes simple under composition.

Example: F[ 3 (F 2 (F 1 (¯p))), where Fi(¯p) = Ai(¯p) + ~ti becomes M 3 M 2 M 1 p¯, where Mi = Ai ~ti ~ 0 T^1

]

With homogeneous coordinates, the following properties of affine transformations become appar- ent:

  • Affine transformations are associative. For affine transformations F 1 , F 2 , and F 3 ,

(F 3 ◦ F 2 ) ◦ F 1 = F 3 ◦ (F 2 ◦ F 1 ).

  • Affine transformations are not commutative. For affine transformations F 1 and F 2 ,

F 2 ◦ F 1 6 = F 1 ◦ F 2.

3.4 Uses and Abuses of Homogeneous Coordinates

Homogeneous coordinates provide a different representation for Cartesian coordinates, and cannot be treated in quite the same way. For example, consider the midpoint between two points p¯ 1 = (1, 1) and p¯ 2 = (5, 5). The midpoint is (¯p 1 + ¯p 2 )/2 = (3, 3). We can represent these points in homogeneous coordinates as pˆ 1 = (1, 1 , 1) and pˆ 2 = (5, 5 , 1). Directly applying the same computation as above gives the same resulting point: (3, 3 , 1). However, we can also represent these points as pˆ′ 1 = (2, 2 , 2) and pˆ′ 2 = (5, 5 , 1). We then have (ˆp′ 1 + ˆp′ 2 )/2 = (7/ 2 , 7 / 2 , 3 /2), which cooresponds to the Cartesian point (7/ 3 , 7 /3). This is a different point, and illustrates that we cannot blindly apply geometric operations to homogeneous coordinates. The simplest solution is to always convert homogeneous coordinates to Cartesian coordinates. That said, there are several important operations that can be performed correctly in terms of homogeneous coordinates, as follows.

3.6 Transformations in OpenGL

OpenGL manages two 4 × 4 transformation matrices: the modelview matrix , and the projection matrix. Whenever you specify geometry (using glVertex), the vertices are transformed by the current modelview matrix and then the current projection matrix. Hence, you don’t have to perform these transformations yourself. You can modify the entries of these matrices at any time. OpenGL provides several utilities for modifying these matrices. The modelview matrix is normally used to represent geometric transformations of objects; the projection matrix is normally used to store the camera transformation. For now, we’ll focus just on the modelview matrix, and discuss the camera transformation later.

To modify the current matrix, first specify which matrix is going to be manipulated: use glMatrixMode(GL MODE to modify the modelview matrix. The modelview matrix can then be initialized to the identity with glLoadIdentity(). The matrix can be manipulated by directly filling its values, multiplying it by an arbitrary matrix, or using the functions OpenGL provides to multiply the matrix by specific transformation matrices (glRotate, glTranslate, and glScale). Note that these transforma- tions right-multiply the current matrix; this can be confusing since it means that you specify transformations in the reverse of the obvious order. Exercise: why does OpenGL right-multiply the current matrix?

OpenGL provides a stacks to assist with hierarchical transformations. There is one stack for the modelview matrix and one for the projection matrix. OpenGL provides routines for pushing and popping matrices on the stack.

The following example draws an upper arm and forearm with shoulder and elbow joints. The current modelview matrix is pushed onto the stack and popped at the end of the rendering, so, for example, another arm could be rendered without the transformations from rendering this arm affecting its modelview matrix. Since each OpenGL transformation is applied by multiplying a matrix on the right-hand side of the modelview matrix, the transformations occur in reverse order. Here, the upper arm is translated so that its shoulder position is at the origin, then it is rotated, and finally it is translated so that the shoulder is in its appropriate world-space position. Similarly, the forearm is translated to rotate about its elbow position, then it is translated so that the elbow matches its position in upper arm coordinates.

glPushMatrix();

glTranslatef(worldShoulderX, worldShoulderY, 0.0f); drawShoulderJoint(); glRotatef(shoulderRotation, 0.0f, 0.0f, 1.0f); glTranslatef(-upperArmShoulderX, -upperArmShoulderY, 0.0f); drawUpperArmShape();

glTranslatef(upperArmElbowX, upperArmElbowY, 0.0f);

drawElbowJoint(); glRotatef(elbowRotation, 0.0f, 0.0f, 1.0f); glTranslatef(-forearmElbowX, -forearmElbowY, 0.0f); drawForearmShape();

glPopMatrix();