C++在QT中通过坐标计算角度的方法
下面展示一些 内联代码片
。
#define M_PI (3.14159265358979323846)
double get_angle(double x1, double y1, double x2, double y2, double vertexX, double vertexY)
{
double theta = atan2(x1 - vertexX, y1 - vertexY) - atan2(x2 - vertexX, y2 - vertexY);
if (theta > M_PI)
theta -= 2 * M_PI;
if (theta < -M_PI)
theta += 2 * M_PI;
theta = abs(theta * 180.0 / M_PI);
return theta;
}
vertexX,vertexY是顶点,x1,y1,x2,y2是另外两个点