设为首页 加入收藏

TOP

poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 - 模版
2014-11-23 20:00:46 来源: 作者: 【 】 浏览:10
Tags:poj 3130 How Mathematician Wonder What You Are 多边形 有没有 模版
/*
poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核



*/
#include 
#include
const double eps=1e-8;
const int N=103;
struct point
{
    double x,y;
}dian[N];
inline bool mo_ee(double x,double y)
{
	double ret=x-y;
	if(ret<0) ret=-ret;
	if(ret y + eps;} // x > y
inline bool mo_ll(double x,double y)  {   return x < y - eps;} // x < y
inline bool mo_ge(double x,double y) {   return x > y - eps;} // x >= y
inline bool mo_le(double x,double y) {   return x < y + eps;} 	// x <= y
inline double mo_xmult(point p2,point p0,point p1)//p1在p2左返回负,在右边返回正
{
    return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}

point mo_intersection(point u1,point u2,point v1,point v2)
{
    point ret=u1;
    double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
		/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
    ret.x+=(u2.x-u1.x)*t;
    ret.y+=(u2.y-u1.y)*t;
    return ret;
}
/////////////////////////

//切割法求半平面交
point mo_banjiao_jiao[N*2];
point mo_banjiao_jiao_temp[N*2];
void mo_banjiao_cut(point *ans,point qian,point hou,int &nofdian)
{
	int i,k;
	for(i=k=0;i 
 
/*
为什么ret<3 
*/
#include
#include
#include   
using namespace std;  

const double eps=1e-8;
struct point 
{
	double x,y;
}dian[20000+10];
point jiao[203];
struct line  
{  
    point s,e;  
    double angle;  
}xian[20000+10];  
int n,yong;
bool mo_ee(double x,double y)  
{  
    double ret=x-y;  
    if(ret<0) ret=-ret;  
    if(ret y + eps;} // x > y     
bool mo_ll(double x,double y)  {   return x < y - eps;} // x < y     
bool mo_ge(double x,double y) {   return x > y - eps;} // x >= y     
bool mo_le(double x,double y) {   return x < y + eps;}     // x <= y     
point mo_intersection(point u1,point u2,point v1,point v2)  
{  
    point ret=u1;  
    double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))  
		/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));  
    ret.x+=(u2.x-u1.x)*t;  
    ret.y+=(u2.y-u1.y)*t;  
    return ret;  
}  
double mo_xmult(point p2,point p0,point p1)//p1在p2左返回负,在右边返回正  
{  
    return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);  
}  


void mo_HPI_addl(point a,point b)  
{  
	xian[yong].s=a;  
	xian[yong].e=b;  
	xian[yong].angle=atan2(b.y-a.y,b.x-a.x);  
	yong++;  
}  
//半平面交
bool mo_HPI_cmp(const line& a,const line& b)
{
	if(mo_ee(a.angle,b.angle))
	{
		return mo_gg( mo_xmult(b.e,a.s,b.s),0);
	}else
	{
		return mo_ll(a.angle,b.angle);
	}
}
int mo_HPI_dq[20000+10];
bool mo_HPI_isout(line cur,line top,line top_1)
{
	point jiao=mo_intersection(top.s,top.e,top_1.s,top_1.e);
	return mo_ll( mo_xmult(cur.e,jiao,cur.s),0);//若顺时针时应为mo_gg
}
int mo_HalfPlaneIntersect(line *xian,int n,point *jiao)
{
	int i,j,ret=0;
	sort(xian,xian+n,mo_HPI_cmp);
	for (i = 0, j = 0; i < n; i++)
	{
		if (mo_gg(xian[i].angle,xian[j].angle))
		{
			xian[++j] = xian[i];
		}
	}
	n=j+1;
	mo_HPI_dq[0]=0;
	mo_HPI_dq[1]=1;
	int top=1,bot=0;
	for (i = 2; i < n; i++)
	{
        while (top > bot && mo_HPI_isout(xian[i], xian[mo_HPI_dq[top]], xian[mo_HPI_dq[top-1]])) top--;
        while (top > bot && mo_HPI_isout(xian[i], xian[mo_HPI_dq[bot]], xian[mo_HPI_dq[bot+1]])) bot++;
        mo_HPI_dq[++top] = i; //当前半平面入栈
	}
    while (top > bot && mo_HPI_isout(xian[mo_HPI_dq[bot]], xian[mo_HPI_dq[top]], xian[mo_HPI_dq[top-1]])) top--;
    while (top > bot && mo_HPI_isout(xian[mo_HPI_dq[top]], xian[mo_HPI_dq[bot]], xian[mo_HPI_dq[bot+1]])) bot++;
    mo_HPI_dq[++top] = mo_HPI_dq[bot];
    for (ret = 0, i = bot; i < top; i++, ret++)
	{
		jiao[ret]=mo_intersection(xian[mo_HPI_dq[i+1]].s,xian[mo_HPI_dq[i+1]].e,xian[mo_HPI_dq[i]].s,xian[mo_HPI_dq[i]].e);
	}
	return ret;
}
int main()
{
	int i;
	while(scanf("%d",&n),n)
	{
		yong=0;
		for(i=0;i 
 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 3225 Help with Intervals(.. 下一篇二叉排序树

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python爬虫教程(从 (2025-12-26 16:49:14)
·【全269集】B站最详 (2025-12-26 16:49:11)
·Python爬虫详解:原 (2025-12-26 16:49:09)
·Spring Boot Java: (2025-12-26 16:20:19)
·Spring BootでHello (2025-12-26 16:20:15)