我正在尝试计算红色显示的值,即内角。
我有一个点数组,表示线相交的位置,并尝试使用点积,但它只返回最小的角度。我需要完整范围的内角(0-359),但似乎找不到符合这个标准的方法。
我正在尝试计算红色显示的值,即内角。
我有一个点数组,表示线相交的位置,并尝试使用点积,但它只返回最小的角度。我需要完整范围的内角(0-359),但似乎找不到符合这个标准的方法。
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]
以及对它的引用。
(-Pi..Pi)
:atan2(crossproduct, dotproduct)