- UID
- 5280
- 积分
- 9466
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-5-18
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
struct point
{
double x,y;
};
double max(double x,double y)
{
return (x>y)?x:y;
}
double min(double x,double y)
{
return (x<y)?x:y;
}
//浮点精度处理,三出口函数
int dblcmp(double d)
{
if (fabs(d)<precision) return 0;
return (d>0)?1:-1;
}
//叉积
double det(double x1,double y1,double x2,double y2)
{
return x1*y2-x2*y1;
}
double cross(struct point a,struct point b,struct point c)
{
return det(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y);
}
//叉积
//点积(使用较少)
double dotdet(double x1,double y1,double x2,double y2)
{
return x1*x2+y1*y2;
}
double dot(struct point a,struct point b,struct point c)
{
return dotdet(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y);
}
点积的三点共线判定
int betweencmp(struct point a,struct point b,struct point c)
{
return dblcmp(dot(a,b,c));
}
//点积(使用较少)
//判断a在不在bc范围内
int xycmp(double p,double mini,double maxi)
{
return dblcmp(p-mini)*dblcmp(p-maxi);
}
int betweencmp(struct point a,struct point b,struct point c)
{
if (fabs(b.x-c.x)>fabs(b.y-c.y))
return xycmp(a.x,min(b.x,c.x),max(b.x,c.x));
else return xycmp(a.y,min(b.y,c.y),max(b.y,c.y));
}
//判断a在不在bc范围内 |
|