61
Chapte r 3 2D TRANSFORMATION

Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

Chapter 3

2D TRANSFORMATION

Page 2: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

2

Transformation

Transformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines etc. The fundamental objective of 2-D transformation is to simulate the movement and manipulation of objects in the plane. Points and lines which join them, along with appropriate drawing algorithm, are used to represent objects. The ability to transform these points and lines is achieved by translation, rotation, scaling and reflection.

Two points of view are used for describing the object movement. The first is that the object itself is moved relative to a stationary co-ordinate system or background. The mathematical statement of this viewpoint is described by geometric transformation applied to each point of the object. The second point view holds that the object is held stationary, while the coordinate system is moved relative to the object. This effect is obtained through the application of coordinate transformations. For example let us consider the movement of any automobile against a scenic background through two view point. We can simulate it by moving the automobile keeping the background fixed (geometric transformation) or keeping the car fixed and moving the background (co-ordinate transformation).

Page 3: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

3

Representation of point and object

A point’s co-ordinate can be expressed as element of matrix. Two matrix formats are used, one is row matrix and other is column matrix format. For a 2D point (x,y) the row matrix format consists of a single row (x,y)1x2 and in column matrix format there is a single column

( xy )2x1 . The above two matrices are frequently

called position vectors. We will follow the column matrix convention. As all graphic objects are built with finite no. of points each such object can be uniquely represented by a optimum no. of definition points lying on the object. For example any line segment can be represented by the end points only although there are thousands of adjacent points on a line between the end points. Any line with end points (1,2) and (3,4) may be represented in column matrix format as

(1 32 4). Similarly for any triangle having the

vertices (1,1,1), (3,5,5) and (5,4,6) can be represented uniquely as

1 3 51 5 41 5 6

Translation

Translation can be defined as rigid body transformation that moves objects without deformation. Every point on the object is

Page 4: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

4

translated by the same amount. Let us think of a point P with the co-ordinate (x, y).

The point is forced to move by an amount Δx in the horizontal direction and Δy in the vertical direction to its new position P/ with the coordinate (x/,y/) such that

x/=x+Δx and y/=y+Δy ,the amount of translation is =2√ (Δx ) 2+(Δy )2In matrix notation this can be written as

Page 5: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

5

( x 'y ' ) =( xy )+(ΔxΔy )(∆ x∆ y) is called Translation vector or Shift

vector. In general the above equation may be expressed as [X/]=[X]+[TT] where [X/] is transformed object matrix ,[X] is the original object matrix and [TT] is the transformation matrix for translation.

Translation of a line can also be represented in a similar manner. Let any line AB with the end point A (0,8) and B (9,12). The line is moved to new position A/B/ with the coordinate A/(6,5) and B/(15,9). In case of translation of a line the end points are shifted and the line is redrawn at the new position by deleting the old line.

Here A(0,8) becomes A/ (6,5) implying Δx=6, Δy= -3B (9,12) becomes B/(15,9) implying Δx=6, Δy= -3

So we can say (65)=(08)+( 6−3) and (15

9 )=( 912)

+( 6−3)

Combining these two we have

(6 155 9 )=(0 9

8 12)+( 6 6−3 −3)

Page 6: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

6

It is to be noted that whatever amount of translation we apply to a straight line the length and orientation (slope) of the translated line remains same as that of the original line. It can be proved that all the points over the lines are shifted by the same amount. The midpoint of the line before transformation is

C=9+0

2,12+8

2

C= (4.5,10)

After transformation Cˊ=6+15

2,5+9

2

Cˊ= (10.5, 7). so Δx=10.5-4.5=6 Δy=7-10=-3 same as the end points. In translation there exists a one to one correspondence between the transformed points and the original points.

Rotation

Page 7: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

7

This transformation is used to rotate object about any point in a reference frame. In rotation position as well as orientation of the object is changed. The point about which the object is rotated is called pivot point or rotation point. Conventionally anti-clockwise rotation is represented by positive angular value.

