我有Vector2
:
Vector2 v = new Vector2(1,0);
如何随机旋转此向量(约(0,0)),在[0,360]度范围内均匀分布?
答案 0 :(得分:2)
要逆时针旋转矢量v
:
Vector2 v = new Vector2( 1,0 );
Random rnd = new Random();
double rotationAngle = 2.0 * Math.PI * rnd.nextDouble();
Vector2 vRotated = new Vector2(
(v.x)*Math.cos(rotationAngle) + (v.y)*Math.sin(rotationAngle),
(v.y)*Math.cos(rotationAngle) - (v.x)*Math.sin(rotationAngle)
);
转型数学来自here