/** * Sets this to a random rotation obtained from a completely uniform distribution. */ public Quaternion randomize (Random rand) { // pick angles according to the surface area distribution return fromAngles(MathUtil.lerp(-FloatMath.PI, +FloatMath.PI, rand.nextFloat()), FloatMath.asin(MathUtil.lerp(-1f, +1f, rand.nextFloat())), MathUtil.lerp(-FloatMath.PI, +FloatMath.PI, rand.nextFloat())); }
/** * Sets this to a random rotation obtained from a completely uniform distribution. */ public Quaternion randomize (Random rand) { // pick angles according to the surface area distribution return fromAngles(MathUtil.lerp(-FloatMath.PI, +FloatMath.PI, rand.nextFloat()), FloatMath.asin(MathUtil.lerp(-1f, +1f, rand.nextFloat())), MathUtil.lerp(-FloatMath.PI, +FloatMath.PI, rand.nextFloat())); }
@Override // from IQuaternion public Vector3 toAngles (Vector3 result) { float sy = 2f*(y*w - x*z); if (sy < 1f - MathUtil.EPSILON) { if (sy > -1 + MathUtil.EPSILON) { return result.set(FloatMath.atan2(y*z + x*w, 0.5f - (x*x + y*y)), FloatMath.asin(sy), FloatMath.atan2(x*y + z*w, 0.5f - (y*y + z*z))); } else { // not a unique solution; x + z = atan2(-m21, m11) return result.set(0f, -MathUtil.HALF_PI, FloatMath.atan2(x*w - y*z, 0.5f - (x*x + z*z))); } } else { // not a unique solution; x - z = atan2(-m21, m11) return result.set(0f, MathUtil.HALF_PI, -FloatMath.atan2(x*w - y*z, 0.5f - (x*x + z*z))); } }
@Override // from IQuaternion public Vector3 toAngles (Vector3 result) { float sy = 2f*(y*w - x*z); if (sy < 1f - MathUtil.EPSILON) { if (sy > -1 + MathUtil.EPSILON) { return result.set(FloatMath.atan2(y*z + x*w, 0.5f - (x*x + y*y)), FloatMath.asin(sy), FloatMath.atan2(x*y + z*w, 0.5f - (y*y + z*z))); } else { // not a unique solution; x + z = atan2(-m21, m11) return result.set(0f, -MathUtil.HALF_PI, FloatMath.atan2(x*w - y*z, 0.5f - (x*x + z*z))); } } else { // not a unique solution; x - z = atan2(-m21, m11) return result.set(0f, MathUtil.HALF_PI, -FloatMath.atan2(x*w - y*z, 0.5f - (x*x + z*z))); } }