LAB Assignment 5: (Bresenham's Algorithm)
LAB Assignment 5: (Bresenham's Algorithm)
ASSIGNMENT 5
(Bresenham’s
Algorithm)
KUNDAN PATIL
171040052
T.Y. B.Tech Production
LAB
ASSIGNMENT-5
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;
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)