question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: uniform random rotation sampling

See original GitHub issue

I’d like to be able to apply a random rotation to an object. There are a couple of ways I initially thought to do this: random euler angles, random (normalized) rotation matrix values, and random (normalized) quaternion values.

The problem is, none of these random rotation methods sample uniformly from SO(3), the set of all 3D rotations. From the (admittedly, limited) research I’ve done, it appears that there are two methods that do sample uniformly from SO(3):

  1. Generate a random point along the surface of a unit sphere, convert the point to a vector, and combine the vector with a random rotation 0 < u < 2*PI to form an axis-angle rotation representation. For generating a random point on the surface of a unit sphere, see the following: https://mathworld.wolfram.com/SpherePointPicking.html

  2. Generate a random quaternion. The method described in the link below samples uniformly from SO(3): http://planning.cs.uiuc.edu/node198.html

Method 2 seems easy enough, and I plan to use it in my application.

Reading through some of the discussion in https://github.com/mrdoob/three.js/issues/18996, it seems like this may be a compelling enough use case to either:

  1. Add a random method to the quaternion class that implements the logic described in method 2 above, or

  2. Add this logic to examples/jsm/math/Sampling.js or examples/jsm/math/Random.js, as discussed in https://github.com/mrdoob/three.js/issues/18996#issuecomment-606243878

What do you all think? I’d understand if you think it’s too application-specific, but I figured I’d raise the idea anyway. I’d be happy to write a PR for either solution if you’d like.

All the best, Cameron

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:17 (12 by maintainers)

github_iconTop GitHub Comments

4reactions
speiggcommented, Apr 12, 2020

How is this (too) complicated?

static randomQuaternion = (() => {
    const _2PI = Math.PI * 2;
    const V_001 = new Vector3(0,0,1)
    const twist = new Quaternion
    const swing = new Quaternion
    const swingAxis = new Vector3
    return function randomQuaternion(outQuat, twistScale = 1, swingScale = 1) {
            const twistMagnitude = ( Math.random() - 0.5 ) * _2PI * twistScale 
            const swingDirection = Math.random() * _2PI
            const swingMagnitude = Math.random() * Math.PI * swingScale
            swingAxis.set(1,0,0).applyAxisAngle(V_001, swingDirection)
            twist.setFromAxisAngle(V_001, twistMagnitude)
            swing.setFromAxisAngle(swingAxis, swingMagnitude)
            return outQuat.multiplyQuaternions(swing, twist)
    }
})()
4reactions
makccommented, Apr 6, 2020

that would be non-uniform, @mrdoob

Read more comments on GitHub >

github_iconTop Results From Across the Web

Random Rotation Ensembles
In order to perform a random rotation, we uniformly sample over all feasible rotations. Randomly rotating each angle in spherical coordinates does not...
Read more >
Uniformly sampled 3D rotation matrices
Sampling 2D rotations uniformly is simple: rotate by an angle ... """Apply a random rotation in 3D, with a distribution uniform over the....
Read more >
Scripting API: Random.rotationUniform - Unity - Manual
Returns a random rotation with uniform distribution (Read Only). ... fibration to return a random Quaternion within a uniformly distributed selection space.
Read more >
tf.keras.layers.RandomRotation | TensorFlow v2.11.0
A preprocessing layer which randomly rotates images during training.
Read more >
Na¨ıveNa¨ıve sampling (a) and uniform sampling (b) of SO(3 ...
There are a total of 5000 rotation samples, with each sample visualized as an ... sampling-based motion planning algorithms typically require a distance ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found