You are on page 1of 33

Computer Aided Design 2011

Unit No. 2 Computer Graphics II


Raster Scan Graphics: - The most common type of a computer output device capable of displaying graphical output is CRT(Cathode Ray Tube). Since CRT is raster display, it is a matrix of discrete cells of finite area called pixel. Thus each pixel on the graphics display represents a region and not a mathematical point. Rasterization: - The process of determining which pixel provides the best approximation to the desired point is known as rasterization. Line Drawing: - the line is drawn by illuminating the cells or pixels at an intensity level. Since d is a point plotting display hence it is not possible to draw a straight line from a addressable pointy expect in case of horizontal vertical and diagonal line. Functions used in graphic system: 1. Initgraph: - This function is used to initiate the graphics system and load the driver and mode used by the graphics system the syntax is initgraph (&driver,&mode,.\\bgi); 2. Detect graph : - This function detects the driover and the mode of the system the syntax is given by detectgraph(&driver,&mode); 3. Put pixel: - This function illuminates the pixerl represented by x and y coordinate in the given color the syntax is putpixel( x, y , red); 4. Close graph: - This function deallocates all the memory allocated by the graphic system. It restores the screen to the mode in which it was before the execution of the initgraph. The syntax is given by closegraph(); Pixel: It is the smallest element of the screen. A pixel is at rest or identified by its lower left corner. The pixel occupies a finite area to the right and above this point. The addressing start at zero , zero. By setting the intensity and color of a pixel a graphic image can be made.

Page 1

[Manish V. Sharma]

Computer Aided Design 2011


Line Drawing Algorithm: There are two basic type of line drawing algorithm or line generating algorithm 1. Digital Differential Analyser Algorithm(DDA) 2. Bresenhams Line Algorithm
Digital Diferential Analyser Algorithm

X1, Y1 - co-ordinates of the start point X2, Y2 - co-ordinates of the end point. Xi, Yi - coordinates of the ith point Xi+1, Yi+1-co-ordinates of the i+1th point on the line Calculate slope m= Y2-Y1 X2-X1 Equation of a line is given by Y=mX+c For ith pixel Yi=m Xi + c (1) For i+1th pixel Yi+1=m Xi+1 + c ...(2) Now subtracting (2)-(1), we get Yi+1- Yi= m (Xi+1 - Xi) ..(3) If m<1, X is incremented i.e. Xi+1=Xi+1 (4) Put (4) in (3), Therefore Yi+1-Yi=m (Xi+1-Xi) Yi+1=Yi+ m .(5) If m>1. Y is incremented i.e. Yi+1=Yi+1(6) Put (6) in (3), therefore Yi+1-Yi=m (Xi+1-Xi) 1/m=(Xi+1-Xi) Xi+1=Xi+1/m.(7)

Page 2

[Manish V. Sharma]

Computer Aided Design 2011


Algo to draw the line in the first quadrant Step No. 1:Declaration of the variables X1, Y1- co-ordinates of the start point X2, Y2- co-ordinates of the end point. X, Y- coordinates of the current point m- slope of the line Step No. 2:Calculation m= Y2-Y1 X2-X1 Step No. 3:Initialization X=X1 Y=Y1 Step No. 4:Plotting the points If (m<1) Loop (X<=X2) putpixel (X,Y) X=X+1 Y=Y+ m If (m>=1) Loop (Y<=Y2) putpixel (X,Y) Y=Y+1 X=X+1/m

Page 3

[Manish V. Sharma]

Computer Aided Design 2011

Page 4

[Manish V. Sharma]

Computer Aided Design 2011

Page 5

[Manish V. Sharma]

Computer Aided Design 2011

Page 6

[Manish V. Sharma]

Computer Aided Design 2011

Page 7

[Manish V. Sharma]

Computer Aided Design 2011

Page 8

[Manish V. Sharma]

Computer Aided Design 2011

Page 9

[Manish V. Sharma]

Computer Aided Design 2011

Page 10

[Manish V. Sharma]

Computer Aided Design 2011

Page 11

[Manish V. Sharma]

Computer Aided Design 2011


Bresenhams Line Algorithm for slope greater than One

Page 12

[Manish V. Sharma]

Computer Aided Design 2011

Page 13

[Manish V. Sharma]

Computer Aided Design 2011


Function to plot 8 symmetrical points for a calculated position Circlepoints( Xc,, Yc, X, Y) { Putpixel(Xc +X, Yc +Y); Putpixel(Xc +X, Yc -Y); Putpixel(Xc -X, Yc -Y); Putpixel(Xc -X, Yc +Y); Putpixel(Xc +Y, Yc +X); Putpixel(Xc +Y, Yc -X); Putpixel(Xc -Y, Yc -X) Putpixel(Xc -Y, Yc +X) End }

Page 14

[Manish V. Sharma]

Computer Aided Design 2011

Page 15

[Manish V. Sharma]

Computer Aided Design 2011

Page 16

[Manish V. Sharma]

Computer Aided Design 2011


Mid Point Algorithm for Circle Drawing Step. No. 1: Declaration of variables (X,Y) Coordinates of the current point (Xc, Yc) Coordinates of the Center P Decision Variable R Radius of the circle Step. No. 2: Calculations P=1-R Step No. 3: Initialization X=0 Y=R Step. No. 4: Plotting the Points Loop(XY) If (P<0) X=X+1 Y=Y P=P+2X+3 If( P>0) X=X+1 Y=Y-1 P=P+2X-2Y+5

Page 17

[Manish V. Sharma]

Computer Aided Design 2011

Page 18

[Manish V. Sharma]

Computer Aided Design 2011

Page 19

[Manish V. Sharma]

Computer Aided Design 2011

Page 20

[Manish V. Sharma]

Computer Aided Design 2011

Page 21

[Manish V. Sharma]

Computer Aided Design 2011

Page 22

[Manish V. Sharma]

Computer Aided Design 2011

Page 23

[Manish V. Sharma]

Computer Aided Design 2011

Page 24

[Manish V. Sharma]

Computer Aided Design 2011

Page 25

[Manish V. Sharma]

Computer Aided Design 2011

Page 26

[Manish V. Sharma]

Computer Aided Design 2011

Page 27

[Manish V. Sharma]

Computer Aided Design 2011

Page 28

[Manish V. Sharma]

Computer Aided Design 2011

Page 29

[Manish V. Sharma]

Computer Aided Design 2011

Page 30

[Manish V. Sharma]

Computer Aided Design 2011

Page 31

[Manish V. Sharma]

Computer Aided Design 2011

Page 32

[Manish V. Sharma]

Computer Aided Design 2011


Que. A pyramid is defined by the coordinate A(0,0,0) B(2,0,0) C(0,1,0) and D(0,0,1) is rotated by 450 about the line L that has the direction V=j+k and pass thru point C (0,1,0) find coordinate of rotated fig?

Page 33

[Manish V. Sharma]

You might also like