Rotation about Origin

2D rotation of a point about origin

Let P(x,y) be any point with polar co-ordinate (r,ϕ) . Then

Page 8: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

8

x=r cosϕ and y=r sinϕ

When this point is rotated by an angle θ in the anti-clock wise rotation the new point become Pˊ=(xˊ,yˊ) such that

xˊ=r cos(θ+ϕ) yˊ=r sin(θ+ϕ)

i.e. xˊ=r cosθsinϕ - r sinθcosϕ yˊ=r sinθcosϕ + r cosθsinϕ

Replacing r cosϕ and r sinϕ with x and y we get xˊ=x cosθ-y sinθ yˊ=x sinθ+y cosθ

In matrix notation this can be written as

( x 'y ' )=(cosθ −sinθsinθ cosθ )(xy)

Symbolically [X’]=[TR][X] where [TR] is the transformation matrix for rotation. The equation is applicable only for rotation about the origin. But in many applications the pivot point will not be the origin. It may be any point lying on the object to be rotated or any point outside the object simply anywhere in the same 2D plane.

Rotation about an arbitrary Pivot Point

Page 9: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

9

Rotation of a point P about PP

Here the pivot point is an arbitrary point Pp

having coordinate (xp,yp). After rotating through an angle θ the point P (x,y) becomes P′ (x′,y′).

Here x′=OB =OA+AB =xp+r cos(θ+ϕ) =xp+r cosθ cosϕ-r sinθ sinϕ =xp+(x-xp) cosθ-(y-yp) sinθ

Now r cosϕ= AC =OC-OA =x-xp and r sinϕ=A′C′ =OC′-OA′ =y-yp

Also y′=OB′ =OA′+A′B′ =yp+r sin(θ+ϕ) =yp+r cosϕ sinθ+r sinϕ cosθ

Page 10: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

10

=yp+(x-xp) sinθ +(y-yp) cosθ

Now x′=xp+(x-xp) cosθ-(y-yp) sinθ y′=yp+(x-xp)sinθ+(y-yp) cosθ

In matrix form we can write the equation in the form

( x 'y ' )=(cosθ −sinθsinθ cosθ )( x−xp

y− yp) +( xpyp)The equation can also be rearrange by grouping the (xp,yp) and (x,y) related terms

x′=(xp-xpcosθ+ypsinθ)+(xcosθ-ysinθ)={xp(1-cosθ)+ypsinθ}+(xcosθ-ysinθ)

Similarlyy′={(-xpsinθ)+yp(1-cosθ)}+(xsinθ+ycosθ) In matrix form

( x 'y ' )=(cosθ −sinθsinθ cosθ )(xy) +

(1−cosθ sinθ−sinθ 1−cosθ )(xpyp)

Symbolically [X′]=[TR][X]+[TP]The equation is different from the equation of rotation with respect to origin by an additive term [Tp] involving pivot point coordinate. However the equation can be transformed into more convenient format [X′]=[T][R] involving no additive terms using Homogeneous Coordinate system.

Page 11: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

11

Note: The matrix representing rotation with respect to origin has some special characteristic The determinant value of the matrix [TR]=

(cosθ −sinθsinθ cosθ ) is =cos2θ+sin2θ=1

The rotation with respect to rotation is known as pure rotation. The general transformation with determinant equal top +1 yield pure rotation.

If we replace the angle θ by –θ the rotation matrix become

(cos (−θ) −sin (−θ)sin (−θ) cos (−θ) ) =( cosθ sinθ

−sinθ cosθ) which can be consider as a inverse rotation of any point by an angle θ and can be denote as [TR]inv

[TR][TR]inv=(cosθ −sinθsinθ cosθ )( cosθ sinθ

−sinθ cosθ) =

( cos2θ+sin 2θ cosθsinθ−sinθcosθsinθcosθ−cosθsinθ cos2θ+sin 2θ )

=(1 00 1) =[I] the identity matrix

