** Known as a typical fractal figure using Python **
** 1. Sierpinski triangle ** ** 2. Burnsley fern ** ** 3. Fractal tree **
Draw **. ** **
I will not mention the mathematics of fractal geometry here (because the author is shallow in the field). However, I hope you enjoy watching ** how fractal figures that can be seen naturally are generated from simple rules **.
** It is a pattern found in the patterns of marine life such as shells. ** Draw a set of points made by the following simple rules.
1.Draw an equilateral triangle with the coordinates of the following three vertices.
Vertex 1: (x1,y1)
Peak 2: (x2,y2)
Top 3: (x3,y3)
2.Any point P inside the triangle(x_0,y_0)Is the first point.
3.The new points are defined as follows.
Draw a point PP at the midpoint between P and vertex 1(1/Probability of 3)
Draw a point PP at the midpoint between P and vertex 2(1/Probability of 3)
Draw a point PP at the midpoint between P and vertex 3(1/Probability of 3)
4.Repeat 3
** Draw a pattern like a fern plant. ** It is odd that ferns with high symmetry can be created from random elements. In Rule 2 of making a Sierpinski triangle in (1), Change the rule to generate a new point $ (x_ {n + 1}, y_ {n + 1}) $ from $ (x_n, y_n) $ as follows.
Let $ r $ be a uniform random number of [0,1]
$(x_{n+1},y_{n+1}) = $
And.
** Generate a wooden pattern. ** **
In Rule 2 of 1) Making a Sierpinski triangle, Change the rule to generate a new point $ (x_ {n + 1}, y_ {n + 1}) $ from $ (x_n, y_n) $ as follows.
$(x_{n+1},y_{n+1}) = $ $ (0.05, 0.6 y_n) $ (Probability 10%) $ (0.05x_n, -0.5 y_n + 1.0 $ (probability 10%) $ (0.46x_n-0.15 y_n, 0.39 x_n + 0.38 y_n + 0.6 $ (probability 20%) $ (0.47x_n-0.15 y_n, 0.17 x_n + 0.42 y_n + 1.1 $ (probability 20%) $ (0.43x_n + 0.28y_n, -0.25x_n + 0.45y_n + 1.0 $ (probability 20%) $ (0.42x_n + 0.26y_n, -0.35x_n + 0.31y_n + 0.7 $ (probability 20%)
"""
Sierpinski triangle
"""
import numpy as np
import matplotlib.pyplot as plt
from random import random, randrange
from math import floor
fig=plt.figure()
anim=[]
#
a=np.zeros([3])
b=np.zeros([3])
X1,Y1=0,5
X2,Y2=5,0
X3, Y3=-5,0
a[0], a[1], a[2] =X1, X2, X3
b[0],b[1], b[2]= Y1, Y2, Y3
plt.plot(a[0],b[0],'o',color='blue',markersize=1)
plt.plot(a[1],b[1],'o',color='blue',markersize=1)
plt.plot(a[2],b[2],'o',color='blue',markersize=1)
x=2.5
y=2.5
for i in range(15000):Main loop:Production rules(1)
if i%1000 ==0:
print(i)
n=randrange(3)
x=(x+a[n])/2
y=(y+b[n])/2
plt.plot(x,y,'o',color='blue',markersize=1)
plt.show()
Every part is self-similar.
"""
Burnsley fern
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import ArtistAnimation #Import methods for creating animations
from random import random, randrange
from math import floor
fig=plt.figure()
anim=[]
#
x=0.5
y=0.5
for i in range(15000):Main loop:Production rules(2)
if i%1000==0:
print(i)
r=random()
if r< 0.02:
x,y = 0.5, 0.27*y
elif 0.02 <= r <=0.17:
x,y = -0.139*x+0.263*y+0.57, 0.246*x+0.224*y-0.036
elif 0.17 < r <=0.3:
x,y = 0.17*x-0.215*y+0.408, 0.222*x+0.176*y+0.0893
elif 0.3 < r <= 1:
x,y = 0.781*x+0.034*y+0.1075, -0.032*x+0.739*y+0.27
plt.plot(x,y,'o',color='blue',markersize=1)
plt.show()
Enlarged leaves contain the same structure (self-similarity). However, as can be seen from the difference in leaves between branches, ferns as a whole do not have self-similarity.
"""
Fractal tree
13Aug. 2017
"""
import numpy as np
import matplotlib.pyplot as plt
from random import random, randrange
from math import floor
fig=plt.figure()
anim=[]
#
x=0.5
y=0.5
for i in range(15000):Main loop:Production rules(3)
if i%1000==0:
print(i)
r=random()
if r<= 0.1:
x,y = 0.05, 0.6*y
elif 0.1 < r <=0.2:
x,y = -0.05*x, -0.5*y+1.0
elif 0.2 < r <=0.4:
x,y = 0.46*x-0.15*y, 0.39 *x+0.38*y+0.6
elif 0.4 < r <= 0.6:
x,y = 0.47*x-0.15*y, 0.17*x+0.42*y+1.1
elif 0.6 < r <= 0.8:
x,y = 0.43*x+0.28*y, -0.25*x+0.45*y+1.0
elif 0.8 < r <= 1.0:
x,y = 0.42*x+0.26*y, -0.35*x+0.31*y+0.7
plt.plot(x,y,'o',color='blue',markersize=1)
# anim.append(im)
plt.show()
● Fractal geometry has non-integer dimensions ([Fractal dimension](https://ja.wikipedia.org/wiki/%E3%83%95%E3%83%A9%E3%82%AF%E3%82%] BF% E3% 83% AB% E6% AC% A1% E5% 85% 83)). There seem to be various definitions of this dimension. I think the definition by Hausdorff Beskovich [1] is easy to understand. Let the straight line be one-dimensional, the triangle be two-dimensional, and the solid be three-dimensional, and the fractal dimension of the symmetrical figure is determined.
● Mathematically, the point set of both ferns and fractal trees in Bernsley is self-affine. Produced by a transformation with [2]. This seems to create self-similarity.
References
[1] Yoshihide Okumura (Department of Mathematics, Faculty of Science, Shizuoka University) pdf
[2] Commentary Page by Mitoku Hayakawa (Media Education Division, Education Information Infrastructure Center, Tohoku University) )