0% found this document useful (0 votes)
59 views6 pages

LAB Assignment 5: (Bresenham's Algorithm)

This document is a lab assignment submission for a computer graphics course. It contains the name and student details of the submitter, Kundan Patil, as well as source code implementing Bresenham's line drawing algorithm. The code takes x and y coordinates of two points as input, calculates the slope and intercept of the line between them, and uses the Bresenham algorithm to iteratively plot pixels and draw the line on the screen. Sample output showing the input and drawn line between the points (100,50) and (200,150) is also included.

Uploaded by

Kundan Patil
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)
59 views6 pages

LAB Assignment 5: (Bresenham's Algorithm)

This document is a lab assignment submission for a computer graphics course. It contains the name and student details of the submitter, Kundan Patil, as well as source code implementing Bresenham's line drawing algorithm. The code takes x and y coordinates of two points as input, calculates the slope and intercept of the line between them, and uses the Bresenham algorithm to iteratively plot pixels and draw the line on the screen. Sample output showing the input and drawn line between the points (100,50) and (200,150) is also included.

Uploaded by

Kundan Patil
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/ 6

CAD CAM LAB

ASSIGNMENT 5
(Bresenham’s
Algorithm)

KUNDAN PATIL
171040052
T.Y. B.Tech Production
LAB
ASSIGNMENT-5

NAME: KUNDAN PATIL


ID NO: 171040052
T. Y. B.Tech Production

CODE:
1
#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
int main(void)
{
int gdriver = DETECT, gmode, errorcode;

initgraph(&gdriver, &gmode, “C:\\tc\\bgi”);

cout<<"\n Enter X1,Y1,X2,Y2"; int x1,y1,x2,y2;


cin>>x1>>y1>>x2>>y2;

int dx=x2-x1;
int dy=y2-y1;
int length;
if (dx>=dy)
length=dx;
else
length=dy;
dx=dx/length;
dy=dy/length;
int sx;
if (dx>=0)
sx=1;
else
sx=-1;
int sy;
if(dy>=0)
sy=1;
else
sy=-1;
float x=x1+0.5*(sx);
float y=y1+0.5*(sy);
int i=0;
while(i<=length)
{ putpixel(int(x),int(y),blue);
x=x+dx;
y=y+dy;
i=i+1;
}
getch();
closegraph();
return 0;
int m = (y2 - y1)/(x2 - x1);
int c = y1-m*x1;
for (int x = x1; x <= x2; x++)
{ y = round(mx + c);
cout<<x<<" "<<y<<endl;
}}

CODE:
2
3
Output 1: Co-ordinates: (100, 50) (200,150)

4
Output 2: Co-ordinates: (100, 50) (200,150)

You might also like