So [TR]inv=[TR]-1 i.e. inverse rotation matrix is equal to inverse of the rotation matrix because [TR][TR]-1=[I]

Another thing is that if we take the transpose of the matrix for pure rotation we have

Page 12: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

12

[TR]T=( cosθ sinθ−sinθ cosθ)=[TR]-1

Thus we can infer that inverse of the pure rotation matrix is its transpose.

General Pivot-Point, Rotation Algo

We can generate rotations about any selected pivot point by performing the following sequence of translate-rotate-translate operations:

Translate the objects so that the pivot-point position is moved to the coordinate origin.

Rotate the object about the coordinate origin

Translate the object so that the pivot is returned to its original position.

Scaling

Scaling with Respect to Origin

caling is a transformation that changes the size or shape of an object. Scaling with respect to origin can be carried out by

multiplying the coordinate values (x,y) of each vertex of a polygon, or each end point of a line or arc or the center point and peripheral definition points of closed curves like circle by

S

Page 13: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

13

scaling factors Sx and Sy respectively to produce the coordinate (x′,y′).

The mathematical expression for pure scaling is,

x′=Sx x

y′=Sy y ( x 'y ' )=(Sx 00 Sy )( xy )

or Symbolically [X′]=[TS][X]

Sx expands or shrinks object dimensions along X direction where as Sy affects dimensions along Y direction

Page 14: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

14

Line PQ scaled to P′Q′ ( Sx=Sy=0.5) and to P′′Q′′ ( Sx=Sy=2). Square ABCD with side 6 unit is uniformly scaled ( Sx=Sy=2) producing a bigger square A′B′C′D′ with side 12 unit. But with non uniform scaling ( Sx=2,Sy=0.5) the square changes to a 12 by 3 rectangle A′′B′′C′′D′′

Any positive numeric values can be assigned to the scaling factors Sx and Sy. Values less than 1 reduce the size of objects and values greater than 1 increase the size of the objects. Both Sx and Sy

equal to 1 leaves the size of the objects unchanged. When Sx and Sy are assigned the same value a uniform scaling is produced that maintain the shape of the object unchanged whereas unequal values for both Sx and Sy result in a differential scaling where the basic shape of the object is changed. Not only that scaling factors with values less than 1 move the objects closer to the origin while values greater than 1 move positions farther from the origin.

Scaling with Respect to fixed point within the object

Scaling with respect to origin always involve translation. Either objects are moved towards origin or away from the origin. However we can control the location of a scaled object by scaling the object with respect to a fixed point within the object. As the point is fixed the object remains fixed.

Page 15: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

15

Here PQ is the original object with the coordinate P(3,5) and Q(3,10) which is scaled by a factor 2 with respect to the fixed point Q. The object becomes P′Q so that

P′=[(3,5)+2x{(3-3),(10-5)}] =[(3,5)+2x(0,5)] =[3,15]

In general if any point (x,y) is scaled with respect to any fixed point (xf,yf) and become (x′,y′) we can write

x′=xf+(x-xf) Sx and y′=yf+(y-yf) Sy

We can rewrite the equations in the formx′=x. Sx +xf(1-Sx) and y′=y.Sy+ yf(1-Sy)

In matrix notation we can write the equations as

( x 'y ' )=(Sx 00 Sy )( xy )+(1−Sx 0

0 1−Sy )(XfYf )[X′]=[TS][X]+[Tf]

Page 16: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

16

Where the first term denotes the scaling with respect to origin and the additive term is constant for all points in the object.

Polygons are scaled by applying transformations to each vertex and then rearranging the polygon using the transformed vertices. Other objects are scaled by applying the scaling transformation equation to the parameters defining the objects. An ellipse in standard position is resized by scaling the semi major and semi minor axes and redrawing the ellipse about the designated center coordinates. Uniform scaling of a circle is done by simply adjusting the radius. Then we redisplay the circle about the center coordinates using the transformed radius.

Note: Sx and Sy can be equal or unequal and can be >1,<1 or even negative integer or fraction but never equal to zero

