0

I want to calculate the length of every full rotation of an Archimedean Spiral given the spacing between each arm and the total length are known. The closest to a solution I've been able to find is here, but this is for finding an unknown length.

I can't interpret math notation so am unable to extrapolate from the info in the link above. The closest I've been able to achieve is:

Distance between each spiral arm:

ArmSpace <- 7

Total length of spiral:

TotalLength <- 399.5238

Create empty df to accommodate TotalLength (note that sum(df[,2]) can be > TotalLength):

df <- data.frame(matrix(NA, nrow=0, ncol=2))
colnames(df) <- c("turn_num", "turn_len_m")
df[1,1] <- 0 # Start location of spiral
df[1,2] <- pi*1/1000

Return length of every turn:

i <- 0
while(i < TotalLength) {
  df[nrow(df)+1,1] <- nrow(df) # Add turn number
  df[nrow(df),2] <- pi*(df[nrow(df)-1,2] +
                          (2*df[nrow(df),1])*ArmSpace)/1000
  i <- sum(df[,2])
}

An annotated example explaining the steps would be most appreciated.

L Tyrone
  • 1,268
  • 3
  • 15
  • 24
  • I am not sure what you really need to calculate. [Look here](https://stackoverflow.com/a/44742854/844416), perhaps formulas are useful. Do you need length s(t) for t=2*pi,4*pi,....? – MBo Feb 06 '23 at 04:37
  • @MBo Thank you so much for that. I didn't state it in my question, but what I'm trying to achieve is almost exactly the same as that answer you linked to. Unfortunately I'm not math literate so I can't work it out alone. Based on the example you linked to, how would I code in R to return a table with the coordinates every .07 along a spiral that is ~399 long AND the coordinates at every completed turn? The table would need to show which revolution each coordinate belong to – L Tyrone Feb 06 '23 at 06:17
  • 0.07 of length? Yes, I used described approach to generate the picture. Cannot find source (in Delphi) for now, perhaps tomorrow. But in general - simple loop generates value of arc length woth needed increment and calculates t (or theta) angle, then coordinates – MBo Feb 06 '23 at 06:55

1 Answers1

1

I used approximation Clackson formula

t = 2 * Pi * Sqrt(2 * s / a)

to get theta angle corresponding to arc length s.

Example in Delphi, I hope idea is clear enough to implement in R

var
  i, cx, cy, x, y: Integer;
  s, t, a, r : Double;
begin
  cx := 0;
  cy := 0;
  a := 10;           //spiral size parameter
  Canvas.MoveTo(cx, cy);
  for i := 1 to 1000 do begin
    s := 0.07 * i;   //arc length
    t :=  2 * Pi * Sqrt(2 * s / a);   //theta
    r := a * t;                       //radius
    x := Round(cx + r * cos(t));      //rounded coordinates 
    y := Round(cy + r * sin(t));
    Memo1.Lines.Add(Format('len %5.3f theta %5.3f r %5.3f x %d y %d', [s, t, r, x, y]));
    Canvas.LineTo(x, y);
    if i mod 10 = 1 then   //draw some points as small circles
       Canvas.Ellipse(x-2, y-2, x+3, y+3);
  end;

Some generated points

len 0.070 theta 0.743 r 7.434 x 5 y 5
len 0.140 theta 1.051 r 10.514 x 5 y 9
len 0.210 theta 1.288 r 12.877 x 4 y 12
len 0.280 theta 1.487 r 14.869 x 1 y 15
len 0.350 theta 1.662 r 16.624 x -2 y 17
len 0.420 theta 1.821 r 18.210 x -5 y 18

Link gives exact formula for ac length,

s(t) = 1/(2*a) * (t * Sqrt(1 + t*t) + ln(t + Sqrt(1+t*t)))

but we cannot calculate inverse (t for given s) using simple formula, so one need to apply numerical methods to find theta for arc length value.

Addition: length of k-th turn. Here we can use exact formula. Python code:

import math
def arch_sp_len(a, t):
    return a/2 * (t * math.sqrt(1 + t*t) + math.log(t + math.sqrt(1+t*t)))

def arch_sp_turnlen(a, k):
    return arch_sp_len(a, k*2*math.pi) - arch_sp_len(a, (k-1)*2*math.pi)

print(arch_sp_turnlen(1, 1))
print(arch_sp_turnlen(1, 2))
print(arch_sp_turnlen(10, 3))
MBo
  • 77,366
  • 5
  • 53
  • 86
  • I can see how to implement that in R. Delphi not too dissimilar. I had a quick look at Delphi and I'm assuming Memo1.Lines.Add, Canvas.Line, and Canvas.Ellipse are for graphic output? I'll have a go tomorrow and will post the code if I'm successful. – L Tyrone Feb 06 '23 at 08:41
  • Yes, Memo1.Lines.Add is for text table output, other lines and point coordinate rounding is for graphic output, so you really need s,t,r calculation and x,y without rounding – MBo Feb 06 '23 at 08:48
  • I have it working in R, but in addition to the equidistant points, I also need a point, - let's call it 'turn' - plotted for every time a full 360 rotation is made around the centre. The arc length from 'turn' to the previous point and from 'turn' to the next point will sum to s. Is this possible? – L Tyrone Feb 07 '23 at 04:53
  • Having `theta=360*k (2*Pi*k)` and length `s`, we can define `a` from given formula. But with the same `a` length of '"turn" will change, it cannot be constant – MBo Feb 07 '23 at 05:01
  • Pivoting to another option, could you please post another loop that returns the length of each completed turn? I didn't finish high school so I really appreciate all your help, and I'll post all the loops in R once I've got it working – L Tyrone Feb 07 '23 at 06:11
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/251680/discussion-between-leroy-tyrone-and-mbo). – L Tyrone Feb 07 '23 at 06:58