0% found this document useful (0 votes)
48 views

Cad Cam Lab Assignment

This document contains code and output for drawing lines using the DDA and Bresenham's line algorithms. The code first implements the DDA algorithm to draw lines between user-input coordinates. It then calculates the slope and y-intercept to output the coordinates. Next, the code implements Bresenham's algorithm, taking user input for start and end points. It calculates deltas, signs, and initial fractional parts for the line. A loop draws pixels and increments fractions until the length is reached. Finally, it outputs the coordinates. Sample outputs show coordinates drawn between (10,20) to (90,110) and (50,50) to (100,120) using DDA, and

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)
48 views

Cad Cam Lab Assignment

This document contains code and output for drawing lines using the DDA and Bresenham's line algorithms. The code first implements the DDA algorithm to draw lines between user-input coordinates. It then calculates the slope and y-intercept to output the coordinates. Next, the code implements Bresenham's algorithm, taking user input for start and end points. It calculates deltas, signs, and initial fractional parts for the line. A loop draws pixels and increments fractions until the length is reached. Finally, it outputs the coordinates. Sample outputs show coordinates drawn between (10,20) to (90,110) and (50,50) to (100,120) using DDA, and

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/ 10

LAB

ASSIGNMENT-4
(DDA Algorithm)

NAME: KUNDAN PATIL


ID NO: 171040052
T. Y. B.Tech Production
1
CODE:
#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 x=x1;
int y=y1;

int e=(2*dy)-dx;
for (int i=0;i<=dx;i++)
{
putpixel(x,y,BLUE);
while(e>=0)
{
y=y+1;
e=e-(2*dx);
}
x=x+1;
e=e+(2*dy);
}

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;
}
getch();
closegraph();
return 0;
}

2
CODE:

3
Output 1: Co-ordinates: (10, 20) (90,110)

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

5
LAB
ASSIGNMENT-5
(Bresenham’s
Algorithm)

NAME: KUNDAN PATIL


ID NO: 171040052
T. Y. B.Tech Production
6
CODE:
#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;
}}
7
CODE:

8
Output 1: Co-ordinates: (100, 50) (200,150)

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

10

You might also like