General fixed point scaling

To produce scaling with respect to a selected fixed position using a scaling function that can only scale relative to the coordinate origin the steps are

Translate object so that the fixed point coincides with the coordinate origin.

Page 17: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

17

Select the object with respect to the coordinate origin.

Use the inverse translation to return the object to its original position.

Reflection

A Reflection is a transformation that produces a mirror image of an object. In 2D reflection we consider any line in 2D plane as the mirror; the original object and the reflected object are both in the same plane but on the opposite side of the mirror line. However we can consider 2D reflection as a 3D rotation of 180° about the mirror line while the rotation path being in the plane perpendicular to the plane containing the mirror line.

The basic principles behind reflection transformation are:

The image and the object both lies on the opposite side of the mirror line.

The perpendicular distance of the object from the mirror line is identical to the distance of the reflected image from the same line while the perpendiculars are along the same straight line

Reflection about X axis

Page 18: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

18

The relation between the point P(x,y) and its image P′(x′,y′) is simply

x′=xy′= -y

In matrix notation we write it as

( x 'y ' )=(1 00 −1)(xy )

So the transformation matrix for reflection about x axis or y=0 is

[TM]y=0 =(1 00 −1)

The 2D reflection of the triangle ABC about x axis produces A′B′C′ which can be consider as 3D rotation of that triangle of 180° about x axis in 3D space.

Page 19: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

19

Reflection about Y axis

A reflection about Y axis changes the x coordinate while the y coordinate remains unchanged. For reflection of P(x,y) to P′(x′,y′) we have

x′= -xy′=y

In matrix notation this can be written as

( x 'y ' )=(−1 00 1)(xy )

The transformation matrix for reflection with respect to y axis or x=0 line is

[TM]x=0= (−1 00 1)

Page 20: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

20

Reflection about the straight line y=x

Let P(x,y) the original point is reflected through the line y=x straight line and P′(x′,y′) be its image.

Here PK and P′K both are equal and perpendicular to y=x or OK.

Now between the ΔPKO and ΔP′OK1. PK=P′K2. <PKO=<P′KO3. OK is common side

So ΔPKO≅ΔP′KO∴OP=OP′ and <POK=<P′OK

Now between the triangle ΔOPM and ΔOP′N we have

1. OP=OP′2. <POM=<P′ON3. <PMO=<P′NO=90°

Page 21: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

21

∴ ΔPMO≅ΔP′NO

So ON=OM and P′N=PM

i.e. x′=y and y′=x

In matrix notation this can be written as

( x 'y ' )=(0 11 0)( xy )

The transformation matrix for reflection with respect to the line y=x is

[TM]y=x=(0 11 0)

In a similar manner this can be prove that the transformation matrix for reflection with respect to the straight line y= -x is

[TM]y=-x=( 0 −1−1 0 )

Reflection through the coordinate origin

Page 22: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

22

When reflection with respect to origin is taken both x and y coordinates change their sign. Here the mirror line passes through origin and contains over the plane perpendicular to XY plane.

x′=-xy′=-y

In matrix notation this can be written as

( x 'y ' )=(−1 00 −1)( xy)

The transformation referred to as a reflection relative to the coordinate origin has the matrix representation

[TM]x=y=0=(−1 00 −1)

This reflection can be consider as a rotation with 180° where rotation is taken in the XY plane half a revolution about the origin i.e. θ=180°.

Page 23: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

23

Homogeneous Coordinates and combination of Transformation

any graphics applications involve sequence s of geometric transformations. For example an

animation requires translation and rotation to be involved at each increment of the motion. In reality design and picture construction combines all types of transformation like translation, rotation, scaling.

M

Let us consider a case which requires 90°

rotation of a point ( xy ) about origin followed by

reflection through the line y=x

After rotation ( x 'y ' )=(0 −11 0 )(xy )=(− y

x ) .

( x 'y ' ) After reflection becomes ( x ' 'y ' ')

