Ch 3 Computer Graphics

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

1

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
CAD/CAM Principles and Applications by P N Rao, 2nd Ed 2

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

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

3

Fig. 3.1 A straight line drawing

Y

y2 y1

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

X
4

Fig. 3.2 Flow chart for line drawing calculation procedure

Calculate dx = x2 - x1 dy = y2 - y1

If |dx| > |dy| No ST = |dy|

Yes

St = |dx|

dx = dx / ST dy = dy / ST X = xi Y = yi Set pixel at X, Y X = X + dx Y = Y + dy

End of Loop? No Yes STOP

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

5

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 CAD/CAM Principles and Applications by P N Rao. 2nd Ed 6 .3.1.

2nd Ed . 3-3 Line drawing using Bresenham algorithm Y i+1 y i i i+1 d2 d1 X 7 CAD/CAM Principles and Applications by P N Rao.Fig.

3.dx) x = x1 y = y1 p1 = 2 dy .dx Put a pixel at (x1.y1 C1 = 2 dy C2 = 2 (dy .4 Flow chart for line drawing calculation using Bresenham procedure Calculate dx = x2 .x1 dy = y2 . y1) x=x+1 If Pi < 0 No P(i+1) = Pi + C2 Y(i+1) = y(i) + 1 Yes P(i+1) = P(i) + C1 y(i+1) = y(i) No End of loop? Yes STOP CAD/CAM Principles and Applications by P N Rao.Fig. 2nd Ed 8 .

2nd Ed 9 .3.3 Antialiasing lines CAD/CAM Principles and Applications by P N Rao.1.

5 The staircase effect of pixels when drawing inclined lines CAD/CAM Principles and Applications by P N Rao. 2nd Ed 10 . 3.Fig.

3. 2nd Ed 11 .6 The staircase effect of pixels when drawing inclined lines decreases with increased resolution CAD/CAM Principles and Applications by P N Rao.Fig.

2nd Ed 12 . 3.7 Antialiasing of pixels proportional to the portion of pixel occupied by the line 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 CAD/CAM Principles and Applications by P N Rao.Fig.

8 Unequal number of lines displayed with the same number of pixels CAD/CAM Principles and Applications by P N Rao. 2nd Ed 13 .Fig. 3.

3. 2nd Ed 14 .2 Co-ordinate systems CAD/CAM Principles and Applications by P N Rao.

2nd Ed 30 15 . 3.9 A typical component to be modelled 50 90 60 120 40 40 20 15 0 CAD/CAM Principles and Applications by P N Rao.Fig.

• Some times it may also be called as model co-ordinate system. 2nd Ed 16 . CAD/CAM Principles and Applications by P N Rao.World Co-ordinate System • This refers to the actual co-ordinate system used as master for the component.

2nd Ed 17 . 3.Fig.10 A typical component with its associated WCS Z Y X CAD/CAM Principles and Applications by P N Rao.

CAD/CAM Principles and Applications by P N Rao.User Co-ordinate System • However. 2nd Ed 18 . 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.

Fig. 3.11 A typical component with its associated UCS Z' Z Y X' X Y' CAD/CAM Principles and Applications by P N Rao. 2nd Ed 19 .

2nd Ed 20 . CAD/CAM Principles and Applications by P N Rao.Display Co-ordinates • This refers to the actual co-ordinates to be used for displaying the image on the screen.

3.Fig. 2nd Ed 21 RIGHT SIDE .12 A typical component with its various view positions TOP Z Y FRONT X CAD/CAM Principles and Applications by P N Rao.

3. 2nd Ed 20 22 .Fig.12 60 90 20 Y X Z 50 TOP 60 120 X Y 30 Z 150 40 Z Y X RIGHT SIDE FRONT CAD/CAM Principles and Applications by P N Rao.13 Various views generated from the model shown in Fig 3.

3. 2nd Ed 23 .3 Database Structures for Graphic Modelling CAD/CAM Principles and Applications by P N Rao.

Surface finishes. Company. Dimensions. Current status. Designer name. 24 CAD/CAM Principles and Applications by P N Rao. • • • • • • Technological data Geometry. Design origin and status of changes.3. • Inspection procedures. Drawing number. Date of design. 2nd Ed . Tolerances. Type of projections. Material specifications or reference. Scale.3 Database Structures for Graphic Modelling • • • • • • • • • • Organisational data Identification number. • Manufacturing procedures.

Fig.14 Data structure for geometric models SOLID EDGE VERTEX VERTEX SURFACE SURFACE CAD/CAM Principles and Applications by P N Rao. 3. 2nd Ed 25 .

3. 2nd Ed 26 .15 Complete data structure for geometric models of products Product Assembly Dimensions Single parts Attributes Solid body Faces Edges Vertices CAD/CAM Principles and Applications by P N Rao.Fig.

2nd Ed 27 .16 Relational data structure for geometric models solid body Face list Edges X Vertices Y Z CAD/CAM Principles and Applications by P N Rao. 3.Fig.

3.4 Transformation of Geometry • • • • Translation Scaling Reflection or Mirror Rotation CAD/CAM Principles and Applications by P N Rao. 2nd Ed 28 .

Fig. 3-17 Some of the possible geometric transformations Y Y dX dY Y Translation X X Scaling Y 25 ° 30 X 25 X Rotation Reflection CAD/CAM Principles and Applications by P N Rao. 2nd Ed 29 .

2nd Ed 30 .18 Translation of geometry Y Y' Z' P P* X' Z P Y X X CAD/CAM Principles and Applications by P N Rao. 3.Fig.

2nd Ed 31 .Fig. 3.19 Translation of geometry in 2D Y Y' dY P* P X' dX X CAD/CAM Principles and Applications by P N Rao.

3. 2nd Ed 32 .Fig.20 Scaling of geometry in 2D Y P* sY P Y X sX X CAD/CAM Principles and Applications by P N Rao.

3.Fig.21 Reflection of geometry in 2D Y Y 28 25 28 X 25 -X X Y -X X -Y CAD/CAM Principles and Applications by P N Rao. 2nd Ed 33 .

Fig. 2nd Ed 34 .22 Example for reflection transformation Y P y X P* -y CAD/CAM Principles and Applications by P N Rao. 3.

Fig. 2nd Ed . 3-23 Example for rotation transformation Y P* y* P r y θ x* α X x 35 O CAD/CAM Principles and Applications by P N Rao.

66 5 10 30° 3.Fig. 3. 2nd Ed 36 .66 8.24 Example Y 13.66 5 8.66 X CAD/CAM Principles and Applications by P N Rao.

3.5 Concatenation of transformations • [P*] = [Tn] [Tn-1] [Tn-2] . 2nd Ed 37 .4.. [T3] [T2] [T1] CAD/CAM Principles and Applications by P N Rao.

3.4.6 Homogeneous Representation  x * 1 0 dX   x   y * = 0 1 dY   y  [P *] =       1  0 0 1   1       CAD/CAM Principles and Applications by P N Rao. 2nd Ed 38 .

2nd Ed 39 . • Rotate the object by the given angle • Translate the point back to its original position. CAD/CAM Principles and Applications by P N Rao.Rotation about an arbitrary point • Translate the point P to O. the origin of the axes system.

3.Fig. 2nd Ed 40 .25 Rotation about an arbitrary point Y P* r A dY P r θ O X dX CAD/CAM Principles and Applications by P N Rao.

• Translate the mirror line along the Y-axis back to the original position. 2nd Ed 41 . O • Rotate the mirror line such that it coincides with the X-axis. • Mirror the object through the X-axis.Reflection about an arbitrary line • Translate the mirror line along the Y-axis such that the line passes through the origin. • Rotate the mirror line back to the original angle with X-axis. CAD/CAM Principles and Applications by P N Rao.

Fig.26 Example for reflection transformation about an arbitrary line Y P* P θ C O CAD/CAM Principles and Applications by P N Rao. 3. 2nd Ed X 42 .

3. 2nd Ed 43 .5 3D Transformations  x * 1  y * 0  =  z *  0     1  0 0 0 dX   1 0 dY  0 1 dZ   0 0 1   x  y   z   1 CAD/CAM Principles and Applications by P N Rao.

2nd Ed 44 .6 Mathematics of Projection CAD/CAM Principles and Applications by P N Rao.3.

27 The principle of projection Projector Drawing Object Projecting plane CAD/CAM Principles and Applications by P N Rao. 2nd Ed 45 . 3.Fig.

28 An object enclosed in a cube to obtain various parallel projections B E Z C Y X A D CAD/CAM Principles and Applications by P N Rao. 3. 2nd Ed 46 .Fig.

2nd Ed 47 .Fig. 3.29 Orthographic projection of an object B E B C Y D X A D LEFT SIDE VIEW FRONT VIEW Z A X TOP VIEW X Z C E Y Z Y RIGHT SIDE VIEW REAR VIEW BOTTOM VIEW CAD/CAM Principles and Applications by P N Rao.

7 Clipping CAD/CAM Principles and Applications by P N Rao.3. 2nd Ed 48 .

2nd Ed 49 .30 Clipping of geometry for display T L R B CAD/CAM Principles and Applications by P N Rao. 3.Fig.

Fig.31 The 4-digit coding of the line end points for clipping 1001 0001 0101 1000 0000 0100 1010 0010 0110 50 CAD/CAM Principles and Applications by P N Rao. 2nd Ed . 3.

32 Identical line clipping of two different geometries CAD/CAM Principles and Applications by P N Rao. 3.Fig. 2nd Ed 51 .

3. 2nd Ed 52 .33 Clipping produced for different geometries by polygon clipping CAD/CAM Principles and Applications by P N Rao.Fig.

34 Back-face removal using the face normal and projecting ray Z Y P X CAD/CAM Principles and Applications by P N Rao.Fig. 3. 2nd Ed N 53 .

which is vectorial in nature. Depending upon the type of graphic display used. 2nd Ed 54 . it is necessary to be familiar with a number of different coordinate systems to facilitate the graphic construction as well as display. it is necessary to convert it into raster format. DDA algorithm is simplest while Bresenham’s algorithm reduces the computations into integer format thereby making it a faster alternative. In addition to the actual graphic information. a large amount of additional data such as organizational and technological data is stored with the product data. It is necessary to modify the pixel information for display to get more realistic visual experience. CAD/CAM Principles and Applications by P N Rao.Summary • • • • • In order to display the graphical information. For converting lines into raster format.

rotation.Summary • • • • • Geometric transformations can be handled conveniently using matrix algebra. The 3D geometry data needs to be converted into 2D by adopting a suitable projection system such as orthographic. isometric or perspective projection. Also it is necessary some times to remove the hidden lines to make the display easier to understand. Various transformations that are quite useful are translation. 2nd Ed 55 . it is necessary to clip the information outside the display window. Since only part of the geometric model will be displayed most of the time. CAD/CAM Principles and Applications by P N Rao. For this purpose back face removal and depth buffer (Z) are used. For this purpose it is necessary to use homogenous representation of vertex data. The 2D transformation methods can be easily extended into 3D. scale and reflection.