# Creating an event distribution of points on a sphere

**URL:** <https://forums.unrealengine.com/t/creating-an-event-distribution-of-points-on-a-sphere/462717>\
**Category:** Asset Creation\
**Tags:** unreal-engine, question\
**Created:** [March 21, 2020, 7:56pm UTC](https://forums.unrealengine.com/t/creating-an-event-distribution-of-points-on-a-sphere/462717 "2020-03-21T19:56:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrs300](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jrs300](https://forums.unrealengine.com/u/jrs300)\
**Post date:** [March 21, 2020, 7:56pm UTC](https://forums.unrealengine.com/t/creating-an-event-distribution-of-points-on-a-sphere/462717/1 "2020-03-21T19:56:31Z")

</div>

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

 ![298220-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/3/3/e33ca32b330cba68038ecf9963c7cfd6b955bf5b.png)

but this is the result I get

![298221-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/d/e/3de88bd5195f3bfa3387fad30267d520d33356d9.png)

Any thoughts on what I might be doing wrong?

---

<div class="post-metadata">

**Author:** ![chrudimer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chrudimer/32/918651_2.png) [@chrudimer](https://forums.unrealengine.com/u/chrudimer)\
**Post date:** [March 21, 2020, 8:53pm UTC](https://forums.unrealengine.com/t/creating-an-event-distribution-of-points-on-a-sphere/462717/2 "2020-03-21T20:53:24Z")

</div>

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):

 ![298225-rotate-by-theta-so-pi.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/1/8/318834a1ed5802e2dce7804654ae312e6f231a51.png)

 ![298223-half-circle-180degree-theta.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/4/d/64dbc9f00092cde18a8ee0a67295ce681376a5f6.jpeg)

 ![298224-rotating-that-by-phi-2pi-creates-sphere.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/1/1/41115544becfd81947d1d92cd7949e5a532b21aa.png)

---

<div class="post-metadata">

**Author:** ![jrs300](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jrs300](https://forums.unrealengine.com/u/jrs300)\
**Post date:** [March 21, 2020, 9:52pm UTC](https://forums.unrealengine.com/t/creating-an-event-distribution-of-points-on-a-sphere/462717/3 "2020-03-21T21:52:54Z")

</div>

Hi chrudimer,

Thanks for your answer 🙂

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:

> <https://stackoverflow.com/questions/9600801/evenly-distributing-n-points-on-a-sphere>

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);

---

<div class="post-metadata">

**Author:** ![chrudimer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chrudimer/32/918651_2.png) [@chrudimer](https://forums.unrealengine.com/u/chrudimer)\
**Post date:** [March 21, 2020, 10:24pm UTC](https://forums.unrealengine.com/t/creating-an-event-distribution-of-points-on-a-sphere/462717/4 "2020-03-21T22:24:59Z")

</div>

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.
