0% found this document useful (0 votes)
58 views7 pages

2-D Transformations Why Do We Need Transformations?: - Glusphere Draws A Sphere of Radius

c'est un cours sur la statistique qui aide à transformer les variables. C'est un bon outil pour les statisticiens.

Uploaded by

Demba Diakhate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views7 pages

2-D Transformations Why Do We Need Transformations?: - Glusphere Draws A Sphere of Radius

c'est un cours sur la statistique qui aide à transformer les variables. C'est un bon outil pour les statisticiens.

Uploaded by

Demba Diakhate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

2-D Transformations Why Do We Need Transformations?

Transformations are functions applied to points in space Makes modeling more convenient
p ' = f ( p) • for example, often easier to generate models around origin
– gluSphere() draws a sphere of radius r about the origin
• can then move them to final position with transformations
Provide a mechanism for manipulating geometric models

Model viewing process via transformations


• projecting 3-D to 2-D will be done this way

Transformations are essential pieces of graphics systems


• OpenGL and PostScript, for instance, use them extensively
Animation
• transformations as a function of time creates motion

Linear Algebra in 30 Seconds Linear & Affine Transformations

We represent points as vectors p = [x y z] p+q We’ll be specifically interested in linear transformations


p
• vectors add according to parallelogram rule
f (α p + β q ) = α f ( p) + β f (q )
• a linear combination of two vectors is
αp + βq • transformation of shape determined by effect on vertices
q • a crucial property that allows for efficient implementation
• set of vectors is linearly independent if none is a linear
combination of the others
• a basis for a space is a linearly independent set of vectors And the related class of affine transformations
whose linear combinations include all vectors in the space f ( p + α (q − p)) = f ( p) + α [ f (q ) − f ( p)]
1  0 • preserves affine combinations (e.g., they map lines to lines)
standard basis for 2-D plane: e1 =   e 2 =  
0 1  • another view: a linear transformation + a translation
• but there are infinitely many possible bases • this is a more general class of functions
Translation Scaling

Offset all points by constant amount Scale all points by constant amount
x ' = x + ∆x x ' = sx
y' = y + ∆y y ' = ty

Written as more concise vector equation And written as a vector equation

 x '  x   ∆ x  x '  s 0   x 
 = +   y ' =  0 t   y 
 y '  y   ∆ y     
or or
p' = p + d p ' = Sp

Squash/stretch along x & y axes

Rotation of Points About Origin The Three Fundamental Transformations

First, write points in polar coordinates  x '


x = ρ cosφ y = ρ sin φ  y '
  Translation: p' = p + d
x ' = ρ cos(φ + θ ) y ' = ρ sin(φ + θ )
Scaling: p ' = Sp
x
y Rotation: p ' = Rp
And solve for the new positions θ  
x ' = x cosθ − y sinθ φ
y ' = x sinθ + y cosθ
We can represent any affine transformation as a sequence of these 3
Can write this as a vector equation as well Translation is only one not represented as matrix multiplication
 x ' cosθ − sinθ   x  • because it’s not a linear transformation
 y ' =  sinθ cosθ   y  • wouldn’t it be nice if we could come up with a matrix formulation!
    
or
p ' = Rp
Homogeneous Coordinates Transforms in Homogeneous Coordinates

Let’s add an extra dimension to our vectors Scaling


x a 
x a     x '  s 0 0   x 
position:   →  y  direction: →
b  b   y ' = 0 t 0   y 
 y   1    0      Rotation
     1  0 0 1   1 
 x ' cosθ − sinθ 0  x 
• this added dimension is the homogeneous coordinate or  y ' =  sinθ cosθ 0  y 
• in general, we’ll have coordinates [x y w]     
p ' = Sp  1   0 0 1   1 
• the resulting 3-D space is a projective space Translation
or
To convert back, divide by w and drop the last coordinate  x ' 1 0 ∆ x  x 
p ' = Rp  y ' =  0 1 ∆ y  y 
• all vectors [αx αy αw] represent the same point     
• if w=0, it represents a “point at infinity”  1   0 0 1   1 

So what does this do to our transformation equations? or


p ' = Tp

Fundamental Homogeneous Transforms Composing Transformations

Matrix multiplication is associative (but not commutative)


• can collapse sequences of transformations into single matrix
Translation: p ' = Tp
• but must not reorder any of them
Scaling: p ' = Sp
A (B(C(D( v )))) = ABCDv
Rotation: p ' = Rp
= ( ABCD) v
Can choose to multiply pairs at either end
• add new matrices at beginning — pre-multiply
Now we can write all three transforms as matrix multiplications
ABCD = A (B(CD))
• add new matrices at the end — post-multiply
In general, we’ll be using some sequence of transformations ABCD = ((( AB)C )D)
M1 (M 2 (L Mn ( v )L))
Exercise: Composing Transformations Exercise: Composing Transformations

original R = rotate(60°) S = scale(1.3, 0.5) T = trans(0.2, 0.2)


(a) TRSv (b) RSTv

What order of R, S, T
will produce this figure?
(a) TRSv
(b) RSTv
(c) TSRv
(d) RTSv
(c) TSRv (d) RTSv

