struct point{
double x, y;
};
double get_angle(point p, point ps[], int n){
int i;
//过p做一条水平直线,求所有点对这条水平直线的夹角,最大的角减去最小的角即可
double Max, Min, ang1, ang2, dang, sum;
Max = Min = sum = 0;
ps[n] = ps[0];
//ang2 = atan2(ps[0].y - p.y, ps[0].x - p.x);
for(i = 1; i <= n; i++){
//ang1 = ang2;
ang1 = atan2(ps[i-1].y - p.y, ps[i-1].x - p.x);
ang2 = atan2(ps[i].y - p.y, ps[i].x - p.x);
if(ang1 - ang2 > pi) ang2 += 2 * pi;
if(ang2 - ang1 > pi) ang1 += 2 * pi;
sum += ang1 - ang2;
if(sum > Max) Max = sum;
if(sum < Min) Min = sum;
if(Max - Min > 2 * pi){
Max = Min + 2 * pi;
break;
}
}
return Max - Min;
}
点对多边形的夹角
最新推荐文章于 2022-08-26 14:14:19 发布