I want to create a spherical distribution of points. At the moment I use this node setup.
But this creates noticeable higher densities on diagonals
It should be more uniform like this
What's a better method for creating a spherical distribution?
I want to create a spherical distribution of points. At the moment I use this node setup.
But this creates noticeable higher densities on diagonals
It should be more uniform like this
What's a better method for creating a spherical distribution?
Spawn twice as many points as you need (I do an exact sphere radius vs cube radius ratio but you're not guaranteed to get enough points regardless how many spare points you generated due to the nature of randomness) inside a cube, and delete the excess that wasn't inside the sphere:
360-430 ms for 10 million points
Taken from here: Karthik Karanth: Generating Random Points in a Sphere
function getPoint() {
var u = Math.random();
var v = Math.random();
var theta = u * 2.0 * Math.PI;
var phi = Math.acos(2.0 * v - 1.0);
var r = Math.cbrt(Math.random());
var sinTheta = Math.sin(theta);
var cosTheta = Math.cos(theta);
var sinPhi = Math.sin(phi);
var cosPhi = Math.cos(phi);
var x = r * sinPhi * cosTheta;
var y = r * sinPhi * sinTheta;
var z = r * cosPhi;
return {x: x, y: y, z: z};
}
300-340 ms for 10 million points
In this particular case, you find that the Random Value
node is not as random as its name suggests....
If you want to solve this mathematically, use the wonderful answer from @Markus von Broady.
However, if you want to use fewer nodes, and stick to using Random Value
, you could solve it as follows:
Random Value
node, but a different value for Seed (!)You can also replace the first two operations with one, but it is important that at least one of your Random Value
has a different seed value.
No way intended to compete with Markus' answer, which is proved, where this is not.
Following the Math Exchange answer here, though, with its commentary, and told that (Blender) Perlin Noise's distribution is Gaussian-like, this is another shot at it:
.. it's just interesting that there's no obvious visible bias? But I wouldn't trust it to do strict statistical sampling.