Geometric Transformations for Computer Graphics
Presentation by R.Sakthivel Murugan, AP/Mech, KCET.
Coordinate Systems • • • • • • •
World Coordinate System Object Coordinate System Hierarchical Coordinate Systems Viewpoint Coordinate System Model Window Coordinate System Screen Coordinate System Viewport Coordinate System
World Coordinate System • Also known as the "universe" or sometimes "model" coordinate system. • This is the base reference system for the overall model, ( generally in 3D ), to which all other model coordinates relate.
Object Coordinate System • When each object is created in a modelling program, the modeler must pick some point to be the origin of that particular object, and the orientation of the object to a set of model axes.
Hierarchical Coordinate Systems • Objects in a scene are arranged in a hierarchy, so that the "position" of one object in the hierarchy is relative to its parent in the hierarchy scheme, rather than to the world coordinate system.
View point Coordinate Systems • This coordinate system is based upon the viewpoint of the observer, and changes as they change their view.
Model Window Coordinate System • Coordinate system refers to the subset of the overall model world that is to be displayed on the screen
Screen Coordinate System • 2D coordinate system refers to the physical coordinates of the pixels on the computer screen, based on current screen resolution. ( E.g. 1024x768 )
Viewport Coordinate System • Coordinate system refers to a subset of the screen space where the model window is to be displayed.
2D Transformations What is transformations? – The geometrical changes of an object from a current state to modified state. Why the transformations is needed? – To manipulate the initially created object and to display the modified object without having to redraw it.
Types of 2D Transformations • Translation • Rotations • Scaling • Reflections
2D Translation (x’,y’)
(tx,ty)
(x,y)
• A translation moves all points in an object along the same straight-line path to new positions. • The path is represented by a vector, called the translation or shift vector.
2D Translation P ( x, y ) T (t x , t y )
?
P' ( x' , y ' ) x' x t x ty =4
y' y t y By Matrix Form,
(2, 2)
tx = 6
x ' x t x y ' y t y P' P T T TransformationMatrix
2D Rotation P’
P
• A rotation repositions all points in an object along a circular path in the plane centered at the pivot point. • First, we’ll assume the pivot is at the origin.
2D Rotation Review Trigonometry => cos = x/r , sin = y/r
P’(x’, y’)
x = r. cos , y = r.sin => cos (+ ) = x’/r •x’ = r. cos (+ ) •x’ = r.coscos -r.sinsin •x’ = x.cos – y.sin =>sin (+ ) = y’/r y’ = r. sin (+ ) •y’ = r.cossin + r.sincos •y’ = x.sin + y.cos
r y’ x’
P(x,y) r
x
y
2D Rotation x' r cos cos r sin sin y ' r cos sin r sin cos x' x cos y sin y ' x sin y cos By Matrix Form,
x' cos sin x y ' sin cos y P' R P R RotationMatrix
Scaling P’
P
• Scaling changes the size of an object and involves two scale factors, Sx and Sy for the xand y- coordinates respectively. • Scales are about the origin.
Scaling P ( x, y ) S (s x , s y )
Sx Sy
x' s x x y' s y y
y
x
f
, yf
x
x' s x y ' 0 P' S P
0 x s y y
S-> Scale factor
2D Reflections y
y
y
x
x
x Reflection about X axis
Reflection about Y axis
Reflection about X & Y axis
P ( x, y ) P ' ( x' , y ' ) [ X ,Y ]
P ( x, y ) P' ( x' , y ' ) [ X , Y ]
P ( x, y ) P ' ( x' , y ' ) [ X ,Y ]
1 0 x P' 0 1 y P ' Pm P
1 0 x P' 0 1 y P ' Rm P
1 0 x P' 0 1 y P' Z m P
Specifying 2D Transformations • Translation – T(tx, ty) – Translation distances
• Scale – S(sx,sy) – Scale factors
• Rotation – R() – Rotation angle
Homogeneous Coordinates w x
x
• Let’s move our problem into 3D. • Let point (x, y) in 2D be represented by point (x, y, 1) in the new space. • Scaling our new point by any value a puts us somewhere along a particular line: (ax, ay, a). • A point in 2D can be represented in many ways in the new space. • (2, 4) ---------- (8, 16, 4) or (6, 12, 3) or (2, 4, 1) or etc.
Homogeneous Coordinates Why do we use 1 for the last coordinate? • The fact that all the points along each line can be mapped back to the same point in 2D gives this coordinate system its name – homogeneous coordinates.
2D Translation
2D Rotation
2D Scaling
x 1 0 t x x y 0 1 t y , P T t , t P x y y 1 0 0 1 1 x cos y sin 1 0
x S x y 0 1 0
sin cos 0
0 Sy 0
0 x 0 y , P R P 1 1
0 x 0 y , P S S x , S y P 1 1
Composite transformations • More complex geometric & coordinate transformation can be built from the basic transformation by using the process of composition of function. • We can represent any sequence of transformations as a single matrix. – No special cases when transforming a point • matrix • vector.
– Composite transformations • matrix • matrix.
Inverse transformations:
1 0 t x cos T1 0 1 t y , R 1 sin 0 0 1 0
sin cos 0
0 0 1 S x 0 , S 1 0 1 S y 0 1 0
0 0 1
P M2 M1 P M2 M1 P M P
Composite transformations:
P T t2 x , t2 y T t1x , t1 y P T t2 x , t2 y T t1x , t1 y P
Composite translations:
1 0 t2 x 1 0 t1x 1 0 t1x t2 x 0 1 t 0 1 t 0 1 t t 2y 1y 1y 2y 0 0 1 0 0 1 0 0 1 T t2 x , t2 y T t1x , t1 y T t1x t2 x , t1 y t2 y
P R 2 R 1 P R 2 R 1 P R 2 R 1 R 1 2
Composite Rotations:
P R 1 2 P
S2 x 0 0 Composite Scaling:
0 S2 y 0
0 S1x 0 0 1 0
0 S1 y 0
0 S1x S2 x 0 0 1 0
0 S1 y S2 y 0
0 0 1
S S2 x , S2 y S S1x , S1 y S S1x S2 x , S1 y S2 y
3D Translation Very similar to 2D. Using 4x4 matrices rather than 3x3.
x x t x
Translation
y
y y t y z z tz
x, y, z z
x, y, z
x
x 1 y 0 z 0 1 0
0 1 0 0
0 tx x 0 t y y 1 tz z 0 1 1
3D Scaling y
y
x x S x y y S y z x S z
z
x
z
Enlarging object also moves it from origin
x S x y 0 P z 0 1 0
0 Sy 0 0
0 0 Sz 0
0 x 0 y SP 0 z 1 1
x
3D Rotations Rotation about X-axis ( Y-Z Plane)
Rotation about Y-axis ( Z-X Plane)
Rotation about Z-axis ( X-Y Plane)
0 x' 1 y ' 0 Cos P' z ' 0 Sin 0 1 0
0 Sin Cos 0
x' Sin y ' 0 P' z ' Cos 1 0
0 Cos 1 0 0 Sin
x' Cos y ' Sin P' z' 0 1 0
Sin Cos 0
0
0
0
0 x 0 y 0 z 1 1 0 x 0 y 0 z 1 1
0 0 x 0 0 y 1 0 z 0 1 1
Thank You