自分なりの家の図を描画してください。屋根や壁の形を変えるほか、適当に窓やドアなどを追加すると良いです。
import numpy as np
import matplotlib.pyplot as plt
roof_nodes = np.array([[0,3],[-3,2],[3,2],[0,3]]).T #屋根の点からなる行列
wall_nodes = np.array([[-2,2],[-2,0],[2,0],[2,2],[-2,2]]).T #壁の点からなる行列
window_nodes = np.array([[0.75,1.5],[0,1.5],[0,0.5],[0.75,0.5],[0.75,1.5],[1.5,1.5],[1.5,0.5],[0.75,0.5]]).T #窓の点からなる行列
door_nodes = np.array([[-1.5,1.5],[-1.5,0],[-0.5,0],[-0.5,1.5],[-1.5,1.5]]).T #ドアの点からなる行列
knob_nodes = np.array([[-0.7,0.9],[-0.8,0.8],[-0.7,0.7],[-0.6,0.8],[-0.7,0.9]]).T #ドアノブの点からなる行列
plt.gca().set_aspect("equal")
plt.plot(roof_nodes[0,:],roof_nodes[1,:],"r-") #屋根の描画
plt.plot(wall_nodes[0,:],wall_nodes[1,:],"r-") #壁の描画
plt.plot(window_nodes[0,:],window_nodes[1,:],"r-") #窓の描画
plt.plot(door_nodes[0,:],door_nodes[1,:],"r-") #ドアの描画
plt.plot(knob_nodes[0,:],knob_nodes[1,:],"r-") #ドアノブの描画
plt.show()
1.2の家(または演習1で考えた自分なりの家)に対して何かしらの拡大・縮小変換、回転変換、対称変換を一つずつ行い、変換前の家と合わせて四つの家を一つの図に描画してください。ただし、別々の色にすること。
import numpy as np
import matplotlib.pyplot as plt
#変換前
roof_nodes = np.array([[0,3],[-3,2],[3,2],[0,3]]).T
wall_nodes = np.array([[-2,2],[-2,0],[2,0],[2,2],[-2,2]]).T
plt.gca().set_aspect("equal")
plt.plot(roof_nodes[0,:],roof_nodes[1,:],"r-")
plt.plot(wall_nodes[0,:],wall_nodes[1,:],"r-")
#x軸方向に2倍、y軸方向に2倍する拡大・縮小変換
A = np.array([[2,0],[0,2]])
new_roof_nodes = A@roof_nodes
new_wall_nodes = A@wall_nodes
plt.plot(new_roof_nodes[0,:],new_roof_nodes[1,:],"b-")
plt.plot(new_wall_nodes[0,:],new_wall_nodes[1,:],"b-")
#反時計回りに30度だけ回転する回転変換
theta = 30/180*np.pi
A = np.array([[np.cos(theta),-np.sin(theta)],[np.sin(theta),np.cos(theta)]])
new_roof_nodes = A@roof_nodes
new_wall_nodes = A@wall_nodes
plt.plot(new_roof_nodes[0,:],new_roof_nodes[1,:],"g-")
plt.plot(new_wall_nodes[0,:],new_wall_nodes[1,:],"g-")
#x軸に関して対称移動する対称変換
A = np.array([[1,0],[0,-1]])
new_roof_nodes = A@roof_nodes
new_wall_nodes = A@wall_nodes
plt.plot(new_roof_nodes[0,:],new_roof_nodes[1,:],"y-")
plt.plot(new_wall_nodes[0,:],new_wall_nodes[1,:],"y-")
plt.show()
線形変換の一種であるせん断変換についてWikipediaなどで調べた上で、1.2の家(または演習1で考えた自分なりの家)に対して何かしらのせん断変換を行い、変換前の家と変換後の家を一つの図に描画してください。ただし、別々の色にすること。
せん断変換は、原点を通るある直線からの符号付き距離に比例した分だけ、その直線と平行な方向に移動する変形(せん断変形)を行う線形変換です。
特に、$m$ を比例定数とするとき、水平せん断($x$ 軸と平行なせん断)は
$$ \begin{pmatrix} x'\\ y' \end{pmatrix} = \begin{pmatrix} 1 & m\\ 0 & 1 \end{pmatrix} \begin{pmatrix} x\\ y \end{pmatrix}, $$鉛直せん断($y$ 軸と平行なせん断)は
$$ \begin{pmatrix} x'\\ y' \end{pmatrix} = \begin{pmatrix} 1 & 0\\ m & 1 \end{pmatrix} \begin{pmatrix} x\\ y \end{pmatrix} $$と表されます。
import numpy as np
import matplotlib.pyplot as plt
#変換前
roof_nodes = np.array([[0,3],[-3,2],[3,2],[0,3]]).T
wall_nodes = np.array([[-2,2],[-2,0],[2,0],[2,2],[-2,2]]).T
plt.gca().set_aspect("equal")
plt.plot(roof_nodes[0,:],roof_nodes[1,:],"r-")
plt.plot(wall_nodes[0,:],wall_nodes[1,:],"r-")
#水平方向に比例定数1のせん断変形を行うせん断変換
A = np.array([[1,1],[0,1]])
new_roof_nodes = A@roof_nodes
new_wall_nodes = A@wall_nodes
plt.plot(new_roof_nodes[0,:],new_roof_nodes[1,:],"b-")
plt.plot(new_wall_nodes[0,:],new_wall_nodes[1,:],"b-")
plt.show()