6
$\begingroup$

I want to create a spherical distribution of points. At the moment I use this node setup.

enter image description here

But this creates noticeable higher densities on diagonals

enter image description here

It should be more uniform like this

enter image description here

What's a better method for creating a spherical distribution?

$\endgroup$
3
  • $\begingroup$ your question isn't clear. What do you mean with better? you could use e.g. a noise texture, but it depends, what exactly you wanna achieve. So please tell us how it should look like and maybe add an image of your target. And your node tree isn't complete as well, so pls provide a node tree which you used so we see at least what you did and how we can improve it. thx $\endgroup$
    – Chris
    Commented Sep 17, 2023 at 13:04
  • $\begingroup$ Plug that node into a set position node. But I've updated $\endgroup$
    – TheJeran
    Commented Sep 17, 2023 at 14:29
  • $\begingroup$ extremelearning.com.au/… $\endgroup$ Commented Mar 5 at 22:20

3 Answers 3

11
$\begingroup$

Discarding Approach

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

Proper Maths Approach

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

$\endgroup$
2
  • $\begingroup$ First result presents same issues as my method. Second one is great! Thank you blender wizard. $\endgroup$
    – TheJeran
    Commented Sep 17, 2023 at 15:24
  • 3
    $\begingroup$ @TheJeran nocebo. First solution is absolutely correct, must be. It's simple to reason about: you start with a uniform distribution in 3D space and then cut out a sphere out of it. $\endgroup$ Commented Sep 17, 2023 at 15:44
8
$\begingroup$

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:

enter image description here

  • Here I use many points created at the same position.
  • I rotate them with random values between $-\pi$ and $\pi$, so that they are positioned in a circle.
  • Then I rotate these positions again on a random axis so that the previously circularly positioned points form a sphere.
  • Finally I scale the positions with a value between $0$ and $1$ with another 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.


(Blender 3.6+)

$\endgroup$
3
  • 1
    $\begingroup$ I like the random axis approach. Take the cubic root of the magnitude for an even distribution (otherwise points clump near the center) i.imgur.com/7ONZ3T6.png $\endgroup$ Commented Sep 17, 2023 at 20:50
  • $\begingroup$ @MarkusvonBroady I actually thought that was intentional, that it gets denser towards the center (at least that's how it is in the example image), but that's a brilliant idea! $\endgroup$
    – quellenform
    Commented Sep 17, 2023 at 21:07
  • $\begingroup$ @quellenform In my use case I would like it to be denser near the center. But I think having uniform distribution is a good property as well $\endgroup$
    – TheJeran
    Commented Sep 18, 2023 at 7:25
5
$\begingroup$

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:

enter image description here

.. it's just interesting that there's no obvious visible bias? But I wouldn't trust it to do strict statistical sampling.

$\endgroup$
3
  • $\begingroup$ This is an amazing answer. The OP wanted points inside a sphere, which you can see by him scaling the vector, but the same can be applied here, with cubic root applied for uniform distribution (to avoid clumping in middle) i.imgur.com/KsUb13b.png Playing with the setup, all kinds of amazing effects can be achieved, basically you can get an even but perlin distribution with local clumping if you get the settings just right $\endgroup$ Commented Sep 17, 2023 at 21:13
  • $\begingroup$ As for checking the solutions, could actually be done in geonodes or python, I'll give it a go tomorrow. It's hard to inspect the distribution visually in 3D. $\endgroup$ Commented Sep 17, 2023 at 21:15
  • 1
    $\begingroup$ @MarkusvonBroady I'd like to get at least some inkling of why 'Gaussiam-like, SD doesn't matter' works.. that's weird, to me. Graphing the distribution of Blender's noise would be a nice little question in its own right. P.S. Cycles must do this all the time.. random distribution over the hemisphere.. I wonder how it does it. $\endgroup$
    – Robin Betts
    Commented Sep 18, 2023 at 6:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .