0

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

Community
  • 1
  • 1
Corey Iles
  • 155
  • 1
  • 17
  • 2
    I'm voting to close this question as off-topic because it's not a programming question. It would perhaps fit on mathematics.SE. – Carey Gregory Nov 24 '15 at 22:16
  • It is very specific to programming. If I was doing it for the math I already know how to graph it. I just need to be able to go through the point in my program. – Corey Iles Nov 24 '15 at 22:19
  • @CoreyIles so where is your code? – Seth Kitchen Nov 24 '15 at 22:21
  • The only code I have is for a helix. I have no idea where to start for this spiral (well other than the function name that is). I tried converting the code from that link to do what I need but I can't get it to work properly. – Corey Iles Nov 24 '15 at 22:23
  • @CoreyIles Then your questions amounts to a ["Gimme teh codez"](http://meta.stackexchange.com/questions/108551/what-site-to-use-if-you-have-a-gimme-teh-codez-question) question. – Carey Gregory Nov 24 '15 at 22:27
  • You probably need to show us some code with at least the expected inputs and outputs. Because reading your question, if you have the formula $r = a + b \theta$, you can just use that to calculate / plot the points. If you need an upwards spiral, just add a $z$-coordinate (something like $z \propto \theta$ would do). – CompuChip Nov 24 '15 at 22:27
  • @CareyGregory I'm not asking someone to give me the code, I want help. – Corey Iles Nov 24 '15 at 22:28
  • @CompuChip I'll try to whip up an example. – Corey Iles Nov 24 '15 at 22:29
  • I second CompuChips comment. A in value => out values example, without all the general and vague talk about spirals and other stuff, would help very much. – deviantfan Nov 24 '15 at 22:30
  • I have already given the inputs and outputs though. But yeah, I know code will make better sense. – Corey Iles Nov 24 '15 at 22:32
  • How do we help you without just doing the work for you? Did you read the question and answer I linked you to? – Carey Gregory Nov 24 '15 at 22:34
  • Yeah, I get it, but I don't expect somehow to just throw me code and not explain it. They don't have to explain the math, just the general idea or whatever they feel needs to be explained. If they don't explain at all that's fine but it's not going to help me as much as explaining would. – Corey Iles Nov 24 '15 at 22:41
  • The graph you posted up which corresponds to 'exactly what you need' is more simple than you make out - the sections of arc between points are of constant length. There is nothing complicated going on with horizontal and vertical separations. – RPM Nov 24 '15 at 22:43
  • The horizontal and vertical separations between the points in your plot are not constant (even under rotation - you can tell because they do not make a square/rectangular/diamond grid) - and I do not think it would be possible to find a solution where they are constant. You might be able to find a solution where the distance between points is constant... – RPM Nov 24 '15 at 22:51
  • You say _not_ spiral but your diagram looks like one. What equations then? Spell out each term you're using. The x,y,z implies you want 3D? What defines "consecutive" and "equidistant" for _your_ purposes? You're defining terms without providing concrete connections between them (e.g. specific equations). Which gets calculated in which order? What functions do you think you need? "Circular figures in general"? Do you mean parallel circles of different radii? If 3D, would this look like conic slices? – Craig Estey Nov 24 '15 at 22:53
  • `You might be able to find a solution where the distance between points is constant` That's what I want. – Corey Iles Nov 24 '15 at 22:56
  • @CraigEstey I never said _not_ spiral. – Corey Iles Nov 24 '15 at 22:57
  • You have the equation for a spiral. If you can mathematically formulate your 'equidistant' requirement you could potentially get some insight by treating the two as a set of simultaneous equations. – RPM Nov 24 '15 at 22:57
  • `If you can mathematically formulate your 'equidistant' requirement` That's precisely what I'm asking help with, I just couldn't think of a good way to explain it. – Corey Iles Nov 24 '15 at 22:59
  • You said: "There is a specific set of data a user can input, they are NOT based on spirals but circular figures in general." But, the rest still holds. And are you talking 2D or 3D? So, I presume you want a 3D spiral? Ah! Now we're getting somewhere. If you can't yet define equidistant, add definitions/equations for the other parts that you can. Doing so may help with the "aha moment" – Craig Estey Nov 24 '15 at 23:03
  • The program is not specific to spirals. It's for many different figures that all use the same input. I never said the question was not relative to spirals. The question is also obviously for 2D, that's why I'm only asking for X and Y. Converting it to 3d would be as simple as constantly incrementing Z. – Corey Iles Nov 24 '15 at 23:06
  • I did quote your post directly about the _not_. Okay, so you have several figures, one of which is a 2D spiral. So, you'll need a "generator" function for it. You'll also need other similar functions for the various shapes you want. Say you had 10 different shapes, you'd need 10 functions. But, what are some examples of the shapes? Can you mention a few? – Craig Estey Nov 24 '15 at 23:19
  • @RPM The 'latter'. And I'd rather have the distance be measured along the spiral, but either is fine. – Corey Iles Nov 24 '15 at 23:21
  • @CraigEstey All of my other figures are already done. They have nothing to do with this situation. But they are: sphere, cylinder (which since I only map the vertices it can also be considered a prism), helix, whirl (which in my case is just a 'log' spiral), circle, and cone (which is just the cylinder with reducing radi, would be much better using the spiral from this question). – Corey Iles Nov 24 '15 at 23:24

1 Answers1

4

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:

Spiral!

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);
Community
  • 1
  • 1
RPM
  • 1,704
  • 12
  • 15