使用效果
C++通过三点坐标,获取夹角
输入 A(x1,y1) B(x2,y2) C(x3,y3) 三点, 获取角 ACB
/*
get angle ACB, point C is the center point
A(x1,y1)
B(x2,y2)
C(x3,y3)
*/
double get_angle_with_points(double x1, double y1, double x2, double y2, double x3, double y3)
{
double theta = atan2(x1 - x3, y1 - y3) - atan2(x2 - x3, y2 - y3);
if (theta > M_PI)
theta -= 2 * M_PI;
if (theta < -M_PI)
theta += 2 * M_PI;
theta = abs(theta * 180.0 / M_PI);
if(y2<=y3) {
theta = 360.0 - theta;
}
return theta;
}