LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the...

21
Assist. Lecturer: Alaa shawqi jaber LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS

Transcript of LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the...

Page 1: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

Assist. Lecturer: Alaa shawqi jaber

LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS

Page 2: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

Outlines:

2D-Transformation Definition

Translation

Scaling

Rotation

Page 3: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation on the object the image will be manipulated. The basic geometric transformations are:

1. Translation (shift or move).

2. Scaling.

3. Rotation.

Page 4: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

A translation is a straight-line movement of an object from one position to another.

Consider a point p(x,y). Translated this point means shift it to a new postion p´(x´,y´) by adding translation distances, Tx and Ty, to the original coordinates position (x,y):

x´= x+Tx

y´= y+Ty

Translation is a rigid-body transformation that is move objects without deformation. Every point on the object is translated by the same amount.

Page 5: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

The translation distance pair (Tx,Ty) is also called a translation vector or shift vector.

The translation equation can performed as a single matrix equation by using column vectors or row vectors to represent coordinate positions and the translation vector.

P=𝑥𝑦 , T =

𝑡𝑥𝑡𝑦 , p´ =

𝑥´𝑦´

Page 6: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

Geometric transformation for a straight line segment is translated by applying the transformation equation to each of the line endpoints and redrawing the line between the new endpoint positions.

Polygons are translated by adding the translation vector to the coordinates of each vertex and regenerating the polygon using the new set of vertex coordinates and the current attribute settings.

To change the position of a circle or ellipse, we translate the center coordinates and redraw the figure in the new location.

Page 7: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

Translation distances can be specified as any real numbers (positive, negative, or zero).

In screen coordinate system the translation factor will be:

If Tx>0 then point moves to the right.

If Tx<0 then point moves to the left.

If Ty>0 then point moves to the down.

If Ty<0 then point moves to the up.

Using Cartesian coordinate system the translation factor will be:

If Tx>0 then point moves to the right.

If Tx<0 then point moves to the left.

If Ty>0 then point moves to the up.

If Ty<0 then point moves to the down.

Page 8: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

This figure Translate the

object from position (a) to

position (b) with translation

distances (-20, 50).

Page 9: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

It is the process that change the size of an object such as magnify the size or reduce it.

Suppose P(x,y) is the point that we want to scale and Sx and Sy are the scaling factors. After scaling we get new point having coordinates as

𝑝𝑠(𝑥𝑠, 𝑦𝑠) 𝑥𝑠=x * Sx

𝑦𝑠=y * Sy

We multiplying the coordinates values (x,y) by the scaling factors Sx and Sy.

Page 10: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

For example, this operation can be carried out for polygons by multiplying the coordinate values (x, y) for each boundary vertex by scaling factors Sx and Sy to produce transformed coordinates ( 𝑥𝑠, 𝑦𝑠):

𝑥𝑠 =x * Sx, 𝑥𝑦𝑠 =y * Sy

The scale equation above can also be written in the matrix form:

P=𝑥𝑦 , S =

𝑆𝑥 00 𝑆𝑦

, 𝑃𝑠 = 𝑥𝑠

𝑦𝑠

Page 11: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

Any positive numeric values can be assigned to the scaling factors Sx and Sy in which:

Values less than 1 reduce the size of objects.

values greater than 1 produce an enlargement.

Specifying a value of 1 for both Sx and Sy leaves the size of objects unchanged.

When Sx and Sy are assigned the same value, a uniform scaling is produced, which maintains relative proportions of the scaled object.

Page 12: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

Unequal values for Sx and Sy result in a differential scaling that is often used in design applications, where pictures are constructed from a few basic shapes that can be modified by scaling transformations.

Ex. Turning a square (a) into a

rectangle (b) by setting Sx = 2

and Sy = 1.

Page 13: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

If the fixed point is at the origin (0,0), a point (x,y) can be scaled by a factor Sx in the X direction and Sy in the Y direction to the point (XF,YF).

