private double Angle(Coordinate cen, Coordinate first, Coordinate second)
{
const double M_PI = 3.1415926535897;
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);
if (ma_val * mb_val == 0) return double.NaN;
double cosM = v1 / (ma_val * mb_val);
//弧度专为角度
double angleAMB = Math.Acos(cosM) * 180 / M_PI;
return angleAMB;
}
比较简单,不再赘述。