+ All Categories
Home > Documents > 3.ComputerGraphics

3.ComputerGraphics

Date post: 03-Oct-2014
Category:
Upload: chakradhar-mangam
View: 159 times
Download: 2 times
Share this document with a friend
55
CAD/CAM Principles and Applications by P N Rao, 2 nd Ed 1 CAD/CAM Principles and Applications Ch 3 Computer Graphics
Transcript
Page 1: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

1

CAD/CAM Principles and Applications

Ch 3 Computer Graphics

Page 2: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

2

Objectives• Convert vector straight lines to raster images to be displayed on

a raster terminal utilizing the pixel information• Understand the problems associated with displaying vectorial

information on a raster terminal• Various types of coordinate systems used in displaying CAD

information• The data requirements of a graphic image and the database

storage methods used • Different types of geometric transformations used during CAD

geometry generation and display and their evaluation• Mathematics required to display a 3D image on the 2D screen of

the display device• Understand the problems associated with the display of graphic

images in the display screen such as clipping and hidden line elimination

Page 3: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

3

3.1 Raster Scan Graphics

• DDA or Digital Differential Analyser is one of the first algorithms developed for rasterising the vectorial information. The equation of a straight line is given by

• Y = m X + C

Page 4: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

4

Fig. 3.1 A straight line drawing

X

Y

x1x2

y1

y2

Page 5: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

5

Fig. 3.2 Flow chart for line drawing calculation procedure

Calculate dx = x2 - x1dy = y2 - y1

If |dx| > |dy| St = |dx|

dx = dx / STdy = dy / ST

X = xiY = yi

Set pixel at X, Y

End of Loop?

STOP

Yes

ST = |dy|

No

X = X + dxY = Y + dy

Yes

No

Page 6: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

6

3.1.2 Bresenham's Algorithm

• Bresenham's method is an improvement over DDA since it completely eliminates the floating-point arithmetic except for the initial computations.

• All other computations are fully integer arithmetic thus is more efficient for raster conversion

Page 7: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

7

Fig. 3-3 Line drawing using Bresenhamalgorithm

X

Y

i i+1

y d2

d1i

i+1

Page 8: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

8

Fig. 3.4 Flow chart for line drawing calculation using Bresenham

procedure

Calculate dx = x2 - x1dy = y2 - y1C1 = 2 dy

C2 = 2 (dy - dx)

x = x + 1

STOP

Put a pixel at (x1, y1)

P(i+1) = P(i) + C1y(i+1) = y(i)

x = x1y = y1

p1 = 2 dy - dx

If Pi < 0 P(i+1) = Pi + C2Y(i+1) = y(i) + 1No

Yes

No End of loop?

Yes

Page 9: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

9

3.1.3 Antialiasing lines

Page 10: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

10

Fig. 3.5 The staircase effect of pixels when

drawing inclined lines

Page 11: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

11

Fig. 3.6 The staircase effect of pixels when drawing

inclined lines decreases with increased resolution

Page 12: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

12

Fig. 3.7 Antialiasing of pixels proportional to

the portion of pixel occupied by the line

1

6

7

8

1

234

5

2 3 4 65 7 8

Page 13: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

13

Fig. 3.8 Unequal number of lines displayed

with the same number of pixels

Page 14: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

14

3.2 Co-ordinate systems

Page 15: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

15

Fig. 3.9 A typical component to be modelled

150

120

9050

60

2040

30

40

Page 16: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

16

World Co-ordinate System

• This refers to the actual co-ordinate system used as master for the component.

• Some times it may also be called as model co-ordinate system.

Page 17: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

17

Fig. 3.10 A typical component with its

associated WCS

X

Y

Z

Page 18: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

18

User Co-ordinate System

• However, sometimes it becomes difficult to define certain geometries if they are to be defined from the WCS. In such cases alternate co-ordinate systems can be defined relative to the WCS. These co-ordinate systems are termed as user co-ordinate systems (UCS) or working co-ordinate systems.

Page 19: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

19

Fig. 3.11 A typical component with its

associated UCS

X

Y

Z

X'

Y'

Z'

Page 20: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

20

Display Co-ordinates

• This refers to the actual co-ordinates to be used for displaying the image on the screen.

Page 21: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

21

Fig. 3.12 A typical component with its various

view positions

X

Y

Z

FRONT

TOP

RIGHT SIDE

Page 22: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

22

Fig. 3.13 Various views generated from the

model shown in Fig 3.12

150

120

90

50 60

30

60

20

20

40

TOP

FRONT RIGHT SIDE

XY

Z

X

Y

Z

XY

Z

Page 23: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

23

3.3 Database Structures for Graphic Modelling

Page 24: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

24

3.3 Database Structures for Graphic Modelling

• Organisational data• Identification number,• Drawing number,• Design origin and status

of changes,• Current status,• Designer name,• Date of design,• Scale,• Type of projections,• Company.

• Technological data• Geometry,• Dimensions,• Tolerances,• Surface finishes,• Material specifications

or reference,• Manufacturing

procedures,• Inspection procedures.

Page 25: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

25

Fig. 3.14 Data structure for geometric modelsSOLID

EDGE

VERTEX

SURFACE

VERTEX SURFACE

Page 26: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

26

Fig. 3.15 Complete data structure for

