Python中的Phyllotaxis模式| 算法植物学的一个单位

简介| 叶底

  Phyllotaxis / phyllotaxy是植物茎上叶子的排列,Phyllotactic螺旋形成自然界中独特的一类模式。这个词本身来自希腊语phullon,意思是“叶子”和出租车,意思是“安排”。基本的花卉叶序安排包括:
  螺旋叶状体 -在螺旋叶状体中,个别花器官是在规则的时间间隔内创建的相同的发散角度。具有螺旋叶状花序的花中的发散角近似为137.5度,这表示遵循斐波纳契系列的图案。下图显示具有顺时针和逆时针螺旋图案的螺旋叶状图案。
python222222.jpg

重点要注意:

  1. Fibonacci系列通常描述自然界中发现的螺旋。它被计算为一系列,其中前一对数字与系列中的下一个数字相加。该系列是1,1,2,3,5,8,13,21,34,55,89 …。

  2. 实际上,顺时针方向有一组螺旋,逆时针方向有一组螺旋。

  3. 花器官螺旋遵循分子和分母组的偏移斐波那契数(1 / 2,1 / 3,2 / 5,3 / 8,5 / 13,8 / 21,13 / 34 …)。分子是围绕轴返回起始原点的次数或转数。分母表示转弯期间启动的器官数量。因此,2/5表示绕轴旋转2圈,5个器官返回原点。

  4. 例如 - 在松树中,我们有(2,3),(5,3)和(5,8)个叶状花序,在头状花序中发现的对是(21,34),(55,34),(55,89)和(89,144),并且在具有六边形鳞片的菠萝上,根据样本的大小,发现三联体(8,13,21)或(13,21,34)。

  5. 植物多样性中斐波那契序列的流行通常被称为“叶序的神秘”。

其他类型的花卉叶序排列是:

2、轮生的Phyllotaxis
3、简单的轮生的Phyllotaxis
4、复杂的轮生的Phyllotaxis
5、不规则的Phyllotaxis

模式的形成:总结

  叶子在一些植物中的美丽排列,称为叶序,服从许多微妙的数学关系。例如,向日葵头部的小花形成两个相反方向的螺旋形:顺时针55个,逆时针34个。出奇,

  1. 这些数字是连续的斐波纳契数。
  2. 替代斐波那契数的比率由收敛数给出为φ^( - 2),其中φ是黄金比率,并且据说测量植物茎上连续叶之间的转角分数:
  3. 例如:榆树和林登的1/2,山毛榉和榛树的1/3,橡木和苹果的2/5,杨树和玫瑰的3/8,柳树和杏仁的5/13等。
  4. 植物茎上的每个新叶与前一个叶以一定角度定位,并且该叶在叶之间是恒定的:通常约137.5度。

  也就是说,如果从上面俯视植物并测量从茎到叶子的线和下一片叶子的相应线之间形成的角度,你会发现通常有一个固定的角​​度,称为发散角度角度。在这里,我们对Spiral phyllotaxy感兴趣,我们将编码使用龟图形在python中形成Spiral Phyllotaxy模式。

设计守则

  1. 我们将编写两个函数,一个用于绘制phyllotaxy图案,另一个用于绘制花瓣。
  2. 只有在完成叶序图案之后才需要绘制花瓣。因此,我们将从drawPhyllPattern()函数内部调用drawPetal()函数,并在绘制Phyllotaxis图案后访问最后的x和y坐标。
  3. drawPetal()函数将使用龟函数和特征绘制花瓣,参考Turtle编程

要编码叶序模式,我们需要遵循以下等式:

x = r * cos(θ)
y = r * sin(θ)

r,θ也可以变化 - 所以形成叶序模式我们用笛卡尔形式代替
通过极地形式:

r = c * sqrt(n)
θ= n * 137.508°

pythonnnn322.jpg

将问题减少到光盘上的最佳包装,所以
    r = c * sqrt(n)来自圆的区域
        面积=πr²和n以某些单位填充区域
        c1 * n /π=r²,c为1 / sqrt(c1 /π)
所以,r =某个常数c * sqrt(n)

伪代码

进口模块(数学,TURTLE)

