不规则多边形内角大于180度的计算方法

4

我正在尝试计算红色显示的值,即内角。

我有一个点数组,表示线相交的位置,并尝试使用点积,但它只返回最小的角度。我需要完整范围的内角(0-359),但似乎找不到符合这个标准的方法。

arrow


这个问题在MATLAB语言中有答案。我认为你仍然能够理解它。 - eigenchris
2个回答

3
假设你的角度是按照标准逆时针格式给出的,以下内容应该可行:
void angles(double points[][2], double angles[], int npoints){
    for(int i = 0; i < npoints; i++){
        int last = (i - 1 + npoints) % npoints;
        int next = (i + 1) % npoints;
        double x1 = points[i][0] - points[last][0];
        double y1 = points[i][1] - points[last][1];
        double x2 = points[next][0] - points[i][0];
        double y2 = points[next][1] - points[i][1];
        double theta1 = atan2(y1, x1)*180/3.1415926358979323;
        double theta2 = atan2(y2, x2)*180/3.1415926358979323;
        angles[i] = (180 + theta1 - theta2 + 360);
        while(angles[i]>360)angles[i]-=360;
    }
}

显然,如果你正在使用某种数据结构来存储你的点,你将需要用你的数据结构替换double points[][2]以及对它的引用。


2
你可以使用 atan2 函数获取完整的角度范围 (-Pi..Pi)
atan2(crossproduct, dotproduct)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接