/// <summary>
/// 求角度
/// </summary>
/// <param name="cen"></param>
/// <param name="first"></param>
/// <param name="second"></param>
/// <returns></returns>
public static double GetAngleWith360(DPoint3 cen, DPoint3 first, DPoint3 second)
{
//计算角度
double ma_x = first.x - cen.x;
double ma_y = first.y - cen.y;
double mb_x = second.x - cen.x;
double mb_y = second.y - cen.y;
double v1 = (ma_x * mb_x) + (ma_y * mb_y);
double ma_val = Math.Sqrt(ma_x * ma_x + ma_y * ma_y);
double mb_val = Math.Sqrt(mb_x * mb_x + mb_y * mb_y);
double cosM = v1 / (ma_val * mb_val);
if (cosM < -1)
{
cosM = -1;
}
else if (cosM > 1)
{
cosM = 1;
}
double angleAMB = Math.Acos(cosM) * 180 / Math.PI;
//计算两条线向量的顺逆时针方向
DPoint3 lineFirst = new DPoint3(first.x - cen.x, first.y - cen.y, 0);
DPoint3 lineSecond = new DPoint3(second.x - cen.x, second.y - cen.y, 0);
bool isClockwise = lineFirst.x * lineSecond.y - lineSecond.x * lineFirst.y < 0;
if (isClockwise)
{
angleAMB = 360 - angleAMB;
}
return angleAMB;
}
版权声明:本文为qq_29621089原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。