python,numpyを使って複素数平面上で回転と平行移動を行いました。母の日のプレゼントにしたかった。
コードの背景となる数学は暇な時書きます。numpyで実装しました。
背景となる数学と目的
そのうち書く
コード
heart.py
import matplotlib
matplotlib.use('Agg') #under my ssh environment,the matplotlib cannnot work as usual so i need matplotlib.use('Agg')
import numpy as np
import matplotlib.pyplot as plt
# the fundamental heart gragh grath00
t = np.linspace(0, 2 * 3.141, 100)
sin1 = np.sin(t)
cos1 = np.cos(t)
cos2 = np.cos(2 * t)
cos3 = np.cos(3 * t)
cos4 = np.cos(4 * t)
gragh_00 =( sin1 ** 3 + ( 13 * cos1 - 5 * cos2 - 2 * cos3 - cos4 ) * 1j/ 15 ) * 4 / 8
#plot
plt.plot(np.real(gragh_00 * 7 / 8 ), np.imag(gragh_00 * 7 /8), linewidth =4, color="red")
# copy heart gragh 24 times
# making point array
point_list = [[a -2 + ( b - 2 ) * 1j] for a in range(5) for b in range(5)]
point_list.remove([0j])
point_array = np.array(point_list)
for i in range(24):
gragh_0i = point_array[i] - 1j * gragh_00 * (point_array[i] / np.absolute(point_array[i]))
plt.plot(np.real(gragh_0i * 7 / 8 ), np.imag(gragh_0i * 7 /8), linewidth =4, color="red")
plt.axis('equal') #without this command matplot change axi's ratio
plt.savefig('heart.png')