Loading in 5 sec....

2D and 3D TransformationPowerPoint Presentation

2D and 3D Transformation

- 66 Views
- Uploaded on

Download Presentation
## PowerPoint Slideshow about ' 2D and 3D Transformation' - thomas-kirby

**An Image/Link below is provided (as is) to download presentation**

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

### 2D and 3D Transformation

Pradondet Nilagupta

Dept. of Computer Engineering

Kasetsart University

204481 Foundation of Computer Graphics

Transformations and Matrices

- Transformations are functions
- Matrices are functions representations
- Matrices represent linear transformation
- {2x2 Matrices} {2D Linear Transformation}

204481 Foundation of Computer Graphics

Transformations (1/3)

- What are they?
- changing something to something else via rules
- mathematics: mapping between values in a range set and domain set (function/relation)
- geometric: translate, rotate, scale, shear,…

- Why are they important to graphics?
- moving objects on screen / in space
- mapping from model space to screen space
- specifying parent/child relationships
- …

204481 Foundation of Computer Graphics

ty

tx

hnew

hold

wold

wnew

Transformation (2/3)- Translation
- Moving an object

- Scale
- Changing the size of an object

xnew = xold + tx; ynew = yold + ty

sx=wnew/wold sy=hnew/hold

xnew = sxxold ynew = syyold

204481 Foundation of Computer Graphics

Transformation (3/3)

- To rotate a line or polygon, we must rotate each of its vertices
- Shear

Original Data y Shear x Shear

204481 Foundation of Computer Graphics

Transformations: Translation (1/2)

- A translation is a straight line movement of an object from one position to another.
- A point (x,y) is transformed to the point (x’,y’) by adding the translation distances Tx and Ty:

x’ = x + Tx

y’ = y + Ty

204481 Foundation of Computer Graphics

Transformations: Translation(2/2)

- moving a point by a given tx and ty amount
- e.g. point P is translated to point P’
- moving a line by a given tx and ty amount
- translate each of the 2 endpoints

204481 Foundation of Computer Graphics

Transformations: Rotation (1/4)

- Objects rotated according to angle of rotation theta ()
- Suppose a point P(x,y) is transformed to the point P'(x',y') by an anti-clockwise rotation about the origin by an angle of degrees, then:

Given x = r cos , y = r sin

x’ = x cos – y sin

y’ = y sin + y cos

204481 Foundation of Computer Graphics

Transformations: Rotation (2/4)

- Rotation P by anticlockwise relative to origin (0,0)

204481 Foundation of Computer Graphics

Transformations: Rotation (3/4)

- Rotation about an arbitary pivot point (xR,yR)
Step 1: translation of the object by (-xR,-yR)

x1 = x - xR

y1 = y - yR

Step 2: rotation about the origin

x2 = x1 cos(q) - y1sin (q)

y2 = y1cos(q) - x1sin (q)

Step 3: translation of the rotated object by (xR,yR)

x’ = xr + x2

y’ = yr + y2

204481 Foundation of Computer Graphics

Transformations: Rotation (4/4)

- object can be rotated around an arbitrary point (xr,yr) known as rotation or pivot point by:

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

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

204481 Foundation of Computer Graphics

Transformations: Scaling (1/5)

- Scaling changes the size of an object
- Achieved by applying scaling factors sx and sy
- Scaling factors are applied to the X and Y co-ordinates of points defining an object’s

204481 Foundation of Computer Graphics

Transformations: Scaling (2/5)

- uniform scaling is produced when sx and sy have same value i.e. sx = sy
- non-uniform scaling is produced when sx and sx are not equal - e.g. an ellipse from a circle.
- i.e. sx sy

x2 = sxx1 y2 = syy1

204481 Foundation of Computer Graphics

Transformations: Scaling (3/5)

Simple scaling - relative to (0,0)

- General form:

Ex: sx = 2 and sy=1

204481 Foundation of Computer Graphics

Transformations: Scaling (4/5)

- If the point (xf,yf) is to be the fixed point, the transformation is: x' = xf + (x - xf) Sx y' = yf + (y - yf) SyThis can be rearranged to give: x' = x Sx + (1 - Sx) xf y' = y Sy + (1 - Sy) yfwhich is a combination of a scaling about the origin and a translation.

204481 Foundation of Computer Graphics

Transformations: Scaling (5/5)

204481 Foundation of Computer Graphics

Transformation as Matrices

Scale:

x’ = sxx

y’ = syy

Rotation:

x’ = xcos - ysin

y’ = xsin + ycos

Translation:

x’ = x + tx

y’ = y + ty

204481 Foundation of Computer Graphics

Shear in x then in y

204481 Foundation of Computer Graphics

Shear in y then in x

204481 Foundation of Computer Graphics

Homogeneous coordinate

- As translations do not have a 2 x 2 matrix representation, we introduce homogeneous coordinates to allow a 3 x 3 matrix representation.
- The Homogeneous coordinate corresponding to the point (x,y) is the triple (xh, yh, w) where: xh = wx yh = wyFor the two dimensional transformations we can set w = 1.

204481 Foundation of Computer Graphics

Matrix representation

204481 Foundation of Computer Graphics

Composite Transformation

Suppose we wished to perform multiple transformations on a point:

204481 Foundation of Computer Graphics

Example of Composite Transformation(1/3)

- A scaling transformation at an arbitrary angle is a combination of two rotations and a scaling:R(-t) S(Sx,Sy) R(t)
- A rotation about an arbitrary point (xf,yf) by and angle t anti-clockwise has matrix:T(-xf,-yf) R(t) T(xf,yf)

204481 Foundation of Computer Graphics

Example of Composite Transformation(2/3)

Reflection about the y-axis Reflection about the x-axis

204481 Foundation of Computer Graphics

Example of Composite Transformation(3/3)

Reflection about the origin Reflection about the line y=x

204481 Foundation of Computer Graphics

Basic 3D Transformations

- Translation
- Scale
- Rotation
- Shear
- As in 2D, we use homogeneous coordinates (x,y,z,w), so that transformations may be composited together via matrix multiplication.

204481 Foundation of Computer Graphics

3D Translation and Scaling

TP = (x + tx, y + ty, z + tz)

SP = (sxx, syy, szz)

204481 Foundation of Computer Graphics

3D Rotation (1/4)

Positive Rotations are defined as follows:

Axis of rotation isDirection of positive rotation is

x y to z

y z to x

z x to y

204481 Foundation of Computer Graphics

P2

Z

U

P1

c

u3

Y

a

ß

u2

b

u1

X

Rotation About An Arbitary Axis (1/3)- Translate one end of the axis to the origin
- Rotate about the y-axis and angle
- Rotate about the x-axis through an angle

204481 Foundation of Computer Graphics

P2

Z

Z

U

Z

a

c

U

u3

P1

c

u3

µ

Y

Y

a

Y

ß

a

ß

u2

u2

u2

b

b

X

u1

u1

X

X

Rotation About An Arbitary Axis (2/3)4. When U is aligned with the z-axis, apply the original rotation, R, about the z-axis.

5. Apply the inverses of the transformations in reverse order.

204481 Foundation of Computer Graphics

Rotation About An Arbitary Axis (3/3)

T-1 Ry(ß) Rx(-µ) R Rx(µ) Ry(-ß) T P

204481 Foundation of Computer Graphics

Download Presentation

Connecting to Server..