2015-03-02 49 views
2

我试图计算在红色图片中显示的值,即内角。不规则多边形内角与角度> 180

我已经有了一个点的阵列,这些点相交并试图使用点积,但它只返回最小的角度。我需要全方位的内部角度(0-359),但似乎找不到符合此标准的很多内容。

arrow

+0

[This question](http://stackoverflow.com/questions/28730855/how-to-compute-directional-angle-between-two-2d-vectors-in-matlab/28732160#28732160)有答案MATLAB语言。不过,我认为你仍应该能够遵循它 – eigenchris 2015-03-02 23:28:23

回答

2

假设你的角度为标准逆时针格式,下面应该工作:

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]并且继续请参考您的数据结构。

1

您可以获取全角度范围(-Pi..Pi)与ATAN2函数:

atan2(crossproduct, dotproduct)