###### 半平面求交——点在凸包外
#include <bits/stdc++.h>
using namespace std;
const int maxn = 50010;
const double EPS = 1e-8;
struct Point
{
double x, y;
};
Point p[maxn];
struct Line
{
Point a, b;
};
Line l[maxn], st[maxn];
int n;
double operator *(const Point &x, const Point &y)
{
return x.x * y.y - x.y * y.x;
}
Point operator - (Point x, const Point &y)
{
x.x -= y.x, x.y -= y.y;
return x;
}
Point operator *(const Line &x, const Line &y)
{
double a1 = (y.b - x.a) * (y.a - x.a), a2 = (y.a - x.b) * (y.b - x.b);
Point r;
r.x = (x.a.x * a2 + x.b.x * a1) / (a2 + a1);
r.y = (x.a.y * a2 + x.b.y * a1) / (a2 + a1);
return r;
}
bool operator == (const Point &a, const Point &b)
{
return fabs(a.x - b.x) < EPS && fabs(a.y - b.y) < EPS;
}
bool JudgeOut(const Line &x, const Point &p0)
{
return (p0 - x.a) * (x.b - x.a) > -EPS;
}
bool Parallel(const Line &x, const Line &y)
{
return fabs((x.b - x.a) * (y.b - y.a)) < EPS;
}
bool HplaneIntersection(const int &tem)
{
for (int i = 0; i < n; i++)
l[i].a = p[i], l[i].b = p[i - 1 - tem + (i - 1 - tem < 0 ? n : 0)];
int top = 1, bot = 0;
st[0] = l[0], st[1] = l[1];
for (int i = 2; i < n; i++)
{
if (Parallel(st[top], st[top - 1]) || Parallel(st[bot], st[bot + 1])) return 0;
while (bot < top && JudgeOut(l[i], st[top]*st[top - 1])) top--;
while (bot < top && JudgeOut(l[i], st[bot]*st[bot + 1])) bot++;
st[++top] = l[i];
}
while (bot < top && JudgeOut(st[bot], st[top]*st[top - 1])) top--;
while (bot < top && JudgeOut(st[top], st[bot]*st[bot + 1])) bot++;
}
int main(int argc, char const *argv[])
{
while (scanf("%d", &n) != EOF)
{
for (int i = 0; i < n; i++)
scanf("%lf%lf", &p[i].x, &p[i].y);
int lft = 1, rgt = (n - 1) >> 1, mid;
while (rgt > lft)
{
mid = (lft + rgt) >> 1;
if (!HplaneIntersection(mid)) rgt = mid;
else lft = mid + 1;
}
printf("%d\n", rgt);
}
return 0;
}

#### 半平面交初级

2016-04-15 20:15:33

#### 半平面相交的排序增量法

2014-04-16 20:24:09

#### poj 1584(凸包+点在凸多边形内+圆在凸多边形内)

2016-04-28 21:32:10

#### 求一点在空间平面上的垂足

2014-04-18 15:13:20

#### 计算几何之半平面交、多边形的核

2016-04-01 17:46:08

#### SGU 253 计算几何 判定点是否在凸包内

2012-01-14 10:41:10

#### 凸包的面积交，面积并。

2016-09-02 20:09:54

#### poj 3805 Separate Points 判断凸包是否相交，nlogn复杂度

2014-07-20 15:39:49

#### 判断点在多边形内外的简单算法

2007-03-30 18:05:00

#### 计算几何学习之半平面交

2014-04-22 15:51:18