已知两点,求角度

float angle(float x1, float y1, float x2, float y2)
{
float angle_temp;
float xx, yy;
xx = x2 - x1;
yy = y2 - y1;
if (xx == 0.0)
angle_temp = PI / 2.0;
else
angle_temp = atan(fabs(yy / xx));
if ((xx < 0.0) && (yy >= 0.0))
angle_temp = PI - angle_temp;
else if ((xx < 0.0) && (yy < 0.0))
angle_temp = PI + angle_temp;
else if ((xx >= 0.0) && (yy < 0.0))
angle_temp = PI * 2.0 - angle_temp;
return (angle_temp);
}

你可能感兴趣的:(C++,c++)