-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStruct Point
73 lines (59 loc) · 1.71 KB
/
Struct Point
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
/// learnt from https://codeforces.com/contest/394/submission/13185760
struct Point{
long double x,y ;
Point(long double _x=0 , long double _y=0){x=_x , y=_y ;}
Point operator-(const Point& b){return Point(x-b.x,y-b.y);}
Point operator+(const Point& b){return Point(x+b.x,y+b.y);}
Point operator/(long double v){return Point(x/v,y/v);}
Point operator*(long double v){return Point(x*v,y*v);}
bool operator<(const Point& rhs){
return x<rhs.x or (x==rhs.x and y<rhs.y) ;
}
long double dis(){
return x*x+y*y ;
}
long double calco(Point arr[]){
long double ans=0 ;
for(int i=1;i<=n;++i)
ans+=(arr[i]-(*this)).dis() ;
return ans ;
}
}p[100010],yo[100010];
int Orientation(Point a[]){
long double res=0 ;
a[3]=a[0] ;
for(int i=0;i<3;++i){
res+=(a[i].x*a[i+1].y)-(a[i].y*a[i+1].x) ;
}
if(res<0.0)return -1 ; /// clockwise ...
else if(res>0.0)return +1 ; /// counterclockwise ...
return 0 ; /// colinear ...
}
int main(){
Point rp(0,0) ;
for(int i=1;i<=n;++i){
long double x , y ;
cin>>x>>y ;
p[i]=Point(x,y) ;
rp=rp+p[i] ;
}
rp=rp/n ;
}
///**** anachor
PT ProjectPointLine(PT a, PT b, PT c) {
return a + (b-a)*dot(c-a, b-a)/dot(b-a, b-a);
}
// project point c onto line segment through a and b
PT ProjectPointSegment(PT a, PT b, PT c) {
double r = dot(b-a,b-a);
if (fabs(r) < EPS) return a;
r = dot(c-a, b-a)/r;
if (r < 0) return a;
if (r > 1) return b;
return a + (b-a)*r;
}
// compute distance from c to segment between a and b
double DistancePointSegment(PT a, PT b, PT c) {
return sqrt(dist2(c, ProjectPointSegment(a, b, c)));
}
/***/