-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgeometry_topcoder.cpp
128 lines (115 loc) · 2.25 KB
/
geometry_topcoder.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
#include<bits/stdc++.h>
using namespace std;
#define inf 1013161010
#define mod 1000000007
#define ll long long
#define in(x) scanf("%d",&x);
#define sz(x) ((int)x.size())
#define lld l64d
#define rep(i,n) for(i=0;i<n;i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define rrep1(i,a,b) for(i=a;i>=b;i--)
#define stlfor(i,t) for(auto i =t.begin();i!=t.end();i++)
#define fr freopen("x.txt","r",stdin)
#define all(x) x.begin(),x.end()
#define set0(x) memset(x,0,sizeof(x))
#define dbg cout<<"yo "<<endl;
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
const double pi(3.14159265358979);
ll gcd(ll a,ll b){return (b==0)? a:gcd(b,a%b); }
int a[223456];
class point
{
public:
double x;
double y;
double dist(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double mand(point a,point b)
{
return abs(a.x-b.x)+abs(a.y-b.y);
}
};
class vect
{
public:
double x,y;
vect()
{
x=0;y=0;
}
vect(point a,point b)
{
x=b.x-a.x;
y=b.y-a.y;
}
double mode(vect a)
{
return (sqrt(a.x*a.x+a.y*a.y));
}
vect operator +(vect a)
{
vect c;
c.x=x+a.x;
c.y=y+a.y;
return c;
}
vect operator -(vect a)
{
vect c;
c.x=x-a.x;
c.y=y-a.y;
return c;
}
double dot(vect a,vect b)
{
return (b.x*a.x + b.y+a.y);
}
double cross(vect a,vect b)
{
return (a.x*b.y-a.y*b.x);
}
};
double polygon_area(point a[],int n)
{
int i=0;
double ans=0;
vect c;
while(i+1<n)
{
ans+=c.cross(vect(a[i],a[0]),vect(a[i+1],a[0]));
i++;
}
return ans;
}
double point_to_line(point a,point b,point c,int is_segment)
{
vect d;
point e;
double ans=d.cross(vect(a,b),vect(a,c))/d.mode(vect(a,b));
if(is_segment)
{
if(d.dot(vect(a,b),vect(b,c))>0)
return e.dist(b,c);
if(d.dot(vect(b,a),vect(c,a))>0)
return e.dist(c,a);
}
return ans;
}
int main()
{
int i,j,n;
point a;
return 0;
}