-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
123 lines (112 loc) · 3.03 KB
/
main.cpp
File metadata and controls
123 lines (112 loc) · 3.03 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
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
//19. Трапеція: (0,0), (2a,0), (a,a), (0,a)
#include <bits/stdc++.h>
using namespace std;
int getCont(double &a);
int getPoint (double &x, double &y);
int wherePoint (double a, double x, double y);
double distPointCont (double a, double x, double y, int pos);
void outPoint (double x, double y);
void outCont (double a);
void outResults (double a, double x, double y, double dist, int pos);
void processCont (double a);
int main()
{
double a;
int in = 0;
setlocale(LC_ALL, "Ukrainian");
while ( !(in == -1) )
{
in = getCont(a);
if ( in == -1 ) return cout << "CONTOUR IS ABSENT\nEND OF WORK", 0;
if ( in == 0 ) cout << "WRONG PARAMETR\n\n";
if ( in == 1) processCont(a);
}
return 0;
}
int getCont(double &a)
{
cout << "Введiть параметр контуру а: ";
cin.clear();
cin >> a;
if (cin.eof())
return -1;
else if (a > 0)
return 1;
else
return 0;
}
void processCont (double a)
{
double x, y, x1, y1, dist;
int pos, getP, k=0;
while (1)
{
++k;
getP = getPoint( x, y);
if (getP == -1)
{
cout << "END OF POINTS\n\n";
return;
}
if (x == x1 && y == y1 && k > 1)
{
cout << "POINT REPEAT\n\n";
return;
}
pos = wherePoint(a, x, y);
dist = distPointCont(a, x, y, pos);
outResults(a, x, y, dist, pos);
x1 = x, y1 = y;
}
}
int getPoint (double &x, double &y)
{
cout << "Введiть координати точок x та y: ";
cin.clear();
cin >> x >> y;
if (cin.eof())
return -1;
else
return 1;
}
int wherePoint (double a, double x, double y)
{
if ( ( y==0 && x>=0 && x<=2*a ) || //down
( y==a && x>=0 && x<=a ) || //up
( x==0 && y>=0 && y<=a ) || //left
( y==-x+2*a && x>=a && x<=2*a ) ) return 0;
if ( y<a && y<-x+2*a && y>0 && x>0 ) return 1;
return -1;
}
double distPointCont (double a, double x, double y, int pos)
{
if (pos == 0) return 0;
if (pos == 1)
return min(sqrt(2)/2*abs(a-x-y), min(a-y, min(y, x)));
if (pos == -1)
{
if (y > a&& x > 0 && x < a) return y-a;
if (x < 0 && y < a && y > 0) return -x;
if (y < 0 && x > 0 && x < 2*a) return -y;
if (y > -x+a && y < x && y > -x-a) return sqrt(2)/2*abs(a-x-y);
return min( sqrt((x-a)*(x-a)+(y-a)*(y-a)), min(sqrt((x-2*a)*(x-2*a)+y*y), min(sqrt(x*x+y*y), sqrt(x*x+(y-a)*(y-a)))));
}
}
void outPoint (double x, double y)
{
cout << "(" << x << "; " << y << ")";
}
void outCont (double a)
{
cout << "[" << a << "]";
}
void outResults (double a, double x, double y, double dist, int pos)
{
cout << "Точка: "; outPoint(x,y);
cout << "\nЇЇ розташування: ";
if ( pos == 1 ) cout << "IN_C";
if ( pos == 0 ) cout << "ON_C";
if ( pos == -1 ) cout << "OUT_C";
cout << "\nПараметр контуру: "; outCont(a);
cout << "\nDISTANCE=" << dist << "\n";
}