( x ' 'y ' ')=(0 11 0)( x 'y ' )=(0 1

1 0)(− yx )=( x

− y )

These successive matrix operations can be symbolically expressed as [X′′]=[TM]y=x[TR]90°[X]

As matrix multiplication is associative we can perform [TM]y=x[TR]90° to draw a combine matrix [TCOMB] such that [TCOMB]= [TM]y=x[TR]90° =

(0 11 0)(0 −1

1 0 )=(1 00 −1)

Page 24: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

24

Now [X′′]=[TCOMB][X]=(1 00 −1)(xy )=( x

− y )

which shows the same result as before.This process of calculating the product matrices of a number of different transformations in a sequence is known as combination of transformations and the resultant matrix is referred to as composite transformation matrix.

The problem is that it is impossible to derive the combination matrix when the transformation involves translation or rotation or scaling with respect to any arbitrary point. The reason being the general form of expression of such transportation is not simply [X′]=[T][X] containing 2 by 2 array [T] having multiplicative factors, rather it is in the form [X′]=[T1][X]+[T2] where the additional matrix is due to translation of the origin. Such transformations cannot be combined to form a single resultant matrix. This problem can be eliminated if we can combine [T1] and [T2] into a single transformation matrix. This can be done by expanding the usual 2X2 transformation matrix format into 3X3 form. The general 3X3 form will be something like,

[(a bc d) m

n0 0 1 ] where the elements a, b, c, d of

the upper left 2X2 sub matrix are the multiplicative factors of [T1] and m, n are the respective translation factors of [T2]. But such 3X3 matrix is not conformable for multiplication with 2X1 positional coordinate matrices.

Page 25: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

25

Therefore we need to include a dummy

coordinate to make 2X1 position matrix( xy ) to a

3x1 matrix ( xy1 ) where the third coordinate is

dummy.

Now if we multiply ( xy1 ) with a non zero scalar

‘h’ then the matrix becomes ( xhy hh ) or

symbolically (XhY hh ) which is known as

homogeneous coordinate of the same point ( xy ) in 2D plane.

( xy ) (XhY hh )=h.( xy1 ) where the

extra coordinate h is homogeniously applied to the cartesian components. Thus a general

Page 26: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

26

homogeneous representation of any P(x,y) is

(xh,yh,h) or (xh,yh,h) that implies x=X hh

,y=Y hh

h can have any non zero scaler value but for geomatric transformation our choice is simply h=1 and the coorespondinghomogeneous coordinate triple (x,y,1) for representing any point (x,y) in XY plane.

Expressing position in homogeneous coordinates allows us to represent all geometric transformation equation uniformly as matrix multiplication.

Thus for translation we now have

( x 'y '1 )=(1 00 1

ΔxΔy

0 0 1 )( xy1 ) coordinates are represented by three element column matrix and transformation operation are written by 3X3 matrix.

Equation of scaling and rotation with respect to origin can be modified as

( x 'y '1 )=(Sx 00 Sy

00

0 0 1)( xy1 )

Page 27: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

27

( x 'y '1 )=(cosθ −sinθsinθ cosθ

00

0 0 1)(xy1)

The simplest form of representing rotation about any arbitrary point (xp,yp) is

( x 'y '1 )=(cosθ −sinθsinθ cosθ

(1−cosθ ) xp+sinθyp(1−cosθ ) yp−sinθxp

0 0 1 )( xy1 )For scaling with respect to any arbitrary fixed point (xf,yf) we have

( x 'y '1 )=(Sx 0

0 Sy(1−Sx ) xf(1−Sy ) yf

0 0 1 )( xy1 )Composite Transformation

Since we are now aware of representing all kinds of transformation in a homogeneous manner we

Page 28: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

28

can reduce a long sequence of transformations to a series of multiplications with little difficulty. Let us now consider the problem of reflection in more general form considering composite transformation which involves successively translation, rotation and reflection.

Reflection through an arbitrary line

The problem of reflection of an object through a line that neither passes through the origin nor is parallel to the coordinate axes can be solved using the following steps.

1. Translate the line and the object so that the line passes through the origin.

2. Rotate the line and the object about the origin until the line coincident with one of the coordinate axes about which we are familiar to perform reflection.

3. Reflect the object about the coordinate axis.

4. To the object apply the inverse rotation about the origin.

5. Translate the object back to the original location.

In matrix notation [TCOMB]=[TT]-1[TR]-1[TM][TR][TT]

Page 29: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

29

Note: for each geometric transformation thereexistsaninversetransformationwhichdescribesjusttheoppositeoperationofthatperformedbytheoriginaltransformation

Let the arbitrary line is given by y=mx+c where m=slope of the line=tanθ and c=intercept on the Y axis made by the line. Then the amount of translation in the first step should be (0,-c) whereas the amount of rotation in step 2 should be –θ about the origin if we prefer to merge the line with the X axis.

So we can say[TCOMB]=[TT]-1

0,-c[TR]-1-θ[TM]y=0[TR]-θ[TT]0,-c

=

(1 00 1

0c

0 0 1)(cosθ −sinθsinθ cosθ

00

0 0 1)(1 00 −1

00

0 0 1)( cosθ sinθ−sinθ cosθ

00

0 0 1)(1 00 1

0−c

0 0 1 )Where θ=tan-1m

Problem: derive the composite matrix for reflection with respect to the line parallel to Y axis say x=k straight line when k≠0

Solution: The line x=k does not intersect the Y axis at all. In that case we will first translate the object and the mirror line by –k unit in X direction to merge the mirror line with Y axis, then reflect the object about Y axis and finally translate the reflected the object k units in X direction

Page 30: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

30

