什么是科赫曲线?
科赫雪花(也称为科赫曲线、科赫星或科赫岛)是一条数学曲线,也是最早被描述的分形曲线之一。它基于瑞典数学家赫尔格·冯·科赫(Helge von Koch)1904年发表的题为“在没有切线的连续曲线上,可从初等几何构造”的论文中提出的科赫曲线。
雪花面积的级数收敛到原始三角形面积的8/5倍,而雪花周长的级数发散到无穷大。因此,雪花有一个由无限长的线包围的有限区域。
建设
第一步:
画一个等边三角形。你可以用指南针或量角器来画,如果你不想花太多时间画雪花的话,也可以用肉眼观察。
第二步:
将每一面分成三等份。这就是为什么边可以被三整除的原因。
第三步:
在每个中间部分画一个等边三角形。测量中间三分之一的长度,以了解这些新三角形边的长度。
第四步:
把每一面分成三份。你可以看到第二代三角形覆盖了第一代三角形的一部分。这三条线段不应该分成三段。
第五步:
在每个中间部分画一个等边三角形。
林登迈耶系统的表示
字母表 :F 常数 : +, ? 公理 :F 产生式规则 :F?F+F–F+F
这里,F表示“向前拉”–表示“右转60°”,+表示“左转60°”。 要创建科赫雪花,可以使用F++F++F(等边三角形)作为公理。
要创建科赫曲线,请执行以下操作:
# Python program to print partial Koch Curve. # importing the libraries : turtle standard # graphics library for python from turtle import * #function to create koch snowflake or koch curve def snowflake(lengthSide, levels): if levels = = 0 : forward(lengthSide) return lengthSide / = 3.0 snowflake(lengthSide, levels - 1 ) left( 60 ) snowflake(lengthSide, levels - 1 ) right( 120 ) snowflake(lengthSide, levels - 1 ) left( 60 ) snowflake(lengthSide, levels - 1 ) # main function if __name__ = = "__main__" : # defining the speed of the turtle speed( 0 ) length = 300.0 # Pull the pen up – no drawing when moving. penup() # Move the turtle backward by distance, # opposite to the direction the turtle # is headed. # Do not change the turtle’s heading. backward(length / 2.0 ) # Pull the pen down – drawing when moving. pendown() snowflake(length, 4 ) # To control the closing windows of the turtle mainloop() |
输出:
要用科赫曲线创建完整的雪花,我们需要重复三次相同的图案。让我们试试看。
# Python program to print complete Koch Curve. from turtle import * # function to create koch snowflake or koch curve def snowflake(lengthSide, levels): if levels = = 0 : forward(lengthSide) return lengthSide / = 3.0 snowflake(lengthSide, levels - 1 ) left( 60 ) snowflake(lengthSide, levels - 1 ) right( 120 ) snowflake(lengthSide, levels - 1 ) left( 60 ) snowflake(lengthSide, levels - 1 ) # main function if __name__ = = "__main__" : # defining the speed of the turtle speed( 0 ) length = 300.0 # Pull the pen up – no drawing when moving. # Move the turtle backward by distance, opposite # to the direction the turtle is headed. # Do not change the turtle’s heading. penup() backward(length / 2.0 ) # Pull the pen down – drawing when moving. pendown() for i in range ( 3 ): snowflake(length, 4 ) right( 120 ) # To control the closing windows of the turtle mainloop() |
输出:
本文由 Subhajit Saha .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。
如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。