0% found this document useful (0 votes)
63 views4 pages

Computer Graphics Lab Assignment 2021

This document contains computer graphics lab assignments submitted by a student named Ritesh R. The first assignment explains the DDA algorithm for drawing 3D shapes by breaking lines into small segments. The code implements DDA to draw a polygon. The second assignment explains Bresenham's line algorithm for drawing lines in 3D, involving determining the driving axis and using error values to decide the next pixel along the line.

Uploaded by

Raghu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views4 pages

Computer Graphics Lab Assignment 2021

This document contains computer graphics lab assignments submitted by a student named Ritesh R. The first assignment explains the DDA algorithm for drawing 3D shapes by breaking lines into small segments. The code implements DDA to draw a polygon. The second assignment explains Bresenham's line algorithm for drawing lines in 3D, involving determining the driving axis and using error values to decide the next pixel along the line.

Uploaded by

Raghu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

AMRITA VISHWA VIDYAPEETAM -MYSURU

AMRITA SCHOOL OF AARTS AND SCIENCES 2020-21

COMPUTER GRAPHICS
LAB ASSIGNMENT : 01

SUBMITTED BY,

RITESH .R
MY.SC.U3BCA18006
BCA ‘C’ SEC
1.DDA ALGORITHM FOR 3D SHAPES?
#INCLUDE<STDIO.H>
#INCLUDE<GRAPHICS.H>
#INCLUDE<MATH.H>
#INCLUDE<CONIO.H>
VOID DRAW(INT X1, INT Y1, INT X2, INT Y2){
FLOAT XINCR,YINCR,DX,DY,X,Y;
INT STEPS,K;
DX=X2-X1;
DY=Y2-Y1;
IF(ABS(DX)>ABS(DY))
STEPS=ABS(DX);
ELSE
STEPS=ABS(DY);
XINCR=DX/STEPS;
YINCR=DY/STEPS;
X=X1;
Y=Y1;
FOR(K=1;K<=STEPS;K++){
DELAY(100);
X+=XINCR;
Y+=YINCR;
PUTPIXEL(X,Y,WHITE);
}
}

VOID MAIN(){
INT GD=DETECT,GM;
INT X[10],Y[10],SIDES,I;
PRINTF("ENTER THE SIDES OF POLYGUN");
SCANF("%D",&SIDES);
FOR(I=0;I<SIDES;I++){
PRINTF("ENTER X[%D], Y[%D]",I+1,I+1);
SCANF("%D%D",&X[I],&Y[I]);
}
INITGRAPH(&GD,&GM,"C:\\TURBOC3\\BGI");
FOR(I=0;I<SIDES;I++){
IF(I==(SIDES-1)){
DRAW(X[I],Y[I],X[0],Y[0]);
}
ELSE{
DRAW(X[I],Y[I],X[I+1],Y[I+1]);
}
}
GETCH();
CLOSEGRAPH();
}
OUTPUT:

2. BRESENHAMS LINE ALGORITHM FOR 3D IMAGES?


ALGORITHM:-
STEP1: START
STEP2: INPUT THE TWO ENDPOINTS AND STORE THE INITIAL POINT AS
(X_{0}, Y_{0}, Z_{0})
STEP3: PLOT (X_{0}, Y_{0}, Z_{0})
STEP4: CALCULATE CONSTANTS DX, DY, DZ AND DETERMINE THE DRIVING
AXIS BY COMPARING THE ABSOLUTE VALUES OF DX, DY, DZ
STEP5: IF ABS(DX) IS MAXIMUM, THEN X-AXIS IS THE DRIVING AXIS
STEP6: IF ABS(DY) IS MAXIMUM, THEN Y-AXIS IS THE DRIVING AXIS
STEP7 :IF ABS(DZ) IS MAXIMUM, THEN Z-AXIS IS THE DRIVING AXIS
LET’S SUPPOSE THAT X-AXIS IS THE DRIVING AXIS, THEN
STEP 8: PY_{0} = 2DY - DX\\ PZ_{0} = 2DZ - DX

STEP 9: AT EACH X_{K} ALONG THE LINE, STARTING AT K = 0, CHECK THE


FOLLOWING CONDITIONS
AND DETERMINE THE NEXT POINT:-
IF PY_{K} < 0 AND PZ_{K} < 0, THEN
PLOT (X_{K}+1, Y_{K}, Z_{K}) AND
SET PY_{K+1}=PY_{K}+2DY, PZ_{K+1}=PZ_{K}+2DZ
ELSE IF PY_{K} > 0 AND PZ_{K} < 0, THEN
PLOT (X_{K}+1, Y_{K}+1, Z_{K}) AND
SET PY_{K+1}=PY_{K}+2DY-2DX, PZ_{K+1}=PZ_{K}+2DZ
ELSE IF PY_{K} 0, THEN
PLOT (X_{K}+1, Y_{K}, Z_{K}+1) AND
SET PY_{K+1}=PY_{K}+2DY, PZ_{K+1}=PZ_{K}+2DZ-2DX
ELSE THEN
PLOT (X_{K}+1, Y_{K}+1, Z_{K}+1) AND
SET PY_{K+1}=PY_{K}+2DY-2DX, PZ_{K+1}=PZ_{K}+2DZ-2DX>
REPEAT STEP 5 DX-1 TIMES
END:

You might also like