Professional Documents
Culture Documents
2D and 3D
Before translation x
After translation x
P' = P + T
After substitution: x' = x cos y sin y ' = x sin + y cos Matrix form: x' cos sin x , = y' sin cos y P' = R P
Rotation equation about origin: x' = r cos( + ) = r cos cos r sin sin y ' = r sin( + ) = r cos sin + r sin cos
Before rotation
After rotation
Rotation about an arbitrary pivot point: After substitution: x' = xr + ( x xr ) cos ( y yr ) sin y ' = yr + ( x xr ) sin + ( y yr ) cos
Rigid-body transformation A line is rotated by applying the rotation equation to each of the line endpoints and redrawing the line between the tow endpoints. Polygons are rotated by moving each vertex through the specified rotation angle and then redraw. Curves are rotated by repositioning the defining points and redrawing the curve.
Differential scaling:
Unequal values of sx and sy.
Scaling values < 1 moves the object closer to the origin. Scaling values > 1 moves the object further away from the origin. Fixed point:
To control the location after scaling. Coordinates for the fixed point (xf, yf) can be any vertices, centroids or any other position. xf(1-sx) and yf(1-sy) are constants for all x' = points in the object.
x s x + x f (1 s x )
Before scaling
After scaling
P' = S P
y ' = y s y + y f (1 s y )
Homogeneous Coordinates
Problem:
Homogeneous Coordinates
A 2D coordinate P1(x1,y1) lying in 3D can be represented as P(x,y,z) = P(hx1,hy1,h). Given P(m,n,h) in homogeneous coordinates the cartesian coordinates can be found by P(m/h,n/h,1). Each point can have many different homogeneous coordinate representations.
Solved by:
Using homogeneous coordinates instead of cartesian coordinates. Then translation, scaling and rotation can be expressed in a general matrix form (multiplication).
P' = T(tx,ty) P
P' = R() P
The inverse translation matrix is obtained by replacing tx and ty with -tx and -ty.
1 0 t x2 1 0 t x1 1 0 t x1 + t x2 Translating from P to P' to P'':0 1 t y 0 1 t y = 0 1 t y + t y 2 1 1 2 1 0 0 1 0 0 1 0 0
Composition of 2D Transformations
P' = S(sx,sy) P
The inverse scaling matrix is obtained by replacing sx and sy with 1/sx and 1/sy. Scaling from P to P' to P'':
s x2 0 0 0 s y2 0 0 s x1 0 0 1 0 0 s y1 0 0 s x1 s x2 0 = 0 1 0 0 s x1 s x2 0 0 0 1
OpenGL provides a rotation function only about the origin. To rotate an object about an arbitrary point (pivot point) we need to do a sequence of three fundamental transformations. 1. Translate the pivot point to origin. 2. Rotate about the origin. 3. Translate the pivot point back to the original position.
T(x1, y1) R() T(-x1, -y1) =
Composition of 2D Transformation
Affine Transformation
Shear Transformation
Preserves parallelism of lines, but not lengths and angles. Rotation, translation and reflection preserves angles and lengths as well. Shear and scaling preserves only parallelism. These properties also applies to 3D.
Distorts the shape of an object such that the transformed shape appears as if the object were composed of internal layer that had been caused to slide over each other.
1 shx 0 0 1 0, SH x = 0 0 1
1 0 0 SH y = shy 1 0 0 0 1
Reflection Transformation
3D Transformations 3D Translation
x' 1 y' 0 A 4 by 4 homogenized matrix = z ' 0 1 0 0 0 tx x 1 0 t y y P' = T P , 0 1 tz z 0 0 1 1
x-axis (y = 0) 1 0 0 0 1 0 0 0 1 y-axis (x = 0) 1 0 0 0 1 0 0 0 1
Original
x
Reflected
xy-plane 1 0 0 0 1 0 0 0 1 xy-plane
0 1 0 1 0 0 0 0 1
y
The inverse translation matrix is obtained by replacing tx, ty and tz with -tx,-ty and -tz.
3D Transformation 3D Translation
3D Transformations 3D Scaling
x' s x y ' 0 A 4 by 4 homogenized matrix = z' 0 1 0 0 sy 0 0 0 0 sz 0 0 x 0 y P' = S P , 0 z 1 1
Each of the defining points are translated. If the object is a polygon, each vertex of the polygon is translated.
(x',y',z') (x,y,z)
The inverse scaling matrix is obtained by replacing sx, sy and sz with 1/sx,1/sy and 1/sz.
3D Transformation 3D Scaling
Scaling with respect to a fixed position sx 0 T( x f , y f , z f ) S( s x , s y , s z ) T( x f , y f , z f ) = 0 0 0 sy 0 0 0 0 sz 0
3D Transformation 3D Rotation
(1 s x )x f
Rotation about z-axis
(1 sy )y f
(1 s z )z f
1
0 0 1 0
0 0 0 1
0 0 0 1
P' = Rz() P
y y y y
P' = Rx() P
y y
(xf,yf,zf)
(xf,yf,zf)
(xf,yf,zf) z x z
(xf,yf,zf) x
cos 0 sin 0
0 sin 0 1 0 0 0 cos 0 0 0 1
P' = Ry() P
Geometric Transformation
A transformation matrix of the form: (translation and rotation) r11 r12 r13 t x r11 r12 t x r r r r t or 21 22 r23 t y is called special orthogonal. 21 22 y r31 r32 r33 t z 0 0 1 0 0 0 1 It preserves angles and length. The inverse is the transpose. Each row vector in the matrix has 3 properties: 1. Each is a unit vector 2. Each is perpendicular to the other 3. The first and second vector will be rotated by R() to lie on the positive x and y axes, respectively. Initial position
Composition of 3D Transformation
y
P3 P2 P1
y
P3 P1 P2
Final position
x z
Two ways to achieve the transformation: 1. Compose the transformation T, Rx, Ry, Rz. 2. Using the properties of the orthogonal matrix.
Composition of 3D Transformation
Done the same way as 2D composition. 1. Translate P1 to the origin 2. Rotate about the y-axis (P1,P2 lies in the (y,z) plane) 3. Rotate about the x-axis (P1,P2 lies on the z-axis) 4. Rotate about the z-axis (P1,P3 lies in the (y,z) plane) The composite matrix will be
Composition of 3D Transformation
Create the rotation matrix by using cross product. PP T Rz will rotate into z-axis. R = [r r r ] = 1 2
z 1z 2z 3z T
Rx = [r1x r2 x r 3 x ]
P1P2 PP PP = 13 1 2 P1P3 P P2 1 Rz Rx Rz Rx
R y = [r1 y r2 y r3 y ] =
T
Rz ( ) Rx ( ) R y ( 90 ) T ( x1 , y1 , z1 )
0 0 T ( x1 , y1 , z1 ) = R T 0 1
Coordinate Systems
Right handed:
y
Left handed:
y z
x z