geometric models of productsProduct

Assembly

Single parts

Solid body

Faces

Edges

Vertices

Dimensions Attributes

Page 27: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

27

Fig. 3.16 Relational data structure for

geometric models

solid body Face list Edges Vertices

X Y Z

Page 28: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

28

3.4 Transformation of Geometry

• Translation• Scaling• Reflection or Mirror• Rotation

Page 29: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

29

Fig. 3-17 Some of the possible geometric

transformations

X

Y

Y

X

Y

X

Y

X

dX

dYTranslation Scaling

ReflectionRotation

30°

2525

Page 30: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

30

Fig. 3.18 Translation of geometry

X

Y

Z

X'

Y'

Z'

P

P*

X

Y P

Page 31: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

31

Fig. 3.19 Translation of geometry in 2D

X

Y

X'

Y'

P

P*

dX

dY

Page 32: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

32

Fig. 3.20 Scaling of geometry in 2D

X

Y

P

P*

X

sX

Y

sY

Page 33: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

33

Fig. 3.21 Reflection of geometry in 2DY

X25

25

Y

X

Y

X

28 28

-X

-Y

-X

Page 34: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

34

Fig. 3.22 Example for reflection transformation

X

Y

P

P*

y-y

Page 35: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

35

Fig. 3-23 Example for rotation transformation

X

Y

P

P*

PPr

O

α

x*x

yy*

θ

Page 36: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

36

Fig. 3.24 Example

10

8.6613

.66

5

3.66

8.66

30°

5

X

Y

Page 37: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

37

3.4.5 Concatenation of transformations

• [P*] = [Tn] [Tn-1] [Tn-2] .. [T3] [T2] [T1]

Page 38: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

38

3.4.6 Homogeneous Representation

[ ]

=

=

11001001

1**

* yx

dYdX

yx

P

Page 39: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

39

Rotation about an arbitrary point

• Translate the point P to O, the origin of the axes system.

• Rotate the object by the given angle• Translate the point back to its original

position.

Page 40: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

40

Fig. 3.25 Rotation about an arbitrary point

X

Y

P

P*

PPr

O

A

r θ

dX

dY

Page 41: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

41

Reflection about an arbitrary line

• Translate the mirror line along the Y-axis such that the line passes through the origin, O

• Rotate the mirror line such that it coincides with the X-axis.

• Mirror the object through the X-axis.• Rotate the mirror line back to the original

angle with X-axis.• Translate the mirror line along the Y-axis

back to the original position.

Page 42: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

42

Fig. 3.26 Example for reflection transformation

about an arbitrary line

X

Y

P*

P

O

C

θ

Page 43: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

43

3.5 3D Transformations

=

11000100010001

1***

zyx

dZdYdX

zyx

Page 44: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

44

3.6 Mathematics of Projection

Page 45: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

45

Fig. 3.27 The principle of projection

Object

Projecting plane

Projector

Drawing

Page 46: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

46

Fig. 3.28 An object enclosed in a cube to

obtain various parallel projections

A

B

C

D

E

Z

X

Y

Page 47: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

47

Fig. 3.29 Orthographic projection of an object

A

B

C

D

E

BOTTOM VIEW

FRONT VIEW RIGHT SIDE VIEWLEFT SIDE VIEW

TOP VIEW

REAR VIEW

A

B

CD E

Z

X

Y

X Y

Y

X

ZZ

Page 48: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

48

3.7 Clipping

Page 49: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

49

Fig. 3.30 Clipping of geometry for display

T

RL

B

Page 50: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

50

Fig. 3.31 The 4-digit coding of the line end

points for clipping

1001 1000 1010

0001 0000 0010

0101 0100 0110

Page 51: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

51

Fig. 3.32 Identical line clipping of two different

geometries

Page 52: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

52

Fig. 3.33 Clipping produced for different

geometries by polygon clipping

Page 53: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

53

Fig. 3.34 Back-face removal using the face

normal and projecting ray

X

Y

Z

PN

Page 54: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

54

Summary• In order to display the graphical information, which is vectorial in

nature, it is necessary to convert it into raster format.• For converting lines into raster format, DDA algorithm is

simplest while Bresenham’s algorithm reduces the computations into integer format thereby making it a faster alternative.

• It is necessary to modify the pixel information for display to get more realistic visual experience.

• Depending upon the type of graphic display used, it is necessary to be familiar with a number of different coordinate systems to facilitate the graphic construction as well as display.

• In addition to the actual graphic information, a large amount ofadditional data such as organizational and technological data isstored with the product data.

Page 55: 3.ComputerGraphics

CAD/CAM Principles and Applications by P N Rao, 2nd Ed

55

Summary• Geometric transformations can be handled conveniently using

matrix algebra. For this purpose it is necessary to use homogenous representation of vertex data.

• Various transformations that are quite useful are translation, rotation, scale and reflection. The 2D transformation methods can be easily extended into 3D.

• The 3D geometry data needs to be converted into 2D by adopting a suitable projection system such as orthographic, isometric or perspective projection.

• Since only part of the geometric model will be displayed most ofthe time, it is necessary to clip the information outside the display window.

• Also it is necessary some times to remove the hidden lines to make the display easier to understand. For this purpose back face removal and depth buffer (Z) are used.


Recommended