我偶尔会遇到这种情况,但总是忘记怎么做。
经常出现的事情之一。
另外,将以弧度表示的角度转换为度数并再转换回来的公式是什么?
radians = degrees * (pi/180)
degrees = radians * (180/pi)
至于实现,主要问题是您希望 pi 的值有多精确。有一些相关的讨论这里
以弧度表示的完整圆是 2*pi。完整的圆(以度为单位)为 360。要从度数转换为弧度,则为 (d/360) * 2*pi,或 d*pi/180。
x 弧度 - > x*180/pi
x 弧度度 -> x*pi/180
我猜你是否想为此创建一个函数[用 PHP]:
function convert($type, $num) {
if ($type == "rads") {
$result = $num*180/pi();
}
if ($type == "degs") {
$result = $num*pi()/180;
}
return $result;
}
是的,可能可以写得更好。
在 javascript 中你可以这样做
radians = degrees * (Math.PI/180);
degrees = radians * (180/Math.PI);
这对我来说已经足够好了:)
// deg2rad * degrees = radians
#define deg2rad (3.14159265/180.0)
// rad2deg * radians = degrees
#define rad2deg (180/3.14159265)
.NET8:https://github.com/dotnet/runtime/issues/86402
double.RadiansToDegrees(1);
float.DegreesToRadians(1);
180 度 = PI * 弧度
360度是2*PI弧度
您可以在以下位置找到转换公式:http://en.wikipedia.org/wiki/Radian#Conversion_ Between_radians_and_ Degrees。
360 度 = 2*pi 弧度
这意味着 deg2rad(x) = x*pi/180 且 rad2deg(x) = 180x/pi;
pi 弧度 = 180 度
所以 1 度 = pi/180 弧度
或 1 弧度 = 180/pi 度
这里是一些使用
rad(deg)
、deg(rad)
以及两个更有用的函数扩展 Object 的代码:getAngle(point1,point2)
和 getDistance(point1,point2)
,其中一个点需要具有 x
和 y
属性。
Object.prototype.rad = (deg) => Math.PI/180 * deg;
Object.prototype.deg = (rad) => 180/Math.PI * rad;
Object.prototype.getAngle = (point1, point2) => Math.atan2(point1.y - point2.y, point1.x - point2.x);
Object.prototype.getDistance = (point1, point2) => Math.sqrt(Math.pow(point1.x-point2.x, 2) + Math.pow(point1.y-point2.y, 2));
radians = (degrees/360) * 2 * pi