2D transformations
What and Wh Transformations? What? : The geometrical changes of an object from a current state to modified state. Changing an object s position (translation), orientation (rotation) or size (scaling) Others transformations: reflection and shearing operations Wh? To manipulate the initiall created object and to displa the modified object without having to redraw it.
Matrices Matri is a two Dimensional arra of numbers. Elements of the matri are identified b its row and column pair. 5 5 6 Matri multiplication: Matri multiplication is associative. Means if we have multiple matrices to multipl then, it does not matter which matri we multipl first. A(BC) = (AB)C 2/27/24 3
In CG images are made up of series of line segments. Each line segment is then represented b its end coordinates. We can make changes in the image b performing some mathematical operations on these co-or. The changes made in a image are called transformations. 2/27/24 4
Basic Transformations :. Scaling 2
Scaling X 2, Y.5
Scaling Scaling changes the size of an object and involves two scale factors, S and S for the - and - coordinates respectivel. Scales are about the origin. We can write the components: p' = s p p' = s p or in matri form: P' = S P Scale matri as: s S s P P
If the scale factors are in between and the points will be moved closer to the origin the object will be smaller. P Eample : P(2, 5), S =.5, S =.5 Find P? If the scale factors are larger than the points will be moved awa from the origin the object will be larger. P P(2, 5) Eample : P(2, 5), S = 2, S = 2 Find P?
P If the scale factors are the same, S = S uniform scaling Onl change in size (as previous eample) If S S differential scaling. Change in size and shape Eample : square rectangle P(, 3), S = 2, S = 5, P? P(, 2)
Matri It is possible to represent this scaling in terms of the matri. S= S S Therefore P = P. S
Thus: Scaling is used to alter the size of an object Simple 2D scaling is performed b multipling object positions (, ) b scaling factors s and s = s = s or P = S P = S S
Points @ 2D Scaling An positive value can be used as scaling factor Values less than reduce the size of the object Values greater than enlarge the object If scaling factor is then the object stas unchanged If s = s, we call it uniform scaling If scaling factor <, then the object moves closer to the origin and If scaling factor >, then the object moves farther from the origin
Translation A translation moves all points in an object along the same straight-line path to new positions. The path is represented b a vector, called the translation or shift vector. We can write the components:? t =4 p' = p + t p' = p + t or in matri form: P' = P + T = + t t (2, 2) t = 6
2. Translation Translation changes the position of an object. P = point before translation P = point after translation Let point P(,) P (, ) = + t, = + t T P P Translation moves the object without deformation How can we write this in matri form?
Some points @ translation 2D Translation To move a line segment, appl the transformation equation to each of the two line endpoints and redraw the line between new endpoints To move a polgon, appl the transformation equation to coordinates of each verte and regenerate the polgon using the new set of verte coordinates
Rotation A rotation repositions all points in an object along a circular path in the plane centered at the pivot point. P First, we ll assume the pivot is at the origin. P
Rotation Review Trigonometr => cos = /r, sin = /r = r. cos, = r.sin P (, ) => cos (+ ) = /r = r. cos (+ ) = r.coscos -r.sinsin =.cos.sin r P(,) =>sin (+ ) = /r = r. sin (+ ) = r.cossin + r.sincos r =.sin +.cos Identit of Trigonometr
Rotation We can write the components: p' = p cos p sin p' = p sin + p cos P (, ) or in matri form: P' = R P can be clockwise (-ve) or counterclockwise (+ve as our eample). Rotation matri r P(,) R cos sin sin cos
Eample Find the transformed point, P, caused b rotating P= (5, ) about the origin through an angle of 9. Rotation cos sin sin cos cos sin sin cos cos9 sin 9 5 sin 9 cos9 5 5 5 5
Matri Representations and Homogeneous Coordinates Man graphics applications involve sequences of geometric transformations Animations Design and picture construction applications We will now consider matri representations of these operations Sequences of transformations can be efficientl processed using matrices
Matri Representations and Homogeneous Coordinates P = M P + M 2 P and P are row matrices M is a 2 b 2 arra containing scaling factors M 2 is a 2 element row matri containing translational terms
Matri Representations and Homogeneous Coordinates To produce a sequence of operations, such as scaling followed b rotation then translation, we could calculate the transformed coordinates one step at a time A more efficient approach is to combine transformations, without calculating intermediate coordinate values
Matri Representations and Homogeneous Coordinates Multiplicative and translational terms for a 2D geometric transformation can be combined into a single matri if we epand the representations to 3 b 3 matrices. We can use the third column for translation terms, and all transformation equations can be epressed as matri multiplications
Homogenous Coordinates w Let s move our problem into 3D. Let point (, ) in 2D be represented b point (,, ) in the new space. Scaling our new point b an value a puts us somewhere along a particular line: (a, a, a). A point in 2D can be represented in man was in the new space. (2, 4) ---------- (8, 6, 4) or (6, 2, 3) or (2, 4, ) or etc.
Homogenous Coordinates We can alwas map back to the original 2D point b dividing b the last coordinate (5, 6, 3) --- (5, 2). (6, 4, ) -?. Wh do we use 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 sstem its name homogeneous coordinates.
Matri Representations and Homogeneous Coordinates Thus 2D Translation Matri is as follows: = t t
Thus 2D Rotation Matri becomes as : = cos sin sin cos Note : Positive values of the rotation angle define the counterclockwise rotation about the rotation point and negative values rotate objects in the clockwise sense.
Thus 2D Scaling Matri becomes as : = s s
Inverse Transformations When we appl an transformation to point(,) we get a new point (, ). Some times we need to get original coordinate from the transformed point. This can be achieved b inverse transformation. 2D Inverse Translation Matri T t t
Inverse Transformations 2D Inverse Rotation Matri Rotation in clockwise direction making Փ negative i.e cos(-θ)=cos θ sin(-θ)=-sin θ Matri becomes: 2D Inverse Scaling Matri cos sin sin cos R s s S
2D Composite Transformations We can setup a sequence of transformations as a composite transformation matri b calculating the product of the individual transformations P =M 2 M P P =M P
ROTATION ABOUT AN ARBITRARY POINT
2D Composite Transformations General 2D Pivot-Point Rotation Translate Rotate Retranslate cos sin sin cos r r r r
Eample Perform a clockwise rotation of 45 a triangle A(,) B(,) and C(5,2) (Dec-25,29, Marks) about a point (-,-) About origin Answer : about origin A = (,) B =( 2,) C =((7/ 2),(-3/ 2)) E2: consider a square p(,) Q(,) R(,) S(,). Rotate the Sq about fied point R(,) b an angle 45 o (anticlockwise) followed b scaling b 2 units in X direction and 2 units in Y direction. (Dec 26, 8 marks)
Prove that two scaling transformations commute that is S S2=S2 S Show that transformation matri for a reflection about a line Y=X is equivalent to reflection to X-ais followed b counterclockwise rotation of 9 (Dec 28 8 marks) Perform X-shear and Y-shear on a triangle having A(2,) B(4,3) C(2,3). Consider the constant value b=c=2 (Dec 28, 8 marks) Answer : A = 4,5 B =, C = 8,7
Scaling with respect to an arbitrar point. Translation 2. Scaling 3. Retranslation Pictoriall shown on net slide.
f f f f s s
Other Two Dimensional Transformations Reflection Transformation that produces a mirror image of an object
Reflection: -ais -ais
Reflection: origin line =
Shear Transformations Shear Transformation that distorts the shape of an object such that the transformed shape appears as the object was composed of internal laers that had been caused to slide over each other (,) (,) (2,) (3,) (,) (,) (,) (,) sh =2
X-Shear An -direction shear relative to the ais An -direction shear relative to the ais sh sh sh ' '
Transformations in 3D
Some graphics applications are 2D such as charts,graphs, maps etc. But to create realistic picture, we need to represent picture in 3D. In 3D, geometr we need additional, third ais z-ais to specif the depth value of the object. Let us see the coordinate sstems used in 3D graphics
Lets plot a point in 3D with coordinates (3,4,2) Y-ais h e i g h t Depth. first plot the point at(3,,2) it is on the plane X-Z 2. then lift the point up b 4 units. X-ais Z-ais width
Translation in 3D! Remembering 2D transformations -> 33 matrices, take a wild guess what happens to 3D transformations. 3D means z-ais comes into picture. Giving Depth information for an object.,,, z z z t t t t t t z t t t T t t t t t t T T=(t, t, t z )
Scale, 3D Stle S=(s, s, s z ) z s z s s z * * * ' * * ),, ( p p s s s P P s s s S z z
3D Rotation In 3D we have to specif the ais of rotation along with the rotation angle. Positive rotation angles produce counterclockwise rotations about a coordinate ais, assuming that we are looking in the negative direction along that coordinate ais
3D Rotation z-ais rotation = cos θ - sin θ = sin θ + cos θ z =z z = z cos sin sin cos or, P = R z (θ) P
When we sa that we want to rotate a point in anticlockwise direction about z-ais, it is ver similar to performing a 2D rotation in anticlockwise direction as follows: Fig:2D Rotation Fig: 3D Rotation
3D Rotation z-ais rotation = cos θ - sin θ = sin θ + cos θ z =z Transformation equations for rotation abt the other aes can be obtained with a cclic permutation of coordinate parameters,, and z. That is we use the replacements: z -ais rotation = cos θ - z sin θ z = sin θ + z cos θ = -ais rotation z =z cos θ - sin θ =z sin θ + cos θ
Matrices for anticlockwise 3D rotation cos sin sin cos R cos sin sin cos R cos sin sin cos Rz
3D Rotation about an arbitrar ais General Three-Dimensional Rotations Special case where an object is to be rotated about an ais that is parallel to one of the coordinate aes. Translate the object so that the rotation ais coincides with parallel coordinate ais 2. Perform the specified rotation about the ais 3. Translate the object so that the rotation ais is moved back to its original position
3D Rotation of an object about an arbitrar ais When an object is to rotated about an ais that is not parallel to one of the coordinate aes. Translate the object so that the rotation ais passes through the coordinate origin 2. Rotate the object so that the ais of rotation coincides with one of the coordinate aes 3. Perform the specified rotation about the selected coordinate ais 4. Appl inverse rotations to bring the rotation ais back to its original position 5. Appl the inverse translation to bring the rotation ais back to its original spatial position
We can determine the transformation matrices for each step. Assume that rotation ais ie arbitrar ais is defined with two points p(,,z) and p2(2,2,z2). Let us sa a point on the ais is (P,Q,R) Initial position of the ais and point is as bellow: p2 (P,Q,R) p
Step : (Translation)transformation of rotation ais so that it passes through the origin. This can be done b moving point P to the origin This repositions the rotation ais and the object as shown z T p p2 (P,Q,R)
Step2: transform the rotation ais so that it coincides the z-ais. This can be performed in two sub-steps:. a) Rotate about -ais to transform ais into z plane b) Swing rotation ais around to the z-ais using -ais rotation. a) Take projection of line segment (,,) to (P,Q,R) onto z plane as shown in fig ie (,Q,R). (,Q,R) (P,Q,R) Light source z
Step2-a Now if we rotate the rotation (arbitrar) ais @ -ais so that it lies in X-Z. In this situation its shadow will coincides the z-ais. So we are interested in angle α, so that shadow will coincides with z-ais. (,Q,R) α L (P,Q,R) length of shadow L = Q 2 +R 2 sin α = Q/L cos α = R/L Therefore the matri for rotation about -ais R (α) = R / L Q / L Q / L R / L
After performing -ais rotation the rotation ais will lie in -z plane as shown: When we perform -ais rotation -value remains unchanged as ais of rotation is in z plane so - coordinate is zero. We need to get z-value L = P 2 +Q 2 +R 2 z-coordinate will be v = (L 2 -P 2 ) P L (P,Q,R)
Step2-b Now we have to rotate the ais around -ais so that it coincides the z-ais. Let that angle be β From figure cosβ = V/L sin β = p/l P β L Therefore the transformation matri for rotation about -ais in clockwise rotation is R (β) = v / L p / L p / L v / L
step3 Rotation about z-ais b given angle ie θ ie. Rz (θ) Rz cos sin sin cos Step 4 and 5 does inverse transformations ie R -, R -,T - Therefore the final transformation matri will be the product of all matrices in sequence. RA= T. R. R.Rz. R -, R -,T -
Reflection w.r.to plane Consider a point P(,,z). The reflection of this point w.r.to plane is given b pointp (,,-z) Corresponding matri is given as: M = -