# Return an array of evenly distributed points on a sphere give Radius and Origin. [duplicate]

This question already has an answer here:

Given a sphere of radius $r$, and origin $x,y,z$ what is the simplest way I can generate an evenly distributed array of points on the sphere $(x_1,y_1,z_1),(x_2,y_2,z_2),\cdots(x_n,y_n,z_n)$.

Note I will be writing this as a function in Javascript, if it is any help.

EDIT

Essentially, I want to create a perfectly symmetrical shape with $X$ number of vertices that fits perfectly inside a sphere with radius $R$.

-

## marked as duplicate by Rahul, Macavity, user91500, hardmath, Najib IdrissiJun 6 '14 at 7:41

Do you want a regular distribution of points, or do you want to pick the points randomly from a uniform distribution? –  Brian M. Scott Jan 15 '13 at 20:54
You can't equidistribute points on a sphere unless they are the corners of a Platonic solid, so $n=4,6,8,12,20$. Do you mean randomly distributed points with constant density? If the second, you could see mathworld or Google "random distribution on sphere" –  Ross Millikan Jan 15 '13 at 20:55
Random will work perfectly., really just whichever way gets the job done with the least amount of overhead to perform the calculation. Thanks @BrianM.Scott –  Jonathan Coe Jan 15 '13 at 20:56
It won't be symmetric if the points are random. But it will "on average be symmetric" whatever that means. –  Ross Millikan Jan 15 '13 at 21:01
If the aim is to pick random points from a uniform distribution on the sphere, shouldn't this be closed as a duplicate of How to find a random axis or unit vector in 3D? If the aim is to find a symmetrical set of equally spaced points on the sphere, see the answers under Which tessellation of the sphere yields a constant density of vertices? –  Rahul Jan 15 '13 at 21:20

Use a uniform random number generator to generate an angle $\theta\in[0,2\pi)$ (essentially a longitude) and a $z\in[-1,1]$; the surface area cut by the planes $z=a$ and $z=b$ depends only on $|a-b|$, provided that $a,b\in[-1,1]$, so you get a uniform distribution.

Once you have $\theta$ and $z$, the point is $\left\langle\sqrt{1-z^2}\cos\theta,\sqrt{1-z^2}\sin\theta,z\right\rangle$ in rectangular coordinates.

-

At the end of the Mathworld article it says you can generate three Gaussian random variables $x,y,z$. Then $r=\sqrt {x^2+y^2+z^2}$ and $\frac xr, \frac yr, \frac zr$ are equally distributed on the unit sphere.

-


$$\large \color{#c00000}{\mbox{Below, we show a}\ \color{#000}{{\tt javascript}}\ \mbox{code that makes the job:}}$$ \begin{align} \end{align}

var TWOPI=2.0*Math.PI;

function randSphereSurface(r)// r: radius
{
var phi=TWOPI*Math.random();
var theta=2.0*Math.asin(Math.sqrt(Math.random()));
var x=r*Math.sin(theta);
var y=x*Math.sin(phi);
x*= x*Math.cos(phi);
var z=r*Math.cos(theta);

return {"x":x,"y":y,"z":z};
}


Use as

var p=randSphereSurface(5.0); // sphere of radius 5.
document.write("The point is (", + p.x + "," + p.y + "," + p.z + ")");

-