前言
原理很简单,大家初中都学过的,但,由于Java中的sin和cos传入的值是弧度,我一开始一直用角度,导致得不出对应的值。
摘抄于此,方便自己查阅。
好记性不如烂笔头
正文
PS:本文摘抄,只是文本继续一定编辑和整理。
圆心坐标 :(x0, y0)
半径 : r
角度: a
设圆上任何一点坐标为:(x1, y1)
根据已知规则,得出如下公式:
x1 = x0 + r * cos( a )
y1 = y0 + r * sin( a )
需要注意,Java中Math的cos(angle)和sin(angle)传入angle的单位是弧度。
转弧度
public static double toRadians(double angdeg) {
return angdeg / 180.0 * PI;
}
转角度
public static double toDegrees(double angrad) {
return angrad * 180.0 / PI;
}
因此,我们需要把角度进行转换为弧度。
下面是java实现的代码:
Y1 = X0 + Radius * Math.cos(Math.toRadians(angle));
Y1 = Y0 + Radius Math.sin(Math.toRadians(angle));
参考文章
© 版权声明