poj How I Mathematician Wonder What You Are! 求多边形的核
来源:互联网 发布:农业科技网络书屋登录 编辑:程序博客网 时间:2024/05/01 02:14
#include <iostream>
#include<cmath>
using namespace std;
const double EPS=1e-8;
const int MAXN=100;
struct point
{
double x,y;
};
struct cp
{
int n;
point p[MAXN];
};
//求直线a1*x+b1*y+c1=0与a2*x+b2*y+c2=0的交点
point intersectL(double a1, double b1, double c1, double a2, double b2, double c2)
{
point ret;
ret.y = (a1 * c2 - c1 * a2) / (b1 * a2 - a1 * b2);
if (fabs(a2) < EPS)
ret.x = -(b1 * ret.y + c1) / a1;
else
ret.x = -(b2 * ret.y + c2) / a2;
return ret;
}
//判断点inpa与点inpb是否相同
bool isEqual(point inpA, point inpB)
{
return (fabs(inpA.x - inpB.x) < EPS && fabs(inpA.y - inpB.y) < EPS);
}
//求向量AB与向量AC的叉乘
double Cross(point inpA, point inpB, point inpC)
{
return (inpB.x - inpA.x) * (inpC.y - inpA.y) - (inpC.x - inpA.x) * (inpB.y - inpA.y);
}
//求由点A,B构成的直线a*x+b*y+c=0;
void Get_line(point inpA, point inpB, double &a1, double &b1, double &c1)
{
a1 = inpB.y - inpA.y;
b1 = inpA.x - inpB.x;
c1 = inpA.y * (inpB.x - inpA.x) - inpA.x * (inpB.y - inpA.y);
}
cp cut(point inpA, point inpB, cp incp)
{
cp ret;
point cross;
int i, j;
double t1, t2;
double a1, b1, c1, a2, b2, c2;
ret.n = 0;
for (i = 0; i < incp.n; i++)
{
j = i + 1;
t1 = Cross(inpA, inpB, incp.p[i]);
t2 = Cross(inpA, inpB, incp.p[j]);
if (t1 < EPS && t2 < EPS)
{
ret.p[ret.n++] = incp.p[i];
ret.p[ret.n++] = incp.p[j];
}
else if (t1 > EPS && t2 > EPS)
continue;
else
{
Get_line(inpA, inpB, a1, b1, c1);
Get_line(incp.p[i], incp.p[j], a2, b2, c2);
cross = intersectL(a1, b1, c1, a2, b2, c2);
if (t1 < EPS)
{
ret.p[ret.n++] = incp.p[i];
ret.p[ret.n++] = cross;
}
else
{
ret.p[ret.n++] = cross;
ret.p[ret.n++] = incp.p[j];
}
}
}
if (ret.n == 0)
return ret;
for (i = 1, j = 1; i < ret.n; i++)
if (!isEqual(ret.p[i - 1], ret.p[i]))
ret.p[j++] = ret.p[i];
ret.n = j;
if (ret.n != 1 && isEqual(ret.p[ret.n - 1], ret.p[0]))
ret.n--;
ret.p[ret.n] = ret.p[0];
return ret;
}
int main()
{
// freopen("input.txt","r",stdin);
int n,i;
cp input,ret;
while(cin>>n&&n)
{
input.n=n;
for(i=0;i<n;i++)
cin>>input.p[n-i-1].x>>input.p[n-i-1].y;
input.p[input.n]=input.p[0];
ret=input;
for(i=0;i<input.n;i++)
{
ret=cut(input.p[i],input.p[i+1],ret);
}
if(ret.n>=1)
cout<<1<<endl;
else cout<<0<<endl;
}
return 0;
}
- poj How I Mathematician Wonder What You Are! 求多边形的核
- poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 - 模版
- POJ 3130 How I Mathematician Wonder What You Are!(半平面交求多边形的核)
- POJ 3130 How I Mathematician Wonder What You Are! & 3335 Rotating Scoreboard (半平面交求多边形的核)
- POJ 3130 How I Mathematician Wonder What You Are! 半平面交求多边形内核是否存在
- POJ 3130 How I Mathematician Wonder What You Are! (半平面交+多边形内核判断)
- poj 3130 How I Mathematician Wonder What You Are!
- POJ 3130 How I Mathematician Wonder What You Are!
- POJ 3130 How I Mathematician Wonder What You Are!
- poj 3130 How I Mathematician Wonder What You Are!
- POJ 3130 How I Mathematician Wonder What You Are!
- POJ 3130 How I Mathematician Wonder What You Are!
- POJ 3130 || How I Mathematician Wonder What You Are!
- poj 3130 How I Mathematician Wonder What You Are!
- POJ 3130 How I Mathematician Wonder What You Are! 笔记
- How I Mathematician Wonder What You Are! POJ
- POJ 3130 & ZOJ 2820 How I Mathematician Wonder What You Are!(半平面相交 多边形是否有核)
- POJ3130 How I Mathematician Wonder What You Are! 半平面交判多边形是否有核
- java中equals方法和“==”的区别:(转)
- FPGA/CPLD入门介绍
- watir教程实例
- 给30岁的程序员
- Hadoop-0.20.0源代码分析(19)
- poj How I Mathematician Wonder What You Are! 求多边形的核
- poj 3133 Manhattan Wiring
- 我爱你---60国庆,我爱你中国
- Java核心技术①
- PKU 1986 Distance Queries LCA
- 想到的一点uml的东西 ~
- SQL Server 2005远程连接和外围应用配置器修复
- 我的心碎了
- 常指针,指针常量