lundi 28 septembre 2020

Three.js 3D random Vectors with random rotation have a strange directional bias

I have been experimenting with Three.js. I'm new to working with libs like this, but I created a short script that takes a random source Vector, generates a random direction in all 3 dimensions, and then clones and translates that vector many times over with a random angle adjustment (simulating e.g. a random space flight cycle)

The following js-bin shows a set of 100 examples of flight cycles (which in turn have 300 "movements" each) visualized in 2 dimensions only. Each color represents a unique flight cycle.

https://jsbin.com/tiwoweyolo/edit?js,output

If I remove the X and Y axis from the random quaternion rotation that occurs on every move, and apply only to Z (which I believe would be a true 2D simulation) the random cycles seem truly random. Try it yourself. Change the setFromAxisAngle() call to only rotate round Z like so:

q.setFromAxisAngle(new THREE.Vector3(0, 0, 1), range(-cone, cone));

The cone angle is my way of ensuring each new vector is generally aimed away from the previous and away from the origin. I don't mind a few loop backs here and there.

Making this change and running the JS and viewing the output window you really see a random set of "flights".

BUT if you noticed, the original js-bin which rotates as follows:

q.setFromAxisAngle(new THREE.Vector3(1, 1, 1), range(-cone, cone));

...there is incredible bias from top left to bottom right. In fact you see very few flights at all travelling bottom left and top right.

Originally I thought this was just an artifact of trying to visualize 3 dimensional coordinates in 2D. However, surely anything that was X,Y in the emptier quadrants would not be affected by Z.

Why is this bias occurring, is it occurring at all, or is it an artifact of rendering 3d vectors in 2D?

If there is a bias, how do I make this more random?




Aucun commentaire:

Enregistrer un commentaire