Corey Iles Corey Iles - 10 months ago 95
C++ Question

How can I get a point on a spiral given degrees of rotation?

The closest thing I've found to help explain what I need is here in this question: Draw equidistant points on a spiral

However, that's not exactly what I want.

The spiral to draw is an archimedean spiral and the points obtained must be equidistant from each other.
(Quote: From the question linked above.)

This is precisely what I want given the Archimedean Spiral equation, equation.

There is a specific set of data a user can input, they are NOT based on spirals but circular figures in general. They are as follows: center point [X,Y,Z], radius, horizontal separation [can be called X separation, depends on figure], and vertical separation [can be called Y separation, depends on figure], and most importantly degrees of rotation. I'd like the horizontal separation to be the distance between consecutive points since they are the ones that need to be the same distance between each other. I'd also like vertical separation to be the distance between the 'parallel' curves.

So given that specific input selection (and yes, some can be ignored), how can I iterate through all of the consecutive, equidistant points it would take to reach the input degrees (which can be very large but is finite) and return the X and Y point of each point of those points?

Basically what I'm try to achieve is a loop from zero to the number of degrees in the input, given all of the rest of the input and my preferences noted above, and drawing a point for all of the equidistant, consecutive points (if you decide to represent using code, just represent the drawing using a 'print').

I'm having a hard time explaining, but I think I got it pretty much covered. The points on this graph are exactly what I need:

enter image description here

Answer Source

Assuming a 2D case and an archimedean spiral centered around zero (a=0), so with equation r=a\theta. Successive lines are then 2\pi b apart, so to obtain a 'vertical spacing' of v, set b=v/(2\pi).

The length of the arc from the centre to a point at given angle is given by Wolfram, but his solution is difficult to working with. Instead, we can approximate the length of the arc (using a very rough for-large-theta approximation) to s=0.5*theta^2. Rearranging, s=sqrt(s/b), allowing us to determine what angles correspond to the desired 'horizontal spacing'. If this approximation is not good enough, I would look at using something like Newton-Raphson. The question you link to uses also uses an approximation, although not the same one.

Finally, recognising that polar coordinates r=b\theta translate to cartesian as follows: x=b*theta*cos(theta); y=b*theta*sin(theta).

I get the following:


This is generated by the following MATLAB code, but it should be straight-forward enough to translate to C++ if this is what you actually need.

% Entered by user
vertspacing = 1;
horzspacing = 1;
thetamax = 10*pi;

% Calculation of (x,y) - underlying archimedean spiral.
b = vertspacing/2/pi;
theta = 0:0.01:thetamax;
x = b*theta.*cos(theta);
y = b*theta.*sin(theta);

% Calculation of equidistant (xi,yi) points on spiral.
smax = 0.5*b*thetamax.*thetamax;
s = 0:horzspacing:smax;
thetai = sqrt(2*s/b);
xi = b*thetai.*cos(thetai);
yi = b*thetai.*sin(thetai);