Search code examples
matlabplotspiral

Spiral of non-overlapping circles


I want to create a spiral of circle markers which never overlap with each other. This is what I got so far, but it overlaps the first markers, and the last ones are too far apart from each other.

t = pi : pi/20 : 20*pi;
t = asind(1./t);
r = t;
x = r .* cos(t);
y = r .* sin(t);
plot(x,y,'o-');
axis equal; hold on 

Plotting without redefining t as asinf(1/t) as follows, is shown in the second plot.

t = pi : pi/20 : 20*pi;
r = t;
x = r .* cos(t);
y = r .* sin(t);
plot(x,y,'o-');

Any ideas on how does the spacing of the angles t must be to accomplish that the markers don't overlap?

enter image description here

enter image description here


Solution

  • Try this:

    syms s;
    scale = 10;
    l = scale/2 : scale/2 : 40*scale;
    t = double(arrayfun(@(y) vpasolve((0.5*(s*sqrt(1+s^2)+asinh(s)))==y,s), l));
    x = t .* cos(t);
    y = t .* sin(t);
    plot(x,y,'o-');
    pbaspect([1 1 1]);
    axis(scale*[-5 5 -5 5])
    

    The idea is to parameterize using the arclength of the curve. The arclength of this spiral is l=1/2*(t*sqrt(1+t*t)+asinh(t)) (can be found using Matlab symbolic integration). To place points uniformly, we do a uniform sampling of the arclength, and find the corresponding t by solving the equation. Since it cannot be solved easily symbolically, we use a numerical solver.

    Note that the scale and the aspect ratio of the plot is really important for it to look uniform and non-overlapping. This is why I added axis/ratio definition. Since each point is solved numerically, it can take quite some time to evaluate. There may be a faster way to do it, but at least you have a result.

    I obtain the following result:

    Uniform Sampling Spiral