Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Bresenham's Circle and Line Drawing Algorithms - Prof. Singh, Exercises of Computer Graphics

A detailed overview of the bresenham's circle and line drawing algorithms, which are widely used in computer graphics for efficiently generating circles and lines on a raster display. The step-by-step implementation of these algorithms, including the mathematical principles behind them, the key variables and calculations involved, and the output generation process. It also highlights the advantages of bresenham's algorithms over other methods, such as their faster execution and higher accuracy. The learning outcomes section further emphasizes the key takeaways, such as the use of integer arithmetic, the ability to draw more accurate circles and curves, and the overall efficiency of these algorithms compared to alternatives like the digital differential analyzer (dda) algorithm. The document serves as a comprehensive resource for students and professionals interested in understanding and implementing these fundamental computer graphics techniques.

Typology: Exercises

2022/2023

Uploaded on 10/22/2022

mridul-dashora
mridul-dashora 🇮🇳

2 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MRIDUL DASHORA
20BCA1482
20BCA1482_MRIDUL DASHORA_Practical-4
Student Name:MRIDUL DASHORA UID: 20BCA1482
Branch: BCA Section/Group: 20BCA5_A
Semester: 5th DateofPerformance: 10.09.2022
Subject Name:COMPUTER GRAPHICS LAB Subject Code:20CAP316_B
A. Task to be done:
Summary of your previous attempts
B. Steps of Experiment
Declare p, q, x, y, r, d variables
& & & & p, q are coordinates of the center of the circle
& & & & r is the radius of the circle
Enter the value of r
&Calculate d = 3 - 2r
Initialize & & & x=0
& & & & & &nbsy= r
&Check if the whole circle is scan converted
& & & & & & If x > = y
& & & & & & Stop
Plot eight points by using concepts of eight-way symmetry. The center is at (p, q).
Current active pixel is (x, y).
& & & & & & & & putpixel (x+p, y+q)
& & & & & & & & putpixel (y+p, x+q)
& & & & & & & & putpixel (-y+p, x+q)
& & & & & & & & putpixel (-x+p, y+q)
& & & & & & & & putpixel (-x+p, -y+q)
& & & & & & & & putpixel (-y+p, -x+q)
& & & & & & & & putpixel (y+p, -x+q)
& & & & & & & & putpixel (x+p, -y-q)
Find location of next pixels to be scanned
& & & & & & If d < 0
& & & & & & then d = d + 4x + 6
& & & & & & increment x = x + 1
& & & & & & If d ≥ 0
& & & & & & then d = d + 4 (x - y) + 10
& & & & & & increment x = x + 1
& & & & & & decrement y = y – 1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Bresenham's Circle and Line Drawing Algorithms - Prof. Singh and more Exercises Computer Graphics in PDF only on Docsity!

MRIDUL DASHORA

20BCA

20BCA1482_MRIDUL DASHORA_Practical-

Student Name: MRIDUL DASHORA UID: 20BCA

Branch: BCA Section/Group: 20BCA5_A

Semester: 5th DateofPerformance: 10.09.

Subject Name: COMPUTER GRAPHICS LAB Subject Code: 20CAP316_B

A. Task to be done:

Summary of your previous attempts

B. Steps of Experiment

 Declare p, q, x, y, r, d variables p, q are coordinates of the center of the circle r is the radius of the circle  Enter the value of r  Calculate d = 3 - 2r  Initialize x= &nbsy= r  Check if the whole circle is scan converted If x > = y Stop  Plot eight points by using concepts of eight-way symmetry. The center is at (p, q). Current active pixel is (x, y). putpixel (x+p, y+q) putpixel (y+p, x+q) putpixel (-y+p, x+q) putpixel (-x+p, y+q) putpixel (-x+p, -y+q) putpixel (-y+p, -x+q) putpixel (y+p, -x+q) putpixel (x+p, -y-q)  Find location of next pixels to be scanned If d < 0 then d = d + 4x + 6 increment x = x + 1 If d ≥ 0 then d = d + 4 (x - y) + 10 increment x = x + 1 decrement y = y – 1

C. Steps For Experiment/ Practical #include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <math.h> void EightWaySymmetricPlot(int xc,int yc,int x,int y) { putpixel(x+xc,y+yc,RED); putpixel(x+xc,-y+yc,YELLOW); putpixel(-x+xc,-y+yc,GREEN); putpixel(-x+xc,y+yc,YELLOW); putpixel(y+xc,x+yc,12); putpixel(y+xc,-x+yc,14); putpixel(-y+xc,-x+yc,15); putpixel(-y+xc,x+yc,6); } void BresenhamCircle(int xc,int yc,int r) { int x=0,y=r,d=3-(2r); EightWaySymmetricPlot(xc,yc,x,y); while(x<=y) { if(d<=0) { d=d+(4x)+6; } else { d=d+(4x)-(4y)+10; y=y-1; } x=x+1; EightWaySymmetricPlot(xc,yc,x,y); } }

Learning outcomes (What I have learnt):

1. It is faster as compared to DDA (Digital Differential Analyzer) because it does not involve floating point calculations like DDA Algorithm. 2. Bresenham's Line Algorithm use fixed point, i.e., Integer Arithmetic... 3. Bresenham's Line Algorithm can draw circle and curves with more accurate than DDA Algorithm. E. Steps of Experiment

 The input of the 2 end points of the line as (x1, y1) & (x2, y2) such that x1 != x2 and

y1 != y

 Calculate dx = x2 – x1 and dy = y2 – y

 if(dx>=dy) step=dx

else step=dy

 xin = dx / step & yin = dy / step

 x = x1 + 0.5 & y = y1 + 0.

 for(k = 0; k < step; k++) {

x = x + xin y = y +

yin putpixel(x, y)

F. Steps For Experiment/ Practical #include <graphics.h> #include <stdio.h> #include <math.h> #include <dos.h> void main( ) { float x,y,x1,y1,x2,y2,dx,dy,step; int i,gd=DETECT,gm; initgraph(&gd,&gm,"c:\turboc3\bgi"); printf("Enter the value of x1 and y1 : "); scanf("%f%f",&x1,&y1); printf("Enter the value of x2 and y2: "); scanf("%f%f",&x2,&y2); dx=abs(x2-x1); dy=abs(y2-y1); if(dx>=dy) step=dx; else step=dy; dx=dx/step; dy=dy/step; x=x1; y=y1; i=1; while(i<=step) { putpixel(x,y,5); x=x+dx; y=y+dy; i=i+1; delay(100); }

 Consider (x, y) as starting point and xendas maximum possible value of x. If dx < 0 Then x = x 2 y = y 2 xend=x 1 If dx > 0 Then x = x 1 y = y 1 xend=x 2  Generate point at (x,y)coordinates.  Check if whole line is generated. If x > = xend Stop.  Calculate co-ordinates of the next pixel If d < 0 Then d = d + i 1 If d ≥ 0 Then d = d + i 2 Increment y = y + 1  Increment x = x + 1  Draw a point of latest (x, y) coordinates I. Steps For Experiment/ Practical

#include<stdio.h>

#include<graphics.h>

void drawline #include<stdio.h>

#include<graphics.h>

void drawline(int x0, int y0, int x1, int y1)

int dx, dy, p, x, y;

dx=x1-x0;

dy=y1-y0;

x=x0;

y=y0;

p=2*dy-dx;

while(x<x1)

if(p>=0)

putpixel(x,y,7);

y=y+1;

p=p+2dy-2dx;

else

putpixel(x,y,7);

p=p+2*dy;}

x=x+1;

int main()

int gdriver=DETECT, gmode, error, x0, y0, x1, y1;

initgraph(&gdriver, &gmode, "c:\turboc3\bgi");

printf("Enter co-ordinates of first point: ");

scanf("%d%d", &x0, &y0);

printf("Enter co-ordinates of second point: ");

scanf("%d%d", &x1, &y1);

drawline(x0, y0, x1, y1);

return 0;

} (int x0, int y0, int x1, int y1)

int dx, dy, p, x, y;

dx=x1-x0;

dy=y1-y0;

x=x0;

y=y0;

p=2*dy-dx;

while(x<x1)

if(p>=0)

putpixel(x,y,7);

y=y+1;

p=p+2dy-2dx;

else

putpixel(x,y,7);

p=p+2*dy;}

1. It is faster as compared to DDA (Digital Differential Analyzer) because it does not involve floating point calculations like DDA Algorithm. 2. Bresenham's Line Algorithm use fixed point, i.e., Integer Arithmetic... 3. Bresenham's Line Algorithm can draw circle and curves with more accurate than DDA Algorithm.

Evaluation Grid:

Sr. No. Parameters Marks Obtained Maximum Marks

1. Demonstration and Performance

(Pre Lab Quiz)

2. Worksheet 10

3. Post Lab Quiz 5