-
Notifications
You must be signed in to change notification settings - Fork 1
/
TriangleInCircle.cpp
154 lines (143 loc) · 3.76 KB
/
TriangleInCircle.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void circlee(int radius,int xc,int yc);
void rotat(int n, float c[][3], float ra);
void multi(int n, float b[][3], float c[][3], float a[][3]);
void dis(int n, float c[][3])
{
float maxx, maxy;
int i;
maxx= getmaxx();
maxy= getmaxy();
maxx/=2;
maxy/=2;
i=0;
while(i<n-1)
{
line(maxx+c[i][0], maxy-c[i][1], maxx+c[i+1][0], maxy-c[i+1][1]);
i++;
}
i=n-1;
line(maxx+c[i][0], maxy-c[i][1], maxx+c[0][0], maxy-c[0][1]);
setcolor(15);
line(0, maxy, maxx*2,maxy);
line(maxx,0,maxx,maxy*2);
setcolor(WHITE);
}
int main()
{
int gDriver=DETECT,gMode;
initgraph(&gDriver,&gMode,"c:\\tc\\bgi");
int radius,xc,yc;
// cout<<endl<<"enter centre point:";
// cout<<endl<<"XC:";
// cin>>xc;
// cout<<endl<<"YC:";
// cin>>yc;
// cout<<endl<<"radius:";
// cin>>radius;
cleardevice();
float c[10][3];
int i;
circlee(100,0,0);
for(i=0;i<3;i++)
{
printf("Enter coordinates of %d vertex \n",i+1);
scanf("%f%f",&c[i][0],&c[i][1]);
c[i][2]=1;
}
dis(3,c);
rotat(3,c,45);
rotat(3,c,90);
rotat(3,c,135);
rotat(3,c,180);
rotat(3,c,225);
rotat(3,c,270);
rotat(3,c,315);
rotat(3,c,360);
getch();
return 0;
}
void multi(int n, float b[][3], float c[][3], float a[][3])
{
int i,j,k;
for(i=0;i<n;i++)
for(j=0;j<3;j++)
{
a[i][j]=0;
}
for(i=0;i<n;i++)
for(j=0;j<3;j++)
for(k=0;k<3;k++)
{
a[i][j]+=c[i][k]*b[k][j];
}
}
void rotat(int n, float c[][3], float ra)
{
int i=0,j;
float b[10][3], xp, yp, a[10][3];
xp = 0;//pivot point
yp = 0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=0;
b[0][0]=cos(ra*3.14/180);
b[1][1]=cos(ra*3.14/180);
b[0][1]=sin(ra*3.14/180);
b[1][0]=-sin(ra*3.14/180);
b[2][0] = (-xp*cos(ra*3.14/180))+(yp*sin(ra*3.14/180))+xp;
b[2][1]= (-xp*sin(ra*3.14/180))-(yp*cos(ra*3.14/180))+yp;
// b[0][2]=50;//-(50*cos(ra*3.14/180))-(50*sin(ra*3.14/180));
// b[1][2]=50;//+(50*sin(ra*3.14/180))-(50*cos(ra*3.14/180));
b[2][2]=1;
multi(3,b,c,a);
setcolor(WHITE);
dis(n,a);
}
void circlee(int radius,int xc,int yc)
{
int p,x,y;
float maxx, maxy;
int i;
maxx= getmaxx();
maxy= getmaxy();
maxx/=2;
maxy/=2;
line(0, maxy, maxx*2,maxy);
line(maxx,0,maxx,maxy*2);
xc=maxx+xc;
yc=maxy-yc;
void draw(int x,int y,int xc,int yc);
p=1-radius;
x=0;
y=radius;
draw(x,y,xc,yc);
while(x<=y)
{
x++;
if(p<0)
{
p+=2*x+1;
}
else
{
p+=2*(x-y)+1;
y--;
}
draw(x,y,xc,yc);
}
}
void draw(int x,int y,int xc,int yc)
{
putpixel(xc+x,yc+y,12);
putpixel(xc+x,yc-y,12);
putpixel(xc-x,yc+y,12);
putpixel(xc-x,yc-y,12);
putpixel(xc+y,yc+x,12);
putpixel(xc-y,yc+x,12);
putpixel(xc+y,yc-x,12);
putpixel(xc-y,yc-x,12);
}