58 views (last 30 days)

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

Roger Stafford
on 11 Jun 2016

Edited: Roger Stafford
on 11 Jun 2016

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.

Image Analyst
on 12 Jun 2016

+1 vote. (David you too can also vote as well as accept an answer).

Roger Stafford
on 12 Jun 2016

Sign in to comment.

Image Analyst
on 11 Jun 2016

John D'Errico
on 11 Jun 2016

You say that you want it "random" in some sense. But then your comment indicates that you don't want areas where there are no points. The problem is that at SOME fine-ness, a random sampling will always have holes in it. That is the nature of randomnity (I may have just coined that word.)

If you choose to bin things so that there are some points in one bin, and others in an adjacent bin, then there is a decent chance that the points in both bins 1 and 2, by random chance, may all lie away from the common edge. If you have enough bins, the chance of this happening in SOME bin are actually very good. In that case, you will perceive a hole in the sampling.

This will happen not matter how you do any random sampling. So really, you don't want a random sampling, even though you say you do.

In fact, you probably want some variation of sampling that has all points in some way uniformly distant from their neighbors. I'd suggest the idea of looking for a uniform tiling of a sphere, so maybe this as a starting point.

Image Analyst
on 11 Jun 2016

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.