Math.sin AND Math.cos
2020-02-25 本文已影响0人
Lennie_S
1.因为Math.sin() , Math.cos()必须带入弧度计算,所以我们需要将角度转换为弧度。角度转弧度公式:弧度 = 2 * π / 360 * 角度 = π / 180 * 角度。(角度 = 180 / π * 弧度)
该圆上每个点的X坐标 = a + Math.sin(弧度) * r 、 Y坐标 = b + Math.cos(弧度) * r。

例:假设圆形为原点(0,0)。
弧度 = 0;
ball.x = Math.sin(angle) * radius; //计算x坐标 核心代码,其他代码只是复制的一截,不要直接复制
ball.y = Math.cos(angle) * radius; //计算y坐标
})();
3.
