# 计算几何学简单的模板

#include <iostream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define maxn 1200
#define eps 1e-8
struct point
{
double x;
double y;
}po[maxn];
struct line
{
point a;
point b;
}；
typedef point vector;
vector operator + (vector a,vector b)
{
return vector(a.x+b.x,a.y+b.y);
}
vector operator - (point a,point b)
{
return vector(a.x-b.x,a.y-b.y);
}
vector operator * (vector a,double b)
{
return vector(a.x*p,a.y*p);
}
vector operator / (vector a,double b)
{
return vector(a.x/p,a.y/p);
}
bool operator<(const point&a,const point&b)
{
return a.x<b.x||(a.x == b.x&&a.y<b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps)
return 0;
else
return x<0?-1:1;
}
bool operator == (const point& a,const point &b)
{
return dcmp(a.x-b.x) == 0 && dcmp(a.y - b.y) == 0;
}

double xmulit(point &a,point &b,point &c)
{
return (a.x-b.x)*(a.y-c.y)-(a.y-b.y)*(a.x-c.x);
}

bool across(point &a,point &b,point &c,point &d)
{
double p=xmulit(a,b,c),p1=xmulit(a,b,d);
if( fabs(p1) <= eps || fabs(p) <= eps ) return true;
if( p*p1 < -eps )
return true;
return false;
}

bool one_line(point &a,point &b,point &c,point &d)
{
double p=xmulit(a,b,c),p1=xmulit(a,b,d);
if( fabs(p1) < eps && fabs(p) < eps ) return true;
return false;
}

bool is_equal(point &a,point &b)
{
return (fabs(a.x-b.x) <= eps) && (fabs(a.y-b.y) <=eps);
}

point intersection(line &u,line &v)
{
point ret=u.a;
double t=((u.a.x-v.a.x)*(v.a.y-v.b.y) - (u.a.y-v.a.y)*(v.a.x-v.b.x))/((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x));
ret.x+=(u.b.x-u.a.x)*t;
ret.y+=(u.b.y-u.a.y)*t;
return ret;
}

double dis(point &a,point &b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

bool on_line(point pi,point pj,point pk)
{
if(xmulit(pi, pj, pk)==0)
{
if(pk.x>=min(pi.x,pj.x)&&pk.x<=max(pi.x,pj.x)&&pk.y>=min(pi.y,pj.y)&&pk.y<=max(pi.y,pj.y))
return true;
}
return false;
}

bool segments_intersect(point p1,point p2,point p3,point p4)
{
double d1=xmulit(p3,p4,p1);
double d2=xmulit(p3,p4,p2);
double d3=xmulit(p1,p2,p3);
double d4=xmulit(p1,p2,p4);
if(d1*d2<0&&d3*d4<0)
return true;
else if(d1==0&&on_segment(p3,p4,p1))
return true;
else if(d2==0&&on_segment(p3,p4,p2))
return true;
else if(d3==0&&on_segment(p1,p2,p3))
return true;
else if(d4==0&&on_segment(p1,p2,p4))
return true;
return false;
}

int inpoto(point a)
{
int i;
point b,c,d;
b.y=a.y;
b.x=1e15;//定义射线
int flag=0;
int count=0;
for(i=0;i<n;i++)
{
c = po[i];
d = po[i + 1];
if(on_segment(c,d,a))//该点在多边形的一条边上
return 1;
if(abs(c.y-d.y)<eps)
continue;
if(on_segment(a,b,c))//和顶点相交的情况，如果y值较大则取
{
if(c.y>d.y)
count++;
}
else if(on_segment(a,b,d))//和顶点相交的情况，如果y值较大则取
{
if(d.y>c.y)
count++;
}
else if(segments_intersect(a,b,c,d))//和边相交
count++;
}
return count%2;//当L和多边形的交点数目C是奇数的时候，P在多边形内，是偶数的话P在多边形外。
}

point mid(point &a,point &b)
{
point c;
c.x=(a.x+b.x)/2;
c.y=(a.y+b.y)/2;
return c;
}

vector rotate (vector a,double rad)
{
}

04-11 456

02-26 200
08-15 1万+
08-18 706
04-21 66
08-16 165
07-07 91
08-12 671
12-28 872
08-24 1758
10-30 2069
08-08 54
08-16 620
07-17 1346
11-21 320
02-13 60
07-12 316
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客