Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ 変換の組み合わせ | 幾何学的変換
Pythonによる幾何モデリング

変換の組み合わせ

メニューを表示するにはスワイプしてください

幾何図形を扱う際、しばしば複数の変換を図形に適用する必要があります。このプロセスは変換の合成と呼ばれます。変換(平行移動、回転、拡大縮小など)を適用する順序は非常に重要です。なぜなら、それぞれの変換が図形の位置、大きさ、または向きを変化させ、次の操作に影響を与えるからです。

例えば、多角形から始めて、それを平行移動(移動)し、次に回転し、最後に拡大縮小したいとします。もし順序を変えて、最初に拡大縮小し、次に回転し、最後に平行移動した場合、全く異なる結果になることがあります。これは変換が可換ではないためです。すなわち、Aの後にBを行う場合と、Bの後にAを行う場合で、必ずしも同じ結果にはなりません。

変換を組み合わせるには、それぞれの変換を順番に図形に適用します。各ステップは前のステップの結果を入力として使用します。この方法により、単純な操作から複雑な操作を構築できますが、常に順序に注意する必要があります。

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
import numpy as np import matplotlib.pyplot as plt # Define a simple triangle polygon polygon = np.array([ [0, 0], [1, 0], [0.5, 1], [0, 0] ]) # Translation: move by (2, 1) def translate(points, tx, ty): return points + np.array([tx, ty]) # Rotation: rotate by theta degrees around origin def rotate(points, theta_deg): theta = np.radians(theta_deg) rotation_matrix = np.array([ [np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)] ]) return points @ rotation_matrix.T # Scaling: scale by (sx, sy) def scale(points, sx, sy): scaling_matrix = np.array([ [sx, 0], [0, sy] ]) return points @ scaling_matrix.T # Apply transformations translated = translate(polygon, 2, 1) rotated = rotate(translated, 45) scaled = scale(rotated, 1.5, 0.5) # Plotting plt.figure(figsize=(6, 6)) plt.plot(polygon[:, 0], polygon[:, 1], 'bo-', label='Original') plt.plot(translated[:, 0], translated[:, 1], 'go-', label='Translated') plt.plot(rotated[:, 0], rotated[:, 1], 'ro-', label='Rotated') plt.plot(scaled[:, 0], scaled[:, 1], 'mo-', label='Scaled') plt.legend() plt.axis('equal') plt.title('Combining Translation, Rotation, and Scaling') plt.show()
question mark

変換を組み合わせる際、変換を適用する順序が重要である理由を最もよく説明しているのはどの記述ですか?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 2.  7

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 2.  7
some-alt