170 likes | 312 Views
COM 366 Interactive Computer Graphics Topic 2 : 2-D Transforms. COM366. Translation. COM366. Scaling. COM366. Rotation – 1. COM366. Rotation - 2. . COM366. Matrix Representation. Rotation. Scaling. Translation. COM366. Homogeneous co-ordinates. Translation.
E N D
COM 366 Interactive Computer Graphics Topic 2 : 2-D Transforms COM366
Translation COM366
Scaling COM366
Rotation – 1 COM366
Rotation - 2 COM366
Matrix Representation Rotation Scaling Translation COM366
Homogeneous co-ordinates Translation Rotation and Scaling COM366
A numerical example Suppose we wish to translate 3 units in the x direction and 2 units in the y direction. Let us imagine we have a node at (4,5) The answer we know will be x’ = 4 + 3 = 7 & y’ = 5 + 2 = 7 x’ = 1*4 + 0*5 + 3*1 = 7y’ = 0*4 + 1*5 + 2*1 = 7 1 = 0*4 + 0*5 + 1*1 COM366
CONCATENATION A translation followed by a Rotation operation x' = R.T.x x' = R.x" = R.(T.x) = R.T.x The ordering of the transformations is critical to the result : COM366
Inverse transformations Take translation as an example x = T-1.T.x COM366
Inverse scaling and rotation Remember cos(-) = cos() and sin(-) = -sin() COM366
Local origin Global origin xf = T-1.RT.xs Rotation about a local origin COM366
Programming the transforms e.g. rotation function Rotatesquare(theta); %First of all define the nodes Node = [-2 -2 2 2 -2; -2 2 2 -2 -2;1 1 1 1 1] %Now convert the rotation angle to radians %Remember 180 degs. = pi radians thetarad = pi*theta/180; %Now let us define the rotation matrix Ctheta = cos(thetarad); Stheta = sin(thetarad); Rot = [Ctheta -Stheta 0; Stheta Ctheta 0; 0 0 1] %Now rotate the square NewNode = Rot*Node; %Draw the square plot(NewNode(1,:),NewNode(2,:)) %Set the limits to the axes and ensure they are of equaldimension axis([-5,5,-5,5]); axis square; COM366
The Linear Transform If T is one of the basic graphic transforms (translation, scaling, rotation) then T is linear in the sense that if 1 and 2 are two parameters then : Put simply in terms of translation a translation of 2 cms followed by a second translation of 3 cms will generate exactly the same image as a single translation of 5 cms. COM366