Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Parth1906
GitHub Repository: Parth1906/SPPU-2019-Pattern-SE-COMP-Computer-Graphics-Practicals
Path: blob/main/5. b) Pattern - Circle in Triangle.cpp
724 views
1
/*
2
5. B) Write a c++ program inscribed and
3
circumscribed circles in triangle
4
*/
5
6
#include<iostream.H>
7
#include<graphics.h>
8
#include<stdio.h>
9
void ddaAlg(int x1,int y1,int x2,int y2)
10
{
11
int dx=x2-x1;
12
int dy=y2-y1;
13
int steps=dx>dy?dx:dy;
14
float xInc=dx/(float)steps;
15
float yInc=dy/(float)steps;
16
float x=x1;
17
float y=y1;
18
for(int i=0;i<=steps;i++)
19
{
20
putpixel(x,y,14);
21
x+=xInc;
22
y+=yInc;
23
}
24
}
25
void display(int xc,int yc,int x,int y)
26
{
27
putpixel(xc+x, yc+y, 3);
28
putpixel(xc-x, yc+y, 3);
29
putpixel(xc+x, yc-y, 3);
30
putpixel(xc-x, yc-y, 3);
31
putpixel(xc+y, yc+x, 3);
32
putpixel(xc-y, yc+x, 3);
33
putpixel(xc+y, yc-x, 3);
34
putpixel(xc-y, yc-x, 3);
35
}
36
37
void CircleB(int x1,int y1,int r)
38
{
39
int x=0,y=r;
40
int d=3-2*r;
41
display(x1,y1,x,y);
42
while(y>=x)
43
{
44
x++;
45
if(d>0)
46
{
47
y--;
48
d=d+4*(x-y)+10;
49
}
50
else
51
{
52
d=d+4*x+6;
53
}
54
display(x1,y1,x,y);
55
}
56
}
57
int main()
58
{
59
int gd=DETECT, gm;
60
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
61
CircleB(150,180,57);
62
CircleB(150,180,57/2);
63
ddaAlg(102,150,198,150);
64
ddaAlg(102,150,150,236);
65
ddaAlg(150,236,198,150);
66
getch();
67
closegraph();
68
return 0;
69
}
70
71
OUTPUT:
72
73