Ex. A line scaled with Eqs x'=x.Sx,

y'=y.Sy and Sx= Sy = 1/2

is reduced in size and moved closer

to the coordinate origin.

Page 14: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

We can control the location of a scaled object by choosing a position, called the fixed point (Xf, Yf), which is remain unchanged after the scaling transformation and also it can be chosen as one of the vertices, the center of the object, or any other position.

For standard figures, such as circles and ellipses, these transformations can be carried out more efficiently by modifying distance parameters in the defining equations. We scale a circle by adjusting the radius and possibly repositioning the circle center.

Page 15: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

A polygon is then scaled relative to the fixed point by scaling the distance from each vertex to the fixed point. For a vertex with coordinates (x, y), the scaled coordinates (x', y') are calculated as:

𝑥𝑔 =xf+(x-xf)Sx, 𝑦𝑔 =yf+(y-yf)Sy

Ex. Scaling relative to a chosen fixed

point (xf, yf). Distances from each

polygon vertex to the fixed point are

scaled by transformation equations

above.

Page 16: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

Other types of objects could be scaled with these equations by applying the calculations to each point along the defining boundary.

It is possible to choose any point (xf,yf) as the fixed point of scaling by performing the following steps:

1. Translate the point (xf,yf) to the origin (0,0), every point(x,y) become the new point(x',y'): x'=x-xf y'=y-yf

2. Scale the translated points with the origin as the fixed point:

𝑥𝑠=x' * Sx 𝑦𝑠=y' * Sy 3. Translate the origin back to the fixed point (xf,yf):

𝑥𝑔= 𝑥𝑠 + xf 𝑦𝑔= 𝑦𝑠 + yf These three steps can be combined in the following equation that scales a point (xf,yf):

𝒙𝒈 =(x-xf)Sx + xf

𝒚𝒈 =(y-yf)Sy + yf

Page 17: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

Transformation of object points along circular paths is called rotation.

The figure below illustrates displacement of a point from position (x, y) to position (x', y') relative to the coordinate origin.

The original angular position of the point from the x axis is Ф, so we have:

x = r cos(Ф), y = r sin(Ф)

After applying a rotation angle Ɵ, the new equations will be: x'=r cos(Ф+Ɵ) , y'=r sin(Ф+Ɵ)

Page 18: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

Using these triangles and standard trigonometric identities, we can write:

x'=r cos(Ф+Ɵ)=r cosФ cosƟ – r sinФ sinƟ

y'=r sin(Ф+Ɵ)= r sinФ cosƟ + r cosФ sinƟ

As mentioned before if we have x = r cos(Ф), y = r sin(Ф), after restated in terms of x and y, the rotation equation relative to the origin coordinate:

x'= x cosƟ - y sinƟ

y'= y cosƟ + x sinƟ

Page 19: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

With the column-vector representations, the matrix form for the rotation equations will be:

P'=R* P

R=cos Ɵ −sinƟsinƟ cos Ɵ

, P=𝑥𝑦

P´ =𝑥´𝑦´

=x cosƟ − y sinƟ

y cosƟ + x sinƟ

Page 20: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation

Positive values for Ɵ in these equations indicate a counterclockwise rotation, and negative values for Ɵ rotate objects in a clockwise direction.

Objects can be rotated about an arbitrary point by modifying the previews Eqs. to include the coordinates (xr, yr) for the selected rotation point (or pivot point).

The transformation equations for the rotated coordinates can be obtained from the trigonometric relationships in this figure as:

x'=xr+(x-xr)cosƟ- (y-yr)sinƟ

y'=yr+(y-yr)cosƟ+(x-xr)sinƟ

Page 21: LECTURE SIX TWO-DIMENSIONAL TRANSFORMATIONS2D (two-dimension)-Transformation means altering the coordinate descriptions of two-dimension objects. By using appropriate coordinate transformation