双曲线(第一次使用ThinkPython学习)

问题描述 投票:0回答:1

我正在通过ThinkPython这本书学习Python(很有趣)。到目前为止,我真的很喜欢这个新爱好。最近的一项练习是制作阿基米德螺旋线。为了测试我的技能,我一直在努力制作双曲线螺旋线,但被挫败了!

根据等式r = a + b * theta ^(1 / c)

  • 当c = 1时我们看到阿基米德螺旋线
  • 当c = -1时,我们应该看到一个双曲线螺旋

我正在使用以下代码,希望对正确方向的任何帮助。

  • 特别指出在没有直接给出答案的情况下可以在正确方向帮助我的人。除非仅仅是格式问题。
  • 如果建议的答案涉及使用(x,y)坐标进行绘制,则没有分数。
import turtle
import math

def draw_spiral(t, n, length=3, a=0.1, b=0.0002):
    """Draws an Archimedian spiral starting at the origin.

    Args:
      n: how many line segments to draw
      length: how long each segment is
      a: how loose the initial spiral starts out (larger is looser)
      b: how loosly coiled the spiral is (larger is looser)

    http://en.wikipedia.org/wiki/Spiral
    """
    theta = 0.1

    for i in range(n):
        t.fd(length)
        dtheta = 1/((a + b * (theta**(1/-1))))

        t.lt(dtheta)
        theta += dtheta

# create the world and bob
bob = turtle.Turtle()
draw_spiral(bob, n=1000)

turtle.mainloop()

"""Source code from ThinkPython @ http://greenteapress.com/thinkpython2/code/spiral.py

edited to attempt a hyperbolic spiral"""

非常感谢!

python new-operator turtle-graphics hyperbolic-function
1个回答
0
投票

只需调整作为参数传递给draw_spiral()的常量:

def draw_spiral(t, n, length=1, a=0.01, b=60):

我能够沿着您描述的直线生成螺旋形:

enter image description here

但是,它是从outside in而不是inside out绘制的。因此,可能不是您想要的。

© www.soinside.com 2019 - 2024. All rights reserved.