Professional Documents
Culture Documents
Chapter2 CAD CAM TRANSFORMATION
Chapter2 CAD CAM TRANSFORMATION
with OpenGL 3e
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Basic two-dimensional geometric
transformations (1/1)
• Two-Dimensional translation
– One of rigid-body transformation, which move objects without
deformation
– Translate an object by Adding offsets to coordinates to generate
new coordinates positions
– Set tx,ty be the translation distance, we have
x' x t x y' y t y
P' P T
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Basic two-dimensional geometric
transformations (1/2)
– We could translate an object by applying the equation to
every point of an object.
• Because each line in an object is made up of an
infinite set of points, however, this process would
take an infinitely long time.
• Fortunately we can translate all the points on a line
by translating only the line’s endpoints and drawing
a new line between the endpoints.
• This figure translates the “house” by (3, -4)
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Translation Example
4
(2, 3)
3
1
(1, 1) (3, 1)
0 1 2 3 4 5 6 7 8 9 10 x
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Basic two-dimensional geometric
transformations (2/1)
• Two-Dimensional rotation
– Rotation axis and angle are specified for rotation r
– Convert coordinates into polar form for calculation
r
x r cos y y sin
– Example, to rotation an object with angle a
• The new position coordinates
x' r cos( ) r cos cos r sin sin x cos y sin
y ' r sin( ) r cos sin r sin sin x sin y cos
• In matrix format
cos sin
R P' R P
sin cos
• Rotation about a point (xr, yr)
x' xr ( x xr ) cos ( y yr ) sin
y ' yr ( x xr ) sin ( y yr ) cos
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Basic two-dimensional geometric
transformations (2/2)
2
1 6
0
1 2 3 4 5 6 7 8 9 10
x
• Positive angles are measured counterclockwise
(from x towards y)
• For negative angles, you can use the identities:
– cos(-) = cos() and sin(-)=-sin()
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Rotation Example
4
(4, 3)
3
1
(3, 1) (5, 1)
0 1 2 3 4 5 6 7 8 9 10
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Basic two-dimensional geometric
transformations (3/1)
• Two-Dimensional scaling
– To alter the size of an object by multiplying the coordinates
with scaling factor sx and sy
x' x s x y y sy
– In matrix format, where S is a 2by2 scaling matrix
x ' s x 0 x
0 P' S P
y ' s y y
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Basic two-dimensional geometric
transformations (3/2)
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Scaling
3 6 9
3 3
2
1 2 3
1 1
0
1 2 3 4 5 6 7 8 9 10
x
Note: House shifts position relative to origin
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Scaling Example
4
(2, 3)
3
1
(1, 1) (3, 1)
0
Computer Graphics with OpenGL,1Third Edition,
2 by Donald3 Hearn and
4 M.Pauline5Baler. 6 7 8 9 10
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Homogeneous Coordinates
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Why Homogeneous Coordinates?
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Homogenous Coordinates
x 1 0 tx x x sx 0 0 x
y 0 1 ty y y 0 sy 0 y
1 0 0 1 1 1 0 0 1 1
Translate Scale
x cos sin 0 x x 1 shx 0 x
y sin cos 0 y y shy 1 0 y
1 0 0 1 1 1 0 0 1 1
Rotate Shear
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Geometric transformations in three-
dimensional space (1)
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Geometric transformations in three-
dimensional space (2)
• Three-dimensional translation
– A point P (x,y,z) in three-dimensional space translate to new
location with the translation distance T (tx, ty, tz)
x' x t x y' y t y z' z t z
– In matrix format
x ' 1 0 0 t x x
y' 0 1 0 t y y
P' T P
z' 0 0 1 t z z
1 0 0 0 1 1
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Geometric transformations in three-
dimensional space (3)
• Three-dimensional scaling
– Relative to the coordinate origin, just include the parameter
for z coordinate scaling in the transformation matrix
x ' s x 0 0 0 x
y ' 0 sy 0 0 y
P' S P
z' 0 0 sz 0 z
1 0 0 0 1 1
– Relative to a fixed point (xf, yf zf)
• Perform a translate-scaling-translate composite
transformation
t( x f , y f , z f ) S(s x , s y , s z ) T( x f , y f ,z f )
s x 0 0 (1 s x )x f
0 sy 0 (1 s y )y f
0 0 sz (1 s z )z f
0 0 0 1
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Geometric transformations in three-
dimensional space (4)
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Geometric transformations in three-
dimensional space (5)
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Geometric transformations in three-
dimensional space (6)
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Geometric transformations in three-
dimensional space (7)
1 T
R R : orthogonal matrix
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Concatenation of Transformations
• Concatenating
– affine transformations by multiplying together
– sequences of the basic transformations
define an arbitrary transformation directly
– ex) three successive transformations
p1 p2
p A B C q
p1 = Ap
p2 = Bp1 q CBAp CBAp
q = Cp2 CBA
M CBA
q = CBp1
q = CBAp q Mp p M q
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Matrix Concatenation Properties
• Associative properties
M1 M2 M3 M1 (M2 M3 ) (M1 M2 ) M3
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Two-dimensional composite
transformation (1)
• Composite transformation
– A sequence of transformations
– Calculate composite transformation matrix rather than
applying individual transformations
P' M2 M1 P
P' M P
• Composite two-dimensional translations
– Apply two successive translations, T1 and T2
T1 T (t1x , t1 y )
T2 T (t 2 x , t 2 y )
P ' T2 (T1 P ) (T2 T1 ) P
T( t 2 x , t 2 y ) T( t 1x , t 1y ) T( t 1x t 2 x , t 1y t 2 y )
– Composite transformation matrix in coordinate form
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Two-dimensional composite
transformation (2)
S(s1x ,two-dimensional
• Composite s1y ) S(s 2 x , s 2 y ) Sscaling
( s1x s 2 x , s1y s 2 y )
P' S(s1x s 2 x , s1y s 2 y ) P
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Two-dimensional composite
transformation (3)
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Two-dimensional composite
transformation (4)
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Pivot-Point Rotation
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Two-dimensional composite
transformation (5)
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Two-dimensional composite
transformation (6)
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
General Fixed-Point Scaling
T x f , y f S s x , s y T x f , y f S x f , y f , s x , s y
1 0 xf s x 0 0 1 0 xf s x 0 x f (1 s x )
0 1 yf 0 sy 0 0 1 yf 0 sy y f (1 s y )
0 0 1 0 0 1 0 0 1 0 0 1
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Two-dimensional composite
transformation (7)
s2
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
General Scaling Directions
• Converted to a parallelogram
y y
(1/2,3/ (2,2)
2)
(0,1) (1,1)
(3/2,1/
2)
(0,0) (1,0) x (0,0) x
Scale
s1 cos s2 sin ( s2 s1 ) cos sin 0
2 2 y s2
R 1 ( ) S ( s1 , s2 ) R( ) ( s2 s1 ) cos sin s1 sin 2 s2 cos 2 0
0 0 1 xs
1
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
General Rotation (1/2)
rotation of a cube about the z axis rotation of a cube about the y axis
?
rotation of a cube about the x axis
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
General Rotation (2/2)
R Rx R y Rz
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Instance Transformation (1/2)
• Instance of an object’s
prototype
– occurrence of that object in
the scene
• Instance transformation
?
– applying an affine
transformation to the
prototype to obtain desired
size, orientation, and location
instance transformation
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education
Instance Transformation (2/2)
M TRS
1 0 0 x cos sin 0 0 x 0 0 0
0 1 0 y sin cos 0 0 0 y 0 0
0 0 1 z 0 0 1 0 0 0 z 0
0 0 0 1 0 0 0 1 0 0 0 1
Computer Graphics with OpenGL, Third Edition, by Donald Hearn and M.Pauline Baler.
IBSN 0-12-0-153-90-7 @ 2004 Pearson Education, Inc., Upper Saddle River, NJ. All right reserved © 2005 Pearson Education