我正在尝试使用 Chaos 游戏在 Python 中生成一个 Spierpinki 三角形。要绘制的点的计算似乎是正确的,但不是绘制了数千个点,而是仅绘制了 10 个左右。
import math
import numpy as np
import random as rand
import matplotlib.pyplot as plt
# Defining vertices
t = np.linspace(0, (2 * math.pi), 4)
v = np.array([[math.cos(t[0]), math.cos(t[1]), math.cos(t[2])],
[math.sin(t[0]), math.sin(t[1]), math.sin(t[2])]])
# Defining Starting point
T = np.array([[0.5, 0], [0, 0.5]])
x = np.array([rand.random() - 0.5, rand.random() - 0.5]).reshape(2, 1)
res = np.zeros((2, 1))
n = 10000
for i in range(n):
for j in range(2):
k = rand.randint(0, 2)
res = np.expand_dims(res, axis=0)
res = np.multiply(T, np.subtract(x[j], v[:, k])) + v[:, k]
xx = [x for (x, y) in res]
yy = [y for (x, y) in res]
plt.plot(xx, yy, 'b.')
plt.show()