1 of 61

Computer Graphics

Dr.S.Sivakumar,Principal

C.P.A College, Bodinayakanur

*

1

2 of 61

Two-Dimensional Geometric Transformations�

3 of 61

Two-Dimensional Geometric Transformations

  • Basic Transformations
    • Translation
    • Rotation
    • Scaling
  • Composite Transformations
  • Other transformations
    • Reflection
    • Shear

4 of 61

Translation

Simply moves an object from one position to another

xnew = xold + dx ynew = yold + dy

Note: House shifts position relative to origin

y

x

0

1

1

2

2

3

4

5

6

7

8

9

10

3

4

5

6

4

5 of 61

Translation

  • Translation transformation

    • Translation vector or shift vector T = (tx, ty)
  • Rigid-body transformation
    • Moves objects without deformation

x

y

p

P’

T

x

y

T

6 of 61

Rotation

Rotates all coordinates by a specified angle

  • xnew = xold × cosθyold × sinθ
  • ynew = xold × sinθ + yold × cosθ

Points are always rotated about the origin

y

x

0

1

1

2

2

3

4

5

6

7

8

9

10

3

4

5

6

6

7 of 61

2-D Rotation

x = r cos (φ)

y = r sin (φ)

x’ = r cos (φ + θ)

y’ = r sin (φ + θ)

Trig Identity…

x’ = r cos(φ) cos(θ) – r sin(φ) sin(θ)

y’ = r sin(φ) sin(θ) + r cos(φ) cos(θ)

Substitute…

x’ = x cos(θ) - y sin(θ)

y’ = x sin(θ) + y cos(θ)

θ

(x, y)

(x’, y’)

φ

7

8 of 61

2-D Rotation

θ

(x, y)

(x’, y’)

x’ = x cos(θ) - y sin(θ)

y’ = x sin(θ) + y cos(θ)

8

9 of 61

2-D Rotation

This is easy to capture in matrix form:

Even though sin(θ) and cos(θ) are nonlinear functions of θ,

    • x’ is a linear combination of x and y
    • y’ is a linear combination of x and y

9

10 of 61

Rotation

  • Rotation transformation

x

y

P(x,y)

P’ (x’,y’)

r

θ Φ

x’=rcos(Φ+θ)= rcos Φ cos θ -rsin Φ sin θ

y’=rsin(Φ+θ)= rcos Φ sin θ+rsin Φ cos θ

x=rcos Φ y=rsin Φ

x’=x cos θ -ysin θ

y’=xsin θ +ycos θ

P’= R· P

11 of 61

Rotation

  • Pivot point

x

y

P(x,y)

P’ (x’,y’)

r

(xr,yr)

x’=xr+(x- xr)cos θ -(y- yr)sin θ

y’=yr+(x- xr)sin θ +(y- yr)cos θ

θ Φ

12 of 61

Scaling

Scalar multiplies all coordinates

WATCH OUT: Objects grow and move!

xnew = Sx × xold ynew = Sy × yold

Note: House shifts position relative to origin

y

x

0

1

1

2

2

3

4

5

6

7

8

9

10

3

4

5

6

12

13 of 61

Scaling

Scaling a coordinate means multiplying each of its components by a scalar

Uniform scaling means this scalar is the same for all components:

× 2

13

14 of 61

Scaling

Non-uniform scaling: different scalars per component:

How can we represent this in matrix form?

X × 2,�Y × 0.5

14

15 of 61

Scaling

Scaling operation:

Or, in matrix form:

scaling matrix

15

16 of 61

Scaling

  • Scaling transformation

    • Scaling factors, sx and sy
    • Uniform scaling

x

y

x

y

17 of 61

Scaling

  • Fixed point

18 of 61

Homogeneous Coordinates

Homogeneous coordinates

    • represent coordinates in 2 dimensions with a 3-vector

Homogeneous coordinates seem unintuitive, but they make graphics operations much easier

18

19 of 61

Homogeneous Coordinates?

Mathematicians commonly use homogeneous coordinates as they allow scaling factors to be removed from equations

The transformations we discussed previously can be represented as 3*3 matrices

Using homogeneous coordinates allows us use matrix multiplication to calculate transformations – extremely efficient!

19

20 of 61

Homogeneous Coordinates

  • A point (x, y) can be re-written in homogeneous coordinates as (xh, yh, h)

  • The homogeneous parameter h is a non-�zero value such that:

  • We can then write any point (x, y) as (hx, hy, h)

  • We can conveniently choose h = 1 so that �(x, y) becomes (x, y, 1)

20

21 of 61

Homogeneous Coordinates

  • Add a 3rd coordinate to every 2D point
    • (x, y, w) represents a point at location (x/w, y/w)
    • (x, y, 0) represents a point at infinity
    • (0, 0, 0) is not allowed

Convenient coordinate system to represent many useful transformations

1

2

1

2

(2,1,1)

or (4,2,2)

or (6,3,3)

x

y

21

22 of 61

Homogeneous Coordinates

Represent translation as a 3x3 matrix?

Using the rightmost column:

22

23 of 61

Translation

Example of Translation

  • α

tx = 2�ty = 1

Homogeneous Coordinates

23

24 of 61

Remember Matrix Multiplication

Recall how matrix multiplication takes place:

24

25 of 61

Homogeneous Translation

The translation of a point by (dx, dy) can be written in matrix form as:

Representing the point as a homogeneous column vector we perform the calculation as:

25

26 of 61

Homogenous Transformations

To make operations easier, 2-D points are written as homogenous coordinate column vectors

Translation:

Scaling:

Rotation:

26

27 of 61

Matrix Representations and Homogeneous Coordinates

  • Homogeneous Coordinates

  • Matrix representations
    • Translation

28 of 61

Matrix Representations

  • Matrix representations
    • Scaling

    • Rotation

29 of 61

Composite Transformations

  • Translations

30 of 61

Composite Transformations

  • Scaling

31 of 61

Composite Transformations

  • Rotations

32 of 61

Combining Transformations

A number of transformations can be combined into one matrix to make things easy

    • Allowed by the fact that we use homogenous coordinates

Rotating a polygon around a point other than the origin

    • Transform to centre point to origin
    • Rotate around origin
    • Transform back to centre point

32

33 of 61

Combining Transformations (cont.)

1

2

3

4

33

34 of 61

Combining Transformations (cont.)

The three transformation matrices are combined as follows

Remember: Matrix multiplication is not commutative

so order matters

34

35 of 61

Matrix Composition

Transformations can be combined by �matrix multiplication

p’ = T(tx,ty) R(Θ) S(sx,sy) p

35

36 of 61

Matrix Composition

  • Matrices are a convenient and efficient way to represent a sequence of transformations
    • General purpose representation
    • Hardware matrix multiply

p’ = (T * (R * (S*p) ) )

p’ = (T*R*S) * p

36

37 of 61

Matrix Composition

  • After correctly ordering the matrices
  • Multiply matrices together
  • What results is one matrix – store it (on stack)!
  • Multiply this matrix by the vector of each vertex
  • All vertices easily transformed with one matrix multiply

37

38 of 61

General Pivot-Point Rotation

  • Rotations about any selected pivot point (xr,yr)
    • Translate-rotate-translate

39 of 61

General Pivot-Point Rotation

40 of 61

General Fixed-Point Scaling

Scaling with respect to a selected fixed position (xf,yf)

41 of 61

General Fixed-Point Scaling

  • Translate-scale-translate

42 of 61

General Scaling Directions

  • Scaling factors sx and sy scale objects along the x and y directions.
  • We scale an object in other directions with scaling factors s1 and s2

43 of 61

General Scaling Directions

44 of 61

Concatenation Properties

  • Matrix multiplication is associative.

A·B ·C = (A·B )·C = A·(B ·C)

  • Transformation products may not be commutative
    • Be careful about the order in which the composite matrix is evaluated.
    • Except for some special cases:
      • Two successive rotations
      • Two successive translations
      • Two successive scalings
      • rotation and uniform scaling

45 of 61

Concatenation Properties

  • Reversing the order
    • A sequence of transformations is performed may affect the transformed position of an object.

46 of 61

General Composite Transformations and Computer Efficiency

  • A general two-dimensional transformation

    • Rotation-scaling terms rsij
    • Translational terms trsx and trsy
  • Minimum number of computations
    • Four multiplications
    • Four additions

47 of 61

Rigid-Body Transformation

  • Rigid-body transformation matrix

  • The upper-left 2-by-2 submatrix is an orthogonal matrix
    • Two vectors (rxx, rxy) and (ryx, ryy) form an orthogonal set of unit vectors.

    • Multiplicative rotation terms rij
    • Translational terms trx and try

48 of 61

Rigid-Body Transformation

  • The orthogonal property of rotation matrices
    • We know the final orientation of an object

Construct the desired transformation by assigning the elements of u’ to the first row of the rotation matrix and the elements of v’ to the second row.

49 of 61

Computational Efficiency

  • Use approximations and iterative calculations to reduce computations
    • Approximate the trigonometric functions based on the first few terms of their power-series expansions.
    • For small enough angles (< 100), cosθ is approximately 1.sinθ is approximately θ
    • Accumulated error control
      • Estimate the error in x’ and y’ at each step
      • Reset object positions when the error accumulation becomes too great

50 of 61

Reflection

  • A transformation produces a mirror image of an object.
  • Axis of reflection
    • A line in the xy plane
    • A line perpendicular to the xy plane
    • The mirror image is obtained by rotating the object 1800 about the reflection axis.
  • Rotation path
    • Axis in xy plane: in a plane perpendicular to the xy plane.
    • Axis perpendicular to xy plane: in the xy plane.

51 of 61

Reflection

  • Reflection about the x axis

52 of 61

Reflection

  • Reflection about the y axis

53 of 61

Reflection

  • Reflection relative to the coordinate origin

54 of 61

Reflection

  • Reflection of an object relative to an axis perpendicular to the xy plane through Prfl

55 of 61

Reflection

  • Reflection about the line y = x

56 of 61

Shear

  • The x-direction shear relative to x axis

If shx = 2:

57 of 61

Shear

  • The x-direction shear relative to y = yref

If shx = ½ yref = -1:

1

1/2

3/2

58 of 61

Shear

  • The y-direction shear relative to x = xref

If shy = ½ xref = -1:

1

1/2

3/2

59 of 61

Transformations between Coordinate Systems

x

y

y’

x’

x0

y0

θ

x

y

y’

x’

θ

60 of 61

Transformations between Coordinate Systems

Method 1:

Method 2:

61 of 61

Affine Transformations

  • A coordinate transformation of the form

x’=axxx+axyy+bx, y’=ayxx+ayyy+by

    • x’ and y’ is a linear function of the original coordinates x and y.
    • aij and bk are constants determined by the transformation type.
    • Translation, rotation, scaling, reflection, and shear are two-dimensional affine transformations.
    • An affine transformation involving only rotation, translation, and reflection preserves angles and lengths.