Accordingly [TM]x=k=[TT]-1-k,0[TM]x=0[[TT]-k,0

=(1 00 1

k0

0 0 1)(−1 00 1

00

0 0 1)(1 00 1

−k0

0 0 1 )=

(−1 00 1

2k0

0 0 1 )Shear

A different category of transformation that distorts the shape of an object such that the transformed shape appears as if the object were composed of internal layers that had been caused to slide over each other. Two common shearing transformations are those that shift coordinate x values and those that shift y values.

An X direction shear relative to the X axis is produced by shifting the original coordinate position (x, y) by an amount proportional to its distance ‘y’ from the X axis i.e.

x′=x+shxy where shx is the shear parameter in the positive X directiony′=y

The corresponding transformation matrix is

Page 31: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

31

(1 Shx0 1

00

0 0 1)

Any real value can be assigned to the shear parameter shx. for example shx=1 changes the square into a parallelogram as in above figure. Negative values for shx shift coordinate positions to the left.

We can generate x direction shear relative to other reference lines with the equation

( x 'y ' )=(1 Sh x0 1 )( xy ) + (0 −Sh x

0 0 )(XrefYref )The transformation matrix can be written using homogeneous as

(1 Sh x0 1

−S h x .Yref0

0 0 1 )

Page 32: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

32

With coordinate positions transformed as x′=x+shx(y-yref) and y′=y

An example of shear transformation for shear parameter value ½ relative to the line

yref= -1

x1′=0+12

X (1-(-1)) =0+1=1

x2′=1+12

X (1(-1)) =1+1=2

x3′=0+12

X (0(-1)) =12

x4′=1+12

X (0-(-1)) = 1+12

= 32

A y direction shear relative to the line x=xref can be written as

( x 'y ' )=( 1 0Sh y 1)( xy) + ( 0 0

−Sh y 0)(XrefYref )

Page 33: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

33

The transformation matrix using homogeneous coordinate can be written as

( 1 0Sh y 1

0−Sh y . Xref

0 0 1 )This generated transformed coordinate positions x′=x and y′=shy(x-xref) +y

Shearing operation can be expressed as sequence of basic transformations. The x direction shear matrix can be written as a composite transformation involving a series of rotation and scaling matrices that would scale a unit square along its diagonal while maintaining the original lengths and orientations of edges parallel to the x axis. Shifts in the positions of objects relative to shearing references

Transformation between coordinate system

Graphical application often require the transformation of object descriptions from one coordinate system to another. For example object described in polar-coordinate are sometimes converted to Cartesian device coordinate for display. For modeling and design applications, individual objects may be defined in their own local Cartesian references and the local coordinates must be transformed to position the objects within the overall scene coordinate system. Here we consider transformation between two Cartesian frames of reference.

Page 34: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

34

Figure shows two Cartesian system with the coordinate origins at (0,0) and (x0,y0) and with an orientation angle θ between x and x′ axis. To transform object description from xy coordinate to x′y′ coordinates we need to superimpose the x′y′ axes to xy axes. This is done in two steps:

Translate so that the origin (x0,y0) of the x′y′ system is moved to the origin of the xy system.

Rotate the x′ axis onto the x axis.

Translation of the coordinate origin is expressed with the matrix operation

T(-x0,-y0)=[1 00 1

−X0−Y 0

0 0 1 ]

Page 35: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

35

To get the axes of the two systems into coincidence we have to perform the clockwise rotation of an angle θ

R(-θ)=[ cosθ sinθ−sinθ cosθ

00

0 0 1]Concatenating these two transformations matrices gives us the complete composite matrix for transforming object descriptions from the xy system to x′y′ system.

Mxy,x′y′=R(-θ).T(-x0,-y0)

Page 36: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

36

ExerciseMultiple Choice Questions

1. If direction of rotation is Z axis, then direction of position of positive rotation is (a) y to z (b) z to x (c) y to x (d) x to y2. Expressing positions in homogeneous co-ordinate is advantageous because (a) It represents all geometric transformation equations as matrix multiplication (b) 2D and 3D representations of transformations become identical (c) Both (a) & (b) (d) None of these.3. In homogenous coordinate representation [4, 2, 0] represents a point (a) Lying at infinity (b) at ( 4, 2 ) (c) At (4, 2) and at (2, 1) (d) None of these.4. Dragging in computer graphics is achieved through which of the following transformation?

Page 37: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

37

(a) Translation (b) Scaling (c) Rotation (d) None of these.

Short Answer Type1. What is shearing? Explain with example.2. Prove that the Inverse of the rotation matrix is its transpose.3. Obtain the transformed co-ordinates of vertices of triangle ABC, with A (0, 0), B (1, 1) and C(5, 2) after rotation about the point (- 1, - 1).Ans. The rotation matrix with respect to any arbitrary point xp, yp is

(cosθ −sinθsinθ cosθ

(1−cosθ ) xp+sinθyp(1−cosθ ) yp−sinθxp

0 0 1 )

Here xp=-1 and yp=-1Let the Δ ABC after scaling changes to ΔA′B′C′

ΔABC is defined by (0 1 50 1 2)

After scaling the coordinate are

(cosθ −sinθsinθ cosθ

(cosθ−1 )−sinθ(cosθ−1 )+sinθ

0 0 1 )(0 10 1

52

1 1 1)

Where rotation is taken as θ

4. What is Homogeneous Co-ordinate System? How is it used for composite transformation?

Page 38: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

38

5. Show how shear transformation may be expressed in terms of rotation and scaling.Ans. Shear transform can be written as a composite transformation involving a series of rotation and scaling matrices. (incomplete)6. Magnify the triangle with vertices a (0, 0), b (1, 1), c (5, 2) to twice its size while keeping c( 5, 2 ) fixed.Ans. General Transformation matrix for scaling with respect to any fixed point xf and yf is

(Sx 00 Sy

(1−Sx ) xf(1−Sy ) yf

0 0 1 )With this problem Sx=Sy=2 and xf=5 and yf=2Let the Δ ABC after scaling changes to ΔA′B′C′

ΔABC is defined by (0 1 50 1 2)

After scaling the coordinate are

(2 00 2

−5−2

0 0 1 )(0 10 1

52

1 1 1)=(−5 −3−2 0

52

1 1 1)Now ΔA′B′C′ becomes (−5 −3 5

−2 0 2)7. Derive the transformation that rotates an object point with an angle about the origin. Write the matrix representation for this rotation. Find the matrix that represents rotation of an object by 30 deg. about the origin. What are the new coordinates of the point p (2, -4) after the rotation?

Page 39: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

39

Ans. Let the new coordinate of the point x′, y′

So ( x 'y '1 )=(cosθ −sinθsinθ cosθ

00

0 0 1)(−2−41 )=

(cos 30° −sin 30°sin30 ° cos30 °

00

0 0 1)(−2−41 )

9. Why are homogeneous coordinates used for transformation computations in computer graphics?10. Derive composite transformation matrix for

two successive translation two successive scaling and general pivot point rotation

Ans. Composite transformation matrix for two successive translations

(1 00 1

Δx 1Δy 1

0 0 1 )(1 00 1

Δx2Δy 2

0 0 1 )=(1 00 1

Δx 1+Δx 2Δy 1+Δy 2

0 0 1 )Composite transformation matrix for two successive scaling

Page 40: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

40

(Sx1 00 Sy 1

00

0 0 1)(Sx2 00 Sy 2

00

0 0 1) =

(Sx1.Sx 2 00 Sy1.Sy 2

00

0 0 1)Descriptive Question

1. Prove that uniform scaling (Sx= Sy) and a rotation form a commutative pair of operations but that, in general, scaling and rotation are not commutative operations.Ans. For rotation [TR]θ =

(cosθ −sinθsinθ cosθ

00

0 0 1) For scaling [TS]Sx,Sy=(Sx 0

0 Sy00

0 0 1)When rotation is followed by scaling we have

Page 41: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

41

[TCOMB]SR=

(Sx 00 Sy

00

0 0 1)(cosθ −sinθsinθ cosθ

00

0 0 1)=

(Sxcosθ −SxsinθSysi nθ Sycosθ

00

0 0 1)When scaling is followed by rotation

[TCOMB]RS=

(cosθ −sinθsinθ cosθ

00

0 0 1)(Sx 00 Sy

00

0 0 1)=

(Sxcosθ −SysinθSxsinθ Sycosθ

00

0 0 1) Comparing the two matrix we find that they are identical only when Sx=Sy i.e. for uniform scaling

2. Show that transformation matrix for a reflection about the line y = - x is equivalent to a reflection relative to the y axis followed by a counterclockwise rotation of 90 degree.

Ans. In homogeneous transformation matrices for reflection through y= -x and about y axis are

Page 42: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

42

( 0 −1−1 0

00

0 0 1) and

(−1 00 1

00

0 0 1)The counterclockwise rotation of

90° can be written as in matrix form

(cosθ −sinθsinθ cosθ

00

0 0 1)θ=90°=

(0 −11 0

00

0 0 1)Reflection relative to y axis

followed by a counterclockwise rotation of 90° can be written in composite transformation as

[TCOMB]= (0 −11 0

00

0 0 1)

(−1 00 1

00

0 0 1) = ( 0 −1−1 0

00

0 0 1)

which is same as reflection matrix through y= -x line.

3. Derive the transformation matrices for 2D reflection about X-axis and y-axis.

Page 43: Chapter 3  · Web viewTransformation means a change in either position or orientation or size or shape of graphic objects like line, arc, circle, ellipse, rectangles, polygon, polylines

43

4. Find the equation of the line y′ = mx′ + b in X - Y coordinates if the X′ - Y′ coordinatesystem results from a 90° rotation of the X - Y coordinate system.

Ans. The rotation coordinate transformation equations can be written as x′=x cos 90°+ y sin 90°=y , y′= -x sin 90° + y cos 90°= -x Substituting we find –x=my+b. Solving for y

we have y=1m

x - bm