Coordinate Systems and Transformations
Graphic Libraries
Hardware dependent program
Hardware independent program
GL Examples: Core, GKS, PEX, OpenGL
Coordinate Systems • Device Coordinate System: identifies locations on the display
=>Virtual Device Coordinate System: Usually the origin is at the low left corner and u,v range from 0 to 1.
Coordinate Systems • Model Coordinate System(MCS): identifies the shapes of object and it is attached to the object. Therefore the MCS moves with the object in the WCS
• World Coordinate System (WCS): identifies locations of objects in the world in the application.
• Viewing Coordinate System (VCS): Defined by the viewpoint and viewsite
Coordinate Systems viewpoint and viewsite
Coordinate Systems
Projection on Screen • Parallel Projection • Perspective Projection
Parallel Projection • Preserve actual dimensions and shapes of objects • Preserve parallelism • Angles preserved only on faces parallel to the projection plane • Orthographic projection is one type of parallel projection
Perspective Projection • Doesn’t preserve parallelism • Doesn’t preserve actual dimensions and angles of objects, therefore shapes deformed • Popular in art (classic painting); architectural design and civil engineering. • Not commonly used in mechanical engineering
Perspective Projection
Coordinate scaling:
Transformations between Coordinate Systems Model Transformation
Viewing Transformation
ProjectionTransformation
Translation 2D
3D
y
y
P2 (x2, y2)
d
yd
P2
P1(x1, y1)
o
xd ⎡ x1 ⎤ ⎢ ⎥ P1 = ⎢ y1 ⎥ ⎢⎣ z1 ⎥⎦
x
P1
z
⎡ x1 ⎤ ⎡ x d ⎤ ⎡ x1 + xd ⎤ P 2 = ⎢⎢ y1 ⎥⎥ + ⎢⎢ y d ⎥⎥ = ⎢⎢ y1 + yd ⎥⎥ = P1 + d ⎢⎣ z1 ⎥⎦ ⎢⎣ z d ⎥⎦ ⎢⎣ z1 + zd ⎥⎦
x
Scaling
2D
y
3D
y
P2
P2 (x 2, y2)y’) V’(x’,
P1
y) P1(xV(x, 1, y1) θ
x
x
o z
⎡x1 ⎤ ⎢ ⎥ P1 = ⎢y1 ⎥ ⎢⎣z1 ⎥⎦
⎡sx1 ⎤ ⎢ ⎥ P 2 = ⎢sy1 ⎥ ⎢⎣sz1 ⎥⎦
P 2 = sP1
y P2
Reflection (about XOY Plane) o
x P1
z
⎡ x1 ⎤ ⎢ ⎥ P1 = ⎢ y1 ⎥ ⎢⎣ z1 ⎥⎦
⎡ x1 ⎤ ⎢ ⎥ P 2 = ⎢ y1 ⎥ ⎢⎣ −z1 ⎥⎦
⎡1 0 0 ⎤ P 2 = ⎢⎢ 0 1 0 ⎥⎥ P1 ⎢⎣ 0 0 −1⎥⎦
Rotation about Z Axis - CCW by Ө ⎡ x1 ⎤ ⎡ r cos ϕ ⎤ P1 = ⎢⎢ y1 ⎥⎥ = ⎢⎢ r sin ϕ ⎥⎥ ⎢⎣ z1 ⎥⎦ ⎢⎣ z ⎥⎦ ⎡ x2 ⎤ ⎡ r cos (ϕ +θ ) ⎤ ⎢ ⎥ P2 = ⎢⎢ y2 ⎥⎥ = ⎢ r sin (ϕ +θ ) ⎥ ⎥⎦ ⎢⎣ z2 ⎥⎦ ⎢⎣ z ⎡ r cos ϕ cos θ − r sin ϕ sin θ ⎤ = ⎢⎢ r cos ϕ sin θ + r sin ϕ cos θ ⎥⎥ ⎢⎣ ⎥⎦ z ⎡ x1 cos θ − y1 sin θ ⎤ = ⎢⎢ x1 sin θ + y1 cos θ ⎥⎥ ⎢⎣ ⎥⎦ z1
φ
z CCW y2
y
y1 P2 θ
z
Φ
o
r
P1
x2 x1
x
P2 (x2, y2)
y θ
o
φ
P1(x1, y1)
x
3-D Transformation
Rotation about Z Axis - CCW by Ө x2 = x1 cos θ − y1 sin θ y2 = x1 sin θ + y1 cos θ z2 = z1 P2 (x2, y2, z2)
y
P1(x1, y1, z2)
θ
φ
o
x Counter Clockwise, CCW
⎡ x2 ⎤ ⎡cos θ − sin θ 0 ⎤ ⎡ x1 ⎤ ⎢ y ⎥ = ⎢sin θ ⎥⎢y ⎥ cos θ 0 ⎢ 2⎥ ⎢ ⎥ ⎢ 1⎥ ⎢⎣ z2 ⎥⎦ ⎢⎣ 0 0 1 ⎥⎦ ⎢⎣ z1 ⎥⎦
Rotation about X Axis CCW by Ө
z
x2 = x
y
y2 = y1 cos θ − z1 sin θ
o
x
z2 = y1 sin θ + z1 cos θ P2 (x2, y2, z2)
z
P1(x1, y1, z1) θ φ
o
y
0 0 ⎤ ⎡ x1 ⎤ ⎡ x2 ⎤ ⎡1 ⎢ y ⎥ = ⎢0 cos θ − sin θ ⎥ ⎢ y ⎥ ⎢ 2⎥ ⎢ ⎥ ⎢ 1⎥ ⎢⎣ z2 ⎥⎦ ⎢⎣0 sin θ cos θ ⎥⎦ ⎢⎣ z1 ⎥⎦
Rotation about Y Axis CCW by Ө
⎡ x1 ⎤ ⎡ r cos ϕ ⎤ P1 = ⎢⎢ y1 ⎥⎥ = ⎢⎢ y1 ⎥⎥ ⎢⎣ z1 ⎥⎦ ⎢⎣ r sin ϕ ⎥⎦ ⎡ x2 ⎤ ⎡ r cos (ϕ − θ ) ⎤ ⎡ r cos ϕ cos θ + r sin ϕ sin θ ⎤ ⎢ ⎥ ⎢ ⎥ = P2 = ⎢⎢ y2 ⎥⎥ = ⎢ y1 y 1 ⎥ ⎢ ⎥ ⎢⎣ z2 ⎥⎦ ⎢⎣ r sin (ϕ − θ ) ⎥⎦ ⎢⎣ r sin ϕ cos θ − r cos ϕ sin θ ⎥⎦ ⎡ x1 cos θ + z1 sin θ ⎤ ⎥ = ⎢⎢ y1 ⎥ ⎢⎣ − x1 sin θ + z1 cos θ ⎦⎥ ⎡ x2 ⎤ ⎡ cos θ 0 sin θ ⎤ ⎡ x1 ⎤ P2 = ⎢⎢ y2 ⎥⎥ = ⎢⎢ 0 1 0 ⎥⎥ ⎢⎢ y1 ⎥⎥ = R[ y ] P1 ⎢⎣ z2 ⎥⎦ ⎢⎣ − sin θ 0 cos θ ⎥⎦ ⎢⎣ z1 ⎥⎦
Z P1 P2
θ φ
X
Y
Homogeneous Representation The representation is introduced to express all geometric transformations in the from of matrix multiplication for the convenience of manipulation.
⎡ x2 ⎤ ⎡1 0 ⎢ y ⎥ ⎢0 1 Translation ⎢ 2 ⎥ = ⎢ ⎢ z2 ⎥ ⎢0 0 ⎢ ⎥ ⎢ ⎣1 ⎦ ⎢⎣ 0 0
0 d x ⎤ ⎡ x1 ⎤ 0 d y ⎥⎥ ⎢ y1 ⎥ ⎢ ⎥ 1 d z ⎥ ⎢ z1 ⎥ ⎥⎢ ⎥ 0 1 ⎥⎦ ⎣1 ⎦
Dummy (n+1)th coordinate to facilitate multiplication
Homogeneous Representations Scaling
Rotation
P2 = [Rz ]P1
⎡sx ⎢0 [H ] = ⎢ ⎢0 ⎢ ⎣0
and
0 0 0⎤ s y 0 0⎥ ⎥ 0 sz 0 ⎥ ⎥ 0 0 1⎦
⎡cos θ ⎢ sin θ [Rz ] = ⎢ ⎢ 0 ⎢ ⎣ 0
− sin θ cos θ 0 0
0 0⎤ 0 0 ⎥⎥ 1 0⎥ ⎥ 0 1⎦
Homogeneous Representations 0 ⎡1 ⎢ 0 cos θ [ Rx ] = ⎢⎢ 0 sin θ ⎢ 0 ⎣0
0 − sin θ cos θ 0
Reflection
P2 = [M ]P1
and
0⎤ 0 ⎥⎥ ; 0⎥ ⎥ 1⎦
⎡ cos θ ⎢ 0 ⎡⎣ R y ⎤⎦ = ⎢ ⎢ − sin θ ⎢ ⎣ 0
⎡± 1 0 0 ⎢ 0 ±1 0 [M ] = ⎢ ⎢ 0 0 ±1 ⎢ ⎣0 0 0
0 sin θ 1 0 0 cos θ 0 0
0⎤ 0⎥⎥ 0⎥ ⎥ 1⎦
0⎤ 0 ⎥⎥ 0⎥ ⎥ 1⎦
Composition of Transformation (Concatenation of Transformation) via Pre-Multiplication
P2 = [ H n ][ H n −1 ]"[ H1 ]P1
An Example Consider a 3D object. The coordinates of the vertices are given as follows: A=[3, 5, 3]
B=[7, 5, 3]
C=[7, 5, 5]
D=[3, 5, 5]
E=[3, 6, 5]
F=[3, 6, 3]
Rotate the 3D object by 30 degree in clockwise (CW) direction at point D about the Y-axis.
Step 1
[T]D-O o
Step 2
[R]y-30
Step 3
[T]O-D
Procedure:
• First we translate ([T]D-O) the object at the refernece point D to the origin O. • Then we rotate ([ R]Y−30) about the Y-axis • Finally, we translate ([T]O-D) the point D from the origin back to its original position.
[T ] D − O
⎡1 0 0 − 3 ⎤ ⎢0 1 0 − 5⎥ ⎥ = ⎢ ⎢0 0 1 − 5⎥ ⎢ ⎥ 0 0 0 1 ⎣ ⎦
[T ]O
[ R]Y−30
− D
⎡cos(−30) 0 sin ( −30 ) 0 ⎤ ⎢ ⎥ 0 1 0 0 ⎥ =⎢ ⎢ − sin(−30) 0 cos(−30) 0 ⎥ ⎢ ⎥ 0 0 1 ⎥⎦ ⎢⎣ 0
⎡1 ⎢0 = ⎢ ⎢0 ⎢ ⎣0
0 0 3⎤ 1 0 5 ⎥⎥ 0 1 5⎥ ⎥ 0 0 1⎦
[A B C D E F]
⎡3 7 7 3 3 3 ⎤ ⎢5 5 5 5 6 6 ⎥ ⎥ P1 = ⎢ ⎢3 3 5 5 5 3 ⎥ ⎢ ⎥ ⎣1 1 1 1 1 1 ⎦
The definition of the point matrix in the homogeneous representation.
−30 Z
P2 = [T ]O − D [ R] [T ]D −O P1 ⎡ 4.00 7.46 6.46 3.00 3.00 4.00 ⎤ ⎢5.00 5.00 5.00 5.00 6.00 6.00 ⎥ ⎥ P2 = ⎢ ⎢3.27 5.27 7.00 5.00 5.00 3.27 ⎥ ⎢ ⎥ ⎣1.00 1.00 1.00 1.00 1.00 1.00 ⎦
Mapping and Parallel Projections • Mapping involves calculating the coordinates of a point known with rispect to a CS to a new CS.
About Transformations • Transformations are applied for both changing WCS in respect to MCS, but also for projections
Mapping and Parallel Projections
Where: Px,py,pz=x2,y2,z2 components required to translate (X2,Y2,Z2) to (X1,Y1,Z1), the following are evaluated as the translation as been performed: nx,ny,nz=x2,y2,z2 components of a unit vector along x1 ox,oy,oz=x2,y2,z2 components of a unit vector along y1 ax,ay,az=x2,y2,z2 components of a unit vector along y1 Once mapping has been performed the Z coordinate is dropped
Mapping and Perspective Projections Once mapping has been performed the zv coordinate are not dropped yet and the xv, yv coordinates are scaled following the similarity rule of triangles (L,S needed). Then zv is dropped.
Generating Parallel Projection Drop the n (zv) coordinate
⎡1 ⎢0 [Dn ]= ⎢⎢0 ⎢0 ⎣
0 0 0⎤ 1 0 0⎥ ⎥, 0 0 0⎥ 0 0 1 ⎥⎦
⎛ u⎞ ⎛u⎞ ⎜ V⎟ ⎜ V⎟ ⎜ ⎟ = [Dn ]⎜ ⎟ ⎜ 0⎟ ⎜n⎟ ⎜ ⎟ ⎜ ⎟ ⎝ 1⎠ ⎝1⎠
In summary, to project a view of an object on the UV plane, one needs to transform each point on the object by:
[T ] = [ Dn ][ Rz ][ Ry ][ Rx ][ Dov ,o ] ⎛ u⎞ ⎜ V⎟ P ′ = ⎜ ⎟ = [T ]P = [T] ⎜ 0⎟ ⎜ ⎟ ⎝ 1⎠
⎛ x⎞ ⎜ y⎟ ⎜ ⎟ ⎜ z⎟ ⎜ ⎟ ⎝ 1⎠
Note: The inverse transforms are not needed! We don't want to go back to x - y - z coordinates.
Orthographic Projection Y Top Front
Right X
Z
• Projection planes (Viewing planes) are perpendicular to the principal axes of the MCS of the model • The projection direction (viewing direction) coincides with one of the MCS axes
Y Top Front
Right X
Geometric Transformations for Generating Orthographic Projection (Front View)
⎡1 0 0 0 ⎤ ⎢0 1 0 0 ⎥ ⎥P Pv = ⎢ ⎢0 0 0 0 ⎥ ⎢ ⎥ ⎣0 0 0 1 ⎦
Z
Yv,Y Front
Xv, X
Drop Z
Geometric Transformations for Generating Orthographic Projection (Top View)
Y Top Front
Yv Right
Top
X
Xv, X Z
Z
0 0 ⎡1 0 0 0 ⎤ ⎡1 ⎢ 0 1 0 0 ⎥ ⎢ 0 cos(90 ° ) − sin(90 ° ) ⎥⎢ Pv = ⎢ ⎢ 0 0 0 0 ⎥ ⎢ 0 sin ( 90 ° ) cos(90 ° ) ⎢ ⎥⎢ 0 0 ⎣ 0 0 0 1 ⎦ ⎢⎣ 0 Drop Z
[ R]90 x
0⎤ ⎡1 ⎢0 0 ⎥⎥ P=⎢ ⎢0 0⎥ ⎥ ⎢ 1 ⎥⎦ ⎣0
0 0 0 0
0 0⎤ − 1 0 ⎥⎥ P 0 0⎥ ⎥ 0 1⎦
Y Top Front
Yv, Y
Geometric Transformations for Generating Orthographic Projection (Right View)
Right Right
X Z
Xv
sin( −90°)
− 1 0⎤ 0 0 ⎥⎥ P 0 0⎥ ⎥ 0 1⎦
Z
⎡1 0 0 0 ⎤ ⎡ cos( −90°) ⎢0 1 0 0 ⎥ ⎢ 0 ⎢ ⎢ ⎥ Pv = ⎢ 0 0 0 0 ⎥ ⎢ − sin ( −90° ) ⎢ ⎥⎢ 0 ⎣ 0 0 0 1 ⎦ ⎢⎣ Drop Z
0 1 0 0
0⎤ ⎡0 0 ⎢0 1 0 0 ⎥⎥ P=⎢ ⎢0 0 cos( −90°) 0 ⎥ ⎥ ⎢ 0 1 ⎥⎦ ⎣0 0
[ R ]−y90
Rotations Needed for Generating Isometric Projection Y
Yv Top Front
Y Right
Top Front
X
Right
Xv
Z Z
0 ⎡1 0 ⎢0 cos φ − sin φ Pv = [ R]φx [ R]θy P = ⎢ ⎢0 sin φ cos φ ⎢ 0 ⎣0 0
Zv
0 ⎤ ⎡cos θ ⎥ ⎢ 0⎥ ⎢ 0 0 ⎥ ⎢ − sin θ ⎥⎢ 1⎦⎣ 0
X
0 sin θ 0 ⎤ ⎥ 1 0 0 ⎥ P 0 cos θ 0 ⎥ ⎥ 0 0 1 ⎦
Isometric Projection: Equally foreshorten the three main axes
θ = ±45°, φ = ±35.26°
Other Possible Rotation Paths • Rx --> Ry
rx = ±45°, ry = ±35.26° • Rz --> Ry(Rx)
rz = ±45°, ry ( x ) = ±54.74° • Rx(Ry) --> Rz
ry ( x ) = ±45°, rz = ANY ANGLE