CG Ex-4
CG Ex-4
Experiment 4
Student Name: Jain Aman UID:22BCS14831
Branch: CSE Section/Group:637/B
Semester: 6th Date of Performance:19/02/25
Subject Name: Computer Graphics Lab Subject Code: 22CSH-352
1. Aim:
a) Develop a program to draw a circle using the circle generator algorithm for a
given center and radius.
b) Develop a program to draw a circle using the midpoint circle algorithm for a
given center and radius.
2. Objective:
• To implement a circle drawing algorithm using a circle generator technique for
a given center and radius.
• To develop a program using the Midpoint Circle Algorithm to efficiently draw
a circle.
• To understand and compare the performance and accuracy of different circle
drawing algorithms.
3. Algorithm:
a) Using the Circle Generator Algorithm:
1. Input: Center of the circle (xc,yc) and radius r.
4. End.
2. Initialize:
• Set initial point (x,y)=(0,r).
• Compute the decision parameter: p=1−r
5. End.
4. Implementation/Code:
#define PI 3.14159
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI"); // Initialize graphics mode
#include <graphics.h>
#include <conio.h>
#include <iostream.h>
#include <dos.h> // Required for delay()
int x = 0, y = r;
int p = 1 - r; // Initial decision parameter
while (x < y) {
x++;
if (p < 0) {
p += 2 * x + 1;
} else {
y--;
p += 2 * (x - y) + 1;
}
plotCirclePoints(xc, yc, x, y);
delay(5); // Small delay for visualization
}
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI"); // Initialize graphics mode
5. Learning Outcome:
• Understand the mathematical foundation of circle drawing algorithms.
• Learn how to efficiently plot pixels to represent a smooth circular shape.
• Compare the accuracy and computational efficiency of different algorithms.
• Gain practical experience in implementing geometric algorithms in a
programming language.
• Develop skills to optimize graphical rendering techniques for digital displays.