3-D Transforms Scaling & Translation in 3-D

We developed 2-D transformations Looks pretty much the same as in 2-D Scaling
• just add on the z dimension to everything
r 0 0 0
0 s 0 0
But we’re mainly interested in 3-D graphics S= 
0 0 t 0
 
0 0 0 1
So we’ll extend these tools to 3-D
Translation
1 0 0 ∆ x
0 1 0 ∆ y
T= 
0 0 1 ∆z 
Unfortunately, rotation is not so simple …  
0 0 0 1
Rotation About Coordinate Axes Some Mathematical Definitions

Looks pretty similar to 2-D case 1 0 0 0 The dual matrix of a vector u


0 cosθ − sinθ 0
Specify rotation as 3 angles Rx =    0 −z y 
• one per coordinate axis 0 sinθ cosθ 0 u = z
*
0 −x 
   
• these are called Euler angles 0 0 0 1
• fairly widely used  − y x 0 
 cosθ 0 sinθ 0 • can write vector cross product u×v as matrix multiply u∗v
Drawback 1: Result is order dependent  0
• suppose we rotate about x then y 1 0 0
Ry =  
• y rotation is about transformed axis after  − sinθ 0 cosθ 0
x rotation is performed   The outer product of a vector u (with itself)
• this gets confusing  0 0 0 1

cosθ − sinθ 0 0 x  x 2 xy xz 


Drawback 2: Difficult to interpolate  
• for animation want to interpolate angles  sinθ cosθ 0 0 uu =  y  [ x
T
y z ] =  xy y 2 yz 
Rz =    
• resulting motion can be weird  0 0 1 0  z   xz yz z 2 
 
 
 0 0 0 1

Rotation About Arbitrary Axis Writing Transformations in OpenGL

Let’s suppose we have a unit direction vector OpenGL maintains a current transformation matrix M
x • issue commands to post-multiply matrices into M
u =  y  where x 2 + y 2 + z 2 = 1
• so, commands are listed in reverse order of application
  • glLoadIdentity() — set M to identity matrix (M ← I)
 z 
• glTranslatef(∆x, ∆y, ∆z) — translation (M ← MT)
• glRotatef(θ, x, y, z) — rotate about given axis (M ← MR)
We can derive a rotation by a given angle about this axis • glScalef(r, s, t) — scale by given factors (M ← MS)

R (θ , u) = uu T + cosθ (I − uu T ) + (sinθ )u* Example: to rotate about an arbitrary point p = [x y z]

This is the approach used by OpenGL — glRotatef(θ, x, y, z) glTranslatef(x, y, z, 0); // (3) move p back
glRotatef(theta, 0, 0, 1); // (2) rotate around z axis
Has many of the same interpolation problems as Euler angles glTranslatef(-x, -y, -z, 0);// (1) move p to origin
DrawSomething();
A Word of Caution on Notation Transformation of Normal Vectors

We’ve consistently written points as column vectors Affine transformations map parallel lines to parallel lines
• virtually everyone does this  x ' a b   x  • but the same does not hold for perpendicular lines
• typically represent matrices in row-major order  y ' =  c d   y 
[[a b] [c d]]     

Some in graphics have traditionally used row vectors Transform M will not map normal vectors to normal vectors
• convert by transposing everything: a c  • first guess would be to map normals as n → Mn
ABv → (ABv)T=vT BT AT [ x ' y '] = [ x y]   • after transform, may or may not be perpendicular to surface
b d 
• note that order is reversed as well Normal vectors are defined by surface tangent planes
• typically represent matrices in column-major order • so let’s consider how planes are transformed
[[a c] [b d]]
• OpenGL actually does it this way
• but you’ll probably never notice

Transformation of Normal Vectors Transformation of Normal Vectors

A plane in 3-D space is described by the homogeneous vector Must in general compute actual local plane
n = (a, b, c , d ) where ax + by + cz + d = 0 is the plane equation n = (a, b, c , d ) where ax + by + cz + d = 0 is the plane equation
• thus any point v on the plane satisfies the equation • however, there are some simpler cases
nT v = 0
Simplified case #1: Affine Transformations
For any 4x4 matrix whose inverse exists, this is equivalent to • map parallel planes to parallel planes
n T M −1Mv = 0 • thus, can pick any value of d — might as well be 0
• thus the transformed point Mv lies on the plane nTM-1 Simplified case #2: Orthogonal (Rigid-Body) Transformations
• it’s plane vector is (nTM-1)T or (M-1)Tn • in this case (e.g., rotation) M −1 = MT
• thus the normal transformation rule becomes n → Mn
This gives us the transformation rule for normal vectors

n → ( M −1 )T n
An Alternative View of Transformations

Can be thought of as mapping points to new locations


• this is the basis of the presentation from last time
Can also be thought of as a change of coordinate system
• vectors are specified as a linear combination of basis vectors
• for instance, in 2-D:
p = p1e1 + p2 e 2
• transformed vector is similar combination of transformed basis
p ' = p1e '1 + p2 e '2 e′2
e2
e′1
This is frequently a useful approach
to understanding transformations

e1

You might also like