功能 -  DrawPhyllotaxisPattern(龟,t长度,花瓣开始,角度= 137.508,大小,cspread)
    turtleColor( “黑”)
    填充颜​​色('‘橙’)
    将角度转换为弧度(Φ)
    initialize(xcenter,ycenter)=(0,0)
    绘制图案开始:
    对于范围(0,t)中的n:
        r = cspread * sqrt(n)
        θ= n *Φ

        x = r * cos(θ)+ xcenter
            y = r * sin(θ)+ ycenter

        TURTLE POSITION(x,y)
        开始绘图():
        如果绘图模式结束:
            DrawFlowerPetals()
 
功能 -  DrawFlowerPetals(Turtle,x坐标,y坐标)
    使用Turtle方法绘制

创建Turtle = gfg
调用DrawPhyllotaxisPattern(gfg,t length,petalstart,angle = 137.508,size,cspread)

结束

实现代码一

import math        
import turtle 
  
def drawPhyllPattern(turtle, t, petalstart, angle = 137.508, size = 2, cspread = 4 ): 
    """print a pattern of circles using spiral phyllotactic data"""
    # initialize position 
    # turtle.pen(outline=1, pencolor="black", fillcolor="orange") 
    turtle.color('black') 
    turtle.fillcolor("orange") 
    phi = angle * ( math.pi / 180.0 ) #we convert to radian 
    xcenter = 0.0
    ycenter = 0.0
     
    # for loops iterate in this case from the first value until < 4, so 
    for n in range (0, t): 
        r = cspread * math.sqrt(n) 
        theta = n * phi 
          
        x = r * math.cos(theta) + xcenter 
        y = r * math.sin(theta) + ycenter 
  
        # move the turtle to that position and draw  
        turtle.up() 
        turtle.setpos(x, y) 
        turtle.down() 
        # orient the turtle correctly 
        turtle.setheading(n * angle) 
        if n > petalstart-1: 
            turtle.color("yellow") 
            drawPetal(turtle, x, y) 
        else: turtle.stamp() 
              
  
def drawPetal(turtle, x, y ): 
    turtle.penup() 
    turtle.goto(x, y) 
    turtle.pendown() 
    turtle.color('black') 
    turtle.fillcolor('yellow') 
    turtle.begin_fill() 
    turtle.right(20) 
    turtle.forward(70) 
    turtle.left(40) 
    turtle.forward(70) 
    turtle.left(140) 
    turtle.forward(70) 
    turtle.left(40) 
    turtle.forward(70) 
    turtle.penup() 
    turtle.end_fill() # this is needed to complete the last petal 
  
  
gfg = turtle.Turtle() 
gfg.shape("turtle") 
gfg.speed(0) # make the turtle go as fast as possible 
drawPhyllPattern(gfg, 200, 160, 137.508 ) 
gfg.penup() 
gfg.forward(1000) 

输出:
66666.png

代码实现二

import math        
import turtle 
  
def drawPhyllotacticPattern( t, petalstart, angle = 137.508, size = 2, cspread = 4 ): 
        """print a pattern of circles using spiral phyllotactic data"""
        # initialize position 
        turtle.pen(outline=1, pencolor="black", fillcolor="orange") 
        # turtle.color("orange") 
        phi = angle * ( math.pi / 180.0 ) 
        xcenter = 0.0
        ycenter = 0.0
         
        # for loops iterate in this case from the first value until < 4, so 
        for n in range (0, t): 
                r = cspread * math.sqrt(n) 
                theta = n * phi 
                  
                x = r * math.cos(theta) + xcenter 
                y = r * math.sin(theta) + ycenter 
   
                # move the turtle to that position and draw  
                turtle.up() 
                turtle.setpos(x, y) 
                turtle.down() 
                # orient the turtle correctly 
                turtle.setheading(n * angle) 
                if n > petalstart-1: 
                        #turtle.color("yellow") 
                        drawPetal(x, y) 
                else: turtle.stamp() 
                  
  
def drawPetal( x, y ): 
        turtle.up() 
        turtle.setpos(x, y) 
        turtle.down() 
        turtle.begin_fill() 
        #turtle.fill(True) 
        turtle.pen(outline=1, pencolor="black", fillcolor="yellow") 
        turtle.right(20) 
        turtle.forward(100) 
        turtle.left(40) 
        turtle.forward(100) 
        turtle.left(140) 
        turtle.forward(100) 
        turtle.left(40) 
        turtle.forward(100) 
        turtle.up() 
        turtle.end_fill() # this is needed to complete the last petal 
  
  
  
turtle.shape("turtle") 
turtle.speed(0) # make the turtle go as fast as possible 
drawPhyllotacticPattern( 200, 160, 137.508, 4, 10 ) 
turtle.exitonclick() # lets you x out of the window when outside of idle 

输出:
Pythonn2.png

猜你喜欢

转载自blog.csdn.net/weixin_43744872/article/details/86620290