-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy path5. b) Pattern - Circle in Triangle.cpp
More file actions
71 lines (68 loc) · 1.02 KB
/
5. b) Pattern - Circle in Triangle.cpp
File metadata and controls
71 lines (68 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
5. B) Write a c++ program inscribed and
circumscribed circles in triangle
*/
#include<iostream.H>
#include<graphics.h>
#include<stdio.h>
void ddaAlg(int x1,int y1,int x2,int y2)
{
int dx=x2-x1;
int dy=y2-y1;
int steps=dx>dy?dx:dy;
float xInc=dx/(float)steps;
float yInc=dy/(float)steps;
float x=x1;
float y=y1;
for(int i=0;i<=steps;i++)
{
putpixel(x,y,14);
x+=xInc;
y+=yInc;
}
}
void display(int xc,int yc,int x,int y)
{
putpixel(xc+x, yc+y, 3);
putpixel(xc-x, yc+y, 3);
putpixel(xc+x, yc-y, 3);
putpixel(xc-x, yc-y, 3);
putpixel(xc+y, yc+x, 3);
putpixel(xc-y, yc+x, 3);
putpixel(xc+y, yc-x, 3);
putpixel(xc-y, yc-x, 3);
}
void CircleB(int x1,int y1,int r)
{
int x=0,y=r;
int d=3-2*r;
display(x1,y1,x,y);
while(y>=x)
{
x++;
if(d>0)
{
y--;
d=d+4*(x-y)+10;
}
else
{
d=d+4*x+6;
}
display(x1,y1,x,y);
}
}
int main()
{
int gd=DETECT, gm;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
CircleB(150,180,57);
CircleB(150,180,57/2);
ddaAlg(102,150,198,150);
ddaAlg(102,150,150,236);
ddaAlg(150,236,198,150);
getch();
closegraph();
return 0;
}
OUTPUT: