What am I getting wrong with trying to create a sphere mesh using a golden spiral?

9 views (last 30 days)
I have included my code, as well as an image that shows the issue. I am trying to create an equally distant number of points across the surface of a sphere. The Fibonacci method I happened upon isn't perfect, but at least I could understand how to get it working at all in Matlab. A better method would be great, but I would like to get this working first.
However, as you can see, the code I am using doesn't create an equal number of points. For some reason, there is a line of holes at longitude 0 where there are no points. Why does this happen? I changed it a bit so it starts at 0 rather than at 1, but that didn't help much.
  2 Comments
John D'Errico
John D'Errico on 8 Jul 2020
Edited: John D'Errico on 8 Jul 2020
What did you base the code upon? Why do you think it should produce equidistant points on the sphere? The image you show does not appear to be remotely uniform so if that is your goal - a uniform mesh on the sphere, then why not look for something better? Anyway, the result is just a scattered set, a point cloud, so not a mesh at all.
Is all you are looking to do, something like this?
So, at least a moderately uniform tiling on a sphere? The example I show is not that terribly uniform, but it is not too bad either.
This?
Or is it really a quasi-uniform sampling of the sphere, and you are not interested in a tiling thereof?
What are you looking to do? What is the goal here?
Isaac Haeffner
Isaac Haeffner on 8 Jul 2020
What I would like is a large, variable number of points on the sphere that are all as equidistant as possible. I need them to be exported to a txt file in two columns.
Everything else I found was in a different language and I couldn't understand the methods that were being used in order to convert them.
This is what I was basing it on: http://blog.marmakoide.org/?p=1

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 8 Jul 2020
Edited: John D'Errico on 8 Jul 2020
So you are not looking for a mesh at all, just a uniform sampling? Simplest might be to use a random sampling, with a twist. That is, just discard those points that are most closely spaced.
ntarget = 250; % 250 final points, quasi-maximally distant on the unit sphere.
oversample = 6;
ninit = ntarget*oversample;
xyz = randn(ninit,3);
% rescale all points to lie on the surface of a unit sphere.
% this is appropriate because a muli-variate gaussian is rotationally symmetric.
xyz = xyz./sqrt(sum(xyz.^2,2));
% iteratively reduce the set, by excluding a point if it is too close
% to its neighbors.
nred = 10;
for ind = 1:(ninit-ntarget)/nred
D = pdist(xyz);
[Dmin,I] = mink(D,nred);
n = size(xyz,1);
bins = cumsum([1,(n-1):-1:1]);
ir = discretize(I,bins);
jr = ind - (ir - 1).*(2*n - ir)/2 + ir;
xyz(ir,:) = [];
end
plot3(xyz(:,1),xyz(:,2),xyz(:,3),'.')
The code is a bit of a hack. Probably as soon as I submit this post I'll have a much cleaner version. But it produces points that are reasonably close to as uniformly far apart as possible.
  1 Comment
Isaac Haeffner
Isaac Haeffner on 8 Jul 2020
Edited: Isaac Haeffner on 9 Jul 2020
for i = 1:ntarget
longlat(i,1) = asin(xyz(i,3));
longlat(i,2) = atan2(xyz(i,2),xyz(i,1));
longlat(i,1) = ((rad2deg(longlat(i,1)))+90)*2;
longlat(i,2) = rad2deg(longlat(i,2));
end
That works just as well as what I had. However, when I convert it into longitude and latitude, it is still balanced away from longitude 0.
This is the code I am using to convert it from xyz to longitude/latitude.
Edit: Nevermind, I got it working! Thanks!

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!