1 of 72

Computer graphics �subject code(22318)

BY A.I.MUSHRIF

2 of 72

Syllabus

Sr.no

Name of topics

Unit 1

Basics of computer graphics

Unit 2

Raster scan Graphics

Unit 3

Overview of Transformations

Unit 4

Windowing and clipping

Unit 5

Introduction to curves

3 of 72

Weightage of marks

Sr.no

Topics

Marks

1

Basics of computer Graphics

08

2

Raster Scan Graphics

18

3

Overview of Transformations

18

4

Windowing and clipping

14

5

Introductions to Curves

12

Total

70

4 of 72

Computer Graphics:�Overview of�Transformations

4

5 of 72

2D Transformations

5

x

y

x

y

x

y

6 of 72

2D Transformations

6

x

y

x

y

x

y

OpenGl transformations:

glTranslatef (tx, ty, tz);

glRotatef (theta, vx, vy, vz)

glScalef (sx,sy,sz)

……

7 of 72

2D Transformations

7

x

y

x

y

x

y

Applications:

  • Animation
  • Image/object manipulation
  • Viewing transformation
  • etc.

8 of 72

Applications of 2D Transformations

  • 2D geometric transformations

  • Animation (demo ,demo)

  • Image warping

  • Image morphing

9 of 72

2D Transformation

  • Given a 2D object, transformation is to change the object’s
    • Position (translation)
    • Size (scaling)
    • Orientation (rotation)
    • Shapes (shear)
  • Apply a sequence of matrix multiplications to the object vertices

9

10 of 72

Point Representation

  • We can use a column vector (a 2x1 matrix) to represent a 2D point x

y

  • A general form of linear transformation can be written as:

x’ = ax + by + c

OR

y’ = dx + ey + f

10

X’ a b c x

Y’ = d e f * y

1 0 0 1 1

11 of 72

Translation

  • Re-position a point along a straight line
  • Given a point (x,y), and the translation distance (tx,ty)

11

The new point: (x’, y’)

x’ = x + tx

y’ = y + ty

(x,y)

(x’,y’)

OR P’ = P + T where P’ = x’ p = x T = tx

y’ y ty

tx

ty

12 of 72

3x3 2D Translation Matrix

12

x’ = x + tx

y’ y ty

Use 3 x 1 vector

x’ 1 0 tx x

y’ = 0 1 ty * y

1 0 0 1 1

  • Note that now it becomes a matrix-vector multiplication

13 of 72

Translation

  • How to translate an object with multiple vertices?

13

Translate individual

vertices

14 of 72

2D Rotation

  • Default rotation center: Origin (0,0)

14

θ

  • > 0 : Rotate counter clockwise
  • < 0 : Rotate clockwise

θ

x

y

o

x

y

o

15 of 72

2D Rotation

15

(x,y)

(x’,y’)

θ

(x,y) -> Rotate about the origin by θ

(x’, y’)

How to compute (x’, y’) ?

φ

r

16 of 72

2D Rotation

16

(x,y)

(x’,y’)

θ

(x,y) -> Rotate about the origin by θ

(x’, y’)

How to compute (x’, y’) ?

φ

x = r cos (φ) y = r sin (φ)

r

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

x

y

o

17 of 72

2D Rotation

17

(x,y)

(x’,y’)

θ

φ

r

x = r cos (φ) y = r sin (φ)

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

x’ = r cos (φ + θ)

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

= x cos(θ) – y sin(θ)

y’ = r sin (φ + θ)

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

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

18 of 72

2D Rotation

18

(x,y)

(x’,y’)

θ

φ

r

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

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

Matrix form?

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

y’ sin(θ) cos(θ) y

=

3 x 3?

19 of 72

3x3 2D Rotation Matrix

19

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

y’ sin(θ) cos(θ) y

=

(x,y)

(x’,y’)

θ

φ

r

x’ cos(θ) -sin(θ) 0 x

y’ sin(θ) cos(θ) 0 y

1 0 0 1 1

=

20 of 72

20

  • How to rotate an object with multiple vertices?

Rotate individual

Vertices

θ

2D Rotation

21 of 72

2D Scaling

21

Scale: Alter the size of an object by a scaling factor

(Sx, Sy), i.e.

x’ = x . Sx

y’ = y . Sy

x’ Sx 0 x

y’ 0 Sy y

=

(1,1)

(2,2)

