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

조회 수: 3 (최근 30일)
David Pesetsky
David Pesetsky 2016년 6월 11일
댓글: Roger Stafford 2016년 6월 12일
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
Roger Stafford 2016년 6월 11일
편집: Roger Stafford 2016년 6월 11일
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.
  댓글 수: 3
Image Analyst
Image Analyst 2016년 6월 12일
Another very clever gem from Roger. He's amazing. So clever that I added it to the FAQ.
+1 vote. (David you too can also vote as well as accept an answer).
Roger Stafford
Roger Stafford 2016년 6월 12일
@Image Analyst: Thank you for putting my solution on FAQ. However, one statement there isn’t correct: “At this point the points can be anywhere inside a solid square cube.” The points were generated by ‘randn’, not ‘rand’, and they can lie anywhere in the entire infinite three-dimensional universe in accordance with the independent three dimensional normal distribution. I have taken the liberty of altering that line to read: “At this point the points can be anywhere in 3D space.”

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Image Analyst
Image Analyst 2016년 6월 11일
Calculate phi and theta for each of the points. Then bin them and take a specified number of points from each bin.
  댓글 수: 2
David Pesetsky
David Pesetsky 2016년 6월 11일
I'm hoping for more of a populating function because there will be areas where no points are in a bin that I want some points in.
David Pesetsky
David Pesetsky 2016년 6월 11일
I think if I use rand to return random x's, y's, and z's, then find the vector length of each and scale each to the sphere radius I want, that should work.
Not sure of the elegant way to code that, but seems like it will work.

댓글을 달려면 로그인하십시오.


John D'Errico
John D'Errico 2016년 6월 11일
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.
  댓글 수: 1
David Pesetsky
David Pesetsky 2016년 6월 11일
Almost. I cannot control the density of the surface points:
[B,V] = bucky;
x=V(:,1);
y=V(:,2);
z=V(:,3);
k = boundary(x,y,z,0);
trisurf(k,x,y,z,'Facecolor','red','FaceAlpha',0.1);

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2016년 6월 11일
Use the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_set_of_random_locations_within_a_circle.3F It should be a simple matter to add a "z" vector and additional angle. One other change you need to make is to make the radius a constant instead of a list of random numbers.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by