不规则多边形的内角,其角度> 180 [英] interior angles of irregular polygon with angles > 180
问题描述
我正在尝试计算图中红色显示的值,即内角.
I'm trying to calculate the values shown in the picture in red i.e. the interior angles.
我得到了直线相交的点的数组,并尝试使用点积,但是它只返回最小的角度.我需要全范围的内角(0-359),但似乎找不到满足此条件的东西.
I've got an array of the points where lines intersect and have tried using the dot-product but it only returns the smallest angles. I need the full range of internal angles (0-359) but can't seem to find much that meets this criteria.
推荐答案
假设您的角度为标准的逆时针格式,则应该可以进行以下操作:
Assuming your angles are in standard counterclockwise format, the following should work:
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]
及其引用.
Obviously, if you are using some sort of data structure for your points, you will want to replace double points[][2]
and references to it with references to your data structure.
这篇关于不规则多边形的内角,其角度> 180的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!