Creating an event distribution of points on a sphere

Hi folks,

I’m trying to work out how to evenly distribute a set of points on a sphere.

I’m using this method

function PointsOnSphere(n)
{

var upts = new Array();

var inc : float = Mathf.PI * (3 - Mathf.Sqrt(5));

var off : float = 2.0 / n;

var x : float;

var y : float;

var z : float;

var r : float;

var phi : float;

for (var i = 0; i < n; i++)

{

y = i * off - 1 + (off /2);

r = Mathf.Sqrt(1 - y * y);

phi = i * inc;

x = Mathf.Cos(phi) * r;

z = Mathf.Sin(phi) * r;

upts.Push(Vector3(x, y, z));

}

var pts : Vector3[] = upts.ToBuiltin(Vector3);

return pts;

I’m trying to recreate this in the shader editor like so

but this is the result I get

298221-2.png

Any thoughts on what I might be doing wrong?

Hi, your math is wrong. Try using spherical coordinates. So you would need two angles and a radius to describe a sphere, if you use only one angle you will get circles/cylinders. So

x = r * sin "theta" * cos "phi"

y = r * sin "theta" * sin "phi"

z = r * cos "theta"

Where r is constant, “theta” goes from 0 to pi and “phi” goes from 0 to 2*pi (imagine you got a point in a distance of r to another point (center) and then rotate this point 180 degree around the center. That would give you a half circle. Then you would rotate that whole half circle by 360 degree and would get a sphere):

Hi chrudimer,

Thanks for your answer :slight_smile:

Just to get clarity on the math above is it

x = r*(sin(theta)*cos(phi)) ?

Here is the post i’m referencing to work this out:

I’m using the Fibonacci method described but I’m think about trying out the golden ratio method.

That looks similar to what you’re describing

except they use sin(theta)*sin(phi) for y and they don’t reference r

x, y, z = cos(theta) * sin(phi), sin(theta) * sin(phi), cos(phi);

Yeah sorry, should be sin(theta) * sin(phi), I corrected it above. And yes x = r * (sin(theta)*cos(phi))

The r is the radius of the sphere, so if you don’t use an r, the radius will be 1.