返回每次旋转的阿基米德螺旋弯曲给定臂间距和总长度的弧长

huangapple go评论55阅读模式
英文:

Return arc length of every rotation of an Archimedean Spiral given arm spacing and total length

问题

以下是已翻译的代码部分:

我想计算每个阿基米德螺旋的完整旋转长度,已知每个螺旋臂之间的间距和总长度。我能找到的最接近解决方案是[这里][1],但这是用于找到未知长度的情况。

我无法解释数学符号,因此无法从上面链接中的信息中推断出解决方法。我能够实现的最接近的方法是:

每个螺旋臂之间的距离:

ArmSpace <- 7

螺旋的总长度:

TotalLength <- 399.5238

创建一个空的数据框以容纳TotalLength(请注意,sum(df[,2])可以大于TotalLength):

df <- data.frame(matrix(NA, nrow=0, ncol=2))
colnames(df) <- c("turn_num", "turn_len_m")
df[1,1] <- 0 # 螺旋的起始位置
df[1,2] <- pi*1/1000

返回每次旋转的长度:

i <- 0
while(i < TotalLength) {
  df[nrow(df)+1,1] <- nrow(df) # 添加旋转编号
  df[nrow(df),2] <- pi*(df[nrow(df)-1,2] +
                          (2*df[nrow(df),1])*ArmSpace)/1000
  i <- sum(df[,2])
}

希望这有所帮助。如果需要进一步的解释或注释示例,请随时提问。

英文:

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 &lt;- 7

Total length of spiral:

TotalLength &lt;- 399.5238

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

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

Return length of every turn:

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

An annotated example explaining the steps would be most appreciated.

答案1

得分: 1

我使用近似的 Clackson formula

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

来获取弧长 s 对应的 theta 角度。

Delphi 中的示例,我希望思路足够清晰,以便在 R 中实现:

var
  i, cx, cy, x, y: Integer;
  s, t, a, r: Double;
begin
  cx := 0;
  cy := 0;
  a := 10;           // 螺旋大小参数
  Canvas.MoveTo(cx, cy);
  for i := 1 to 1000 do begin
    s := 0.07 * i;   // 弧长
    t := 2 * Pi * Sqrt(2 * s / a);   // theta
    r := a * t;                       // 半径
    x := Round(cx + r * cos(t));      // 四舍五入的坐标
    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   // 作为小圆圈绘制一些点
      Canvas.Ellipse(x-2, y-2, x+3, y+3);
  end;
end;

生成的一些点:

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

链接 给出了弧长的精确公式:

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

但是我们不能使用简单的公式来计算反函数(给定 s 求 t),所以需要应用数值方法来找到弧长值对应的 theta。

另外,第 k 圈的长度。在这里,我们可以使用精确的公式。Python 代码:

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))
英文:

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(&#39;len %5.3f theta %5.3f r %5.3f x %d y %d&#39;, [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))

huangapple
  • 本文由 发表于 2023年2月6日 07:58:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75356348.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定