MATLAB: [x,y,z] = sphere, except uniform or random distributed points

sphereuniform points in space

Hi,
I like the [x,y,z] = sphere; function, except would like the points returned to be more of a random or uniform sampling of the surface. It seems to have tighter spacing at the "poles", and sparse at the "equator".
Thanks a lot. Dave

Best Answer

Here is a way to generate random points on a sphere that is statistically uniform.
r = randn(3,n); % Use a large n
r = bsxfun(@rdivide,r,sqrt(sum(r.^2,1)));
x = r(1,:);
y = r(2,:);
z = r(3,:);
If you want a radius other than one, multiply the second line by the desired radius, R.
Note: If you use 'rand' rather than 'randn' in the above, the distribution will not be statistically uniform.