计算角度并将其转换为度数
Calculating the angle and converting it to degrees
我无法获得准确的角度测量值并将其转换为度数。
我首先计算了距离:
double distance = Math.Sqrt(deltax + deltay);
Console.WriteLine("Distance :" + Math.Round(distance, 3));
Console.WriteLine("");
然后尝试计算角度:
double angle = Math.Atan2(deltay, deltax);
double RadiantoDegree = (angle * 180 / Math.PI);
Math.Round((decimal)angle, 3);
Console.WriteLine("Angle :" + angle)
对于 x1=2、y1=2、x2=1、y2=1 等输入,角度应为 -135.000 度。
问题是您没有使用 angle
的转换值。
你可以这样做:
angle = (angle * 180 / Math.PI);
而不是定义 RadiantToDegree
但从不使用它。所以现在发生的是你基本上只是以弧度打印你的角度。
我无法获得准确的角度测量值并将其转换为度数。
我首先计算了距离:
double distance = Math.Sqrt(deltax + deltay);
Console.WriteLine("Distance :" + Math.Round(distance, 3));
Console.WriteLine("");
然后尝试计算角度:
double angle = Math.Atan2(deltay, deltax);
double RadiantoDegree = (angle * 180 / Math.PI);
Math.Round((decimal)angle, 3);
Console.WriteLine("Angle :" + angle)
对于 x1=2、y1=2、x2=1、y2=1 等输入,角度应为 -135.000 度。
问题是您没有使用 angle
的转换值。
你可以这样做:
angle = (angle * 180 / Math.PI);
而不是定义 RadiantToDegree
但从不使用它。所以现在发生的是你基本上只是以弧度打印你的角度。