Sx = 2, Sy = 2

(2,2)

(4,4)

22 of 72

2D Scaling

22

(1,1)

(2,2)

Sx = 2, Sy = 2

(2,2)

(4,4)

  • Not only the object size is changed, it also moved!!
  • Usually this is an undesirable effect
  • We will discuss later (soon) how to fix it

23 of 72

3x3 2D Scaling Matrix

23

x’ Sx 0 x

y’ 0 Sy y

=

x’ Sx 0 0 x

y’ = 0 Sy 0 * y

1 0 0 1 1

24 of 72

Put it all together

  • Translation:

  • Rotation:

  • Scaling:

24

25 of 72

Or, 3x3 Matrix Representations

  • Translation:

  • Rotation:

  • Scaling:

25

x’ 1 0 tx x

y’ = 0 1 ty * y

1 0 0 1 1

x’ cos(θ) -sin(θ) 0 x

y’ sin(θ) cos(θ) 0 * y

1 0 0 1 1

=

x’ Sx 0 0 x

y’ = 0 Sy 0 * y

1 0 0 1 1

Why use 3x3 matrices?

26 of 72

Why Use 3x3 Matrices?

  • So that we can perform all transformations using matrix/vector multiplications

  • This allows us to pre-multiply all the matrices together

  • The point (x,y) needs to be represented as

(x,y,1) -> this is called Homogeneous

coordinates!

  • How to represent a vector (vx,vy)?

26

27 of 72

Why Use 3x3 Matrices?

  • So that we can perform all transformations using matrix/vector multiplications

  • This allows us to pre-multiply all the matrices together

  • The point (x,y) needs to be represented as

(x,y,1) -> this is called Homogeneous

coordinates!

  • How to represent a vector (vx,vy)? (vx,vy,0)

27

28 of 72

Shearing

  • Y coordinates are unaffected, but x coordinates are translated linearly with y
  • That is:
    • y’ = y
    • x’ = x + y * h

28

x 1 h 0 x

y = 0 1 0 * y

1 0 0 1 1

29 of 72

29

x 1 0 0 x

y = g 1 0 * y

1 0 0 1 1

Shearing in Y

30 of 72

Reflection

30

31 of 72

Reflection

31

32 of 72

Reflection

32

33 of 72

Reflection about X-axis

33

34 of 72

Reflection about X-axis

34

x 1 0 0 x

y = 0 -1 0 * y

1 0 0 1 1

35 of 72

Reflection about Y-axis

35

36 of 72

Reflection about Y-axis

36

x -1 0 0 x

y = 0 1 0 * y

1 0 0 1 1

37 of 72

What’s the Transformation Matrix?

37

38 of 72

What’s the Transformation Matrix?

38

x -1 0 0 x

y = 0 -1 0 * y

1 0 0 1 1

39 of 72

39

  • The standard rotation matrix is used to rotate about the origin (0,0)

cos(θ) -sin(θ) 0

sin(θ) cos(θ) 0

0 0 1

  • What if I want to rotate about an arbitrary center?

Rotation Revisit

40 of 72

Arbitrary Rotation Center

  • To rotate about an arbitrary point P (px,py) by θ:

40

(px,py)

41 of 72

Arbitrary Rotation Center

  • To rotate about an arbitrary point P (px,py) by θ:
    • Translate the object so that P will coincide with the origin: T(-px, -py)

41

(px,py)

42 of 72

Arbitrary Rotation Center

  • To rotate about an arbitrary point P (px,py) by θ:
    • Translate the object so that P will coincide with the origin: T(-px, -py)
    • Rotate the object: R(θ)

42

(px,py)

43 of 72

Arbitrary Rotation Center

  • To rotate about an arbitrary point P (px,py) by θ:
    • Translate the object so that P will coincide with the origin: T(-px, -py)
    • Rotate the object: R(θ)
    • Translate the object back: T(px,py)

43

(px,py)

44 of 72

44

    • Translate the object so that P will coincide with the origin: T(-px, -py)
    • Rotate the object: R(θ)
    • Translate the object back: T(px,py)

  • Put in matrix form: T(px,py) R(θ) T(-px, -py) * P

x’ 1 0 px cos(θ) -sin(θ) 0 1 0 -px x

y’ = 0 1 py sin(θ) cos(θ) 0 0 1 -py y

1 0 0 1 0 0 1 0 0 1 1

Arbitrary Rotation Center

45 of 72

45

Arbitrary Rotation Center

46 of 72

46

47 of 72

47

48 of 72

48

Example of arbitrary rotation

49 of 72

49

Example of arbitrary rotation

50 of 72

50

Example of arbitrary rotation

51 of 72

51

Projections

PROJECTION METHODS

1. Parallel Projection

2.Perspective Projection

52 of 72

52

Types of projections

1.Parallel projection

2.Perspective projection

Parallel projection

parallel projection is a projection of an object in three-dimensional space onto a fixed plane, known as the projection plane or image plane, where the rays, known as lines of sight or projection lines, are parallel to each other.

Projections

53 of 72

53

Parallel Projection

54 of 72

54

Parallel Projections

Types of parallel projection

  • Orthographic projection
  • Oblique projection

55 of 72

55

Parallel Projections

Types of parallel projection

  • Orthographic projection

The projection of a single view of an object (such as a view of the front) onto a projection plane in which the lines of projection are perpendicular to the projection plane.

when the projection is perpendicular to the view plane. In short,

– direction of projection = normal to the projection plane.

– the projection is perpendicular to the view plane

56 of 72

56

Parallel Projections

Types of parallel projection

  • Orthographic projection
  • Isometric Projection: All projectors make equal angles generally angle is of 30°.
  • Diametric: In these two projectors have equal angles. With respect to two principle axis.
  • Trimetric: The direction of projection makes unequal angle with their principle axis.

57 of 72

57

Orthographic Projections

58 of 72

58

Parallel Projections

Oblique projection

when the projection is not perpendicular to the view plane. In short,

  • Direction of projection is not normal to the projection plane.
  • Not perpendicular.

.

59 of 72

59

Parallel Projections

Oblique projection

Cavalier: All lines perpendicular to the projection plane are projected with no change in length.

Cabinet: All lines perpendicular to the projection plane are projected to one half of their length. These give a realistic appearance of object.

.

60 of 72

60

Parallel Projections

Oblique projection

Cavalier: All lines perpendicular to the projection plane are projected with no change in length.

.

61 of 72

61

Parallel Projections

Oblique projection

Cabinet: All lines perpendicular to the projection plane are projected to one half of their length. These give a realistic appearance of object.

.

62 of 72

62

Parallel Projections

.

Fig orthographic projection

Fig Oblique projection

63 of 72

63

  • Perspective projection 

It is a type of drawing that graphically approximates on a planar (two-dimensional) surface (e.g. paper) the images of three-dimensional objects so as to approximate actual visual perception. It is sometimes also called perspective view or perspective drawing or simply perspective

Perspective projection

The object position are transformed to the view plane along lines that converge to a point called projection reference point or (center of projection)

Projections

64 of 72

64

Perspective Projections

65 of 72

65

Characteristics of perspective projection:

  • Center of Projection (CP) is a finite distance from object
  • Projectors are rays (i.e., non-parallel)
  • Vanishing points: The projection lines appear to converge on a vanishing point.
  • Objects appear smaller as distance from CP (eye of observer) increases
  • Difficult to determine exact size and shape of object
  • Most realistic, difficult to execute

Perspective Projections

66 of 72

66

Perspective Projections

Types of perspective projection

  • One-Point Perspective:
  • Two-Point Perspective
  • Three-Point Perspective

67 of 72

67

Perspective Projections

Types of perspective projection

  • One-Point Perspective:
  • The projection is one-point perspective when it contains only one vanishing point on the horizon line.
  • This type of perspective is typically used for images of roads, railway tracks, hallways, or buildings viewed so that the front is directly facing the viewer.
  • These parallel lines converge at the vanishing point.

68 of 72

68

Perspective Projections

Fig : One point Perspective

69 of 72

69

Perspective Projections

  • Two-Point Perspective:
  • Two point of perspective is seen when there are two vanishing point from observers point of view .
  • Two-point perspective drawings are often used in architectural drawings and interior designs; they can be used for drawings of both interiors and exteriors.

70 of 72

70

Perspective Projections

Fig : Two point Perspective

71 of 72

71

Perspective Projections

  • Three-Point Perspective:
  • Three point of perspective is seen when there are three vanishing point from observers point of view .
  • Three-point perspective drawings are often used in building drawings

72 of 72

72

Perspective Projections

Fig : Three point Perspective