0% found this document useful (0 votes)
3 views8 pages

ashutosh_cg

This document is a practical file for MCS 411- Practical-1 based on Computer Graphics, submitted to Jiwaji University by Anushka Gaur. It includes programming assignments for various algorithms such as the mid-point circle algorithm, Bresenham’s line drawing algorithm, and the DDA line algorithm. The document provides code examples and outputs for each program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

ashutosh_cg

This document is a practical file for MCS 411- Practical-1 based on Computer Graphics, submitted to Jiwaji University by Anushka Gaur. It includes programming assignments for various algorithms such as the mid-point circle algorithm, Bresenham’s line drawing algorithm, and the DDA line algorithm. The document provides code examples and outputs for each program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

A

PRACTICAL FILE
ON

MCS 411- Practical-1


(Based on Computer Graphics)

SUBMITTED TO
JIWAJI UNIVERSITY, GWALIOR (M.P.)

IN PARTIAL FULFILLMENT FOR THE REQUIREMENTS OF IVth SEMESTER OF

Master Of Science
In
Computer Science
ADADEMIC YEAR 2021-22

Submitted to:- Submitted by:-


Mr. Pankaj Goyal Anushka Gaur
Faculty Roll No. 201359780

SCHOOL OF MATHEMATICS AND ALLIED SCIENCES


JIWAJI UNIVERSITY, GWALIOR (M.P.)
2022
MCS 411-
Practical-1

Based on
Computer
Graphics
1. Write a program for mid point circle

//mid point algorithm


#include<iostream>
using namespace std;

int main()
{
cout<<"This program was made by Ashutosh Rathore\n";
int x = 0,y = 0,a,b,r,k = 0,p;
cout<<"enter the value of a,b,r\n";
cin>>a>>b>>r;

x+=a;
y+=b;

y =r;
p = 1-r;
cout<<"\n";
cout<<"k"<<"\t"<<"pk"<<"\t"<<"(x,y)"<<"\n";

for(int i=0;i<30;i++)
cout<<"-";

cout<<"\n";
while ( x < y)
{
cout<<k<<"\t";
cout<<p<<"\t";
x++;
if(p<0)
{
p = p+2*x+1;
}
else
{
y--;
p = p + 2*x - 2*y + 1;
}
cout<<"("<<x<<","<<y<<")"<<"\n";
k++;
}

Output:
2. Write a program for bresenham’s line drawing algorithm

// program for bresenham’s line


#include <stdio.h>
#include <math.h>
int main()
{
printf("This program was made by Ashutosh Rathore");
int a, r, ya, yb, dx, dy, p, x, y;
printf("\nEnter first point(x1,y1) coordinates: ");
scanf("%d%d", &a, &ya);
printf("\nEnter second point(x2,y2) coordinates: ");
scanf("%d%d", &r, &yb);
dx = r - a;
dy = yb - ya;
p = 2 * dy - dx;
x = a;
y = ya;
printf("\n\t\t\t(%d, %d)", x, y);
for (int i = 0; i < dx; i++)
{
if (p < 0)
{
x = x + 1;
printf("\n\t%d\t%d\t(%d, %d)", i, p, x, y);
p = p + 2 * dy;
}
else
{
x = x + 1;
y = y + 1;
printf("\n\t%d\t%d\t(%d, %d)", i, p, x, y);
p = p + 2 * dy - 2 * dx;
}
}
return 0;
}

Output:
3.

// program for line dda


#include <stdio.h>
#include <math.h>

int main()
{
printf("This program was made by Ashutosh Rathore");
int a, b, ya, yb, dx, dy, steps;
float xinc, yinc, x, y;

printf("\nEnter first point(x1,y1) coordinates");


scanf("%d%d", &a, &ya);
printf("\nEnter second point(x2,y2) coordinates");
scanf("%d%d", &b, &yb);
dx = b - a;
dy = yb - ya;
if (abs(dx) >= abs(dy))
steps = abs(dx);
else
steps = abs(dy);
xinc = dx / (float)steps;
yinc = dy / (float)steps;
x = a;
y = ya;
printf("\n(%d, %d)", int(x + 0.5), int(y + 0.5));
for (int i = 1; i <= steps; i++)
{
x = x + xinc;
y = y + yinc;
printf("\n(%d, %d)", int(x + 0.5), int(y + 0.5));
}
return 0;
}

Output:

You might also like