近似の可視化
メニューを表示するにはスワイプしてください
多角形近似が複雑な曲線にどれだけ適合しているかを理解するためには、元の曲線とその近似を同じプロット上で可視化することが有効です。この方法により、近似が曲線にどこまで忠実に従っているか、またどこで逸脱しているかを観察できます。matplotlib を使用して両方の形状を同時に表示し、異なる色や線種を割り当てることで視認性を高めることができます。一般的な手順は以下の通りです。
- 元の曲線の数学的方程式を用いて点を生成する;
- 多角形近似の頂点を計算する;
- 両方の点や線を同じ座標軸上にプロットし、直接比較する。
このプロセスは、円や楕円、その他の滑らかな曲線など、近似の品質を評価するために視覚的な違いが重要となる場合に特に有用です。
12345678910111213141516171819202122232425import numpy as np import matplotlib.pyplot as plt # Parameters for the circle center = (0, 0) radius = 1 # Generate points for the original circle theta = np.linspace(0, 2 * np.pi, 500) x_circle = center[0] + radius * np.cos(theta) y_circle = center[1] + radius * np.sin(theta) # Generate points for the polygonal approximation (e.g., hexagon) num_sides = 6 theta_poly = np.linspace(0, 2 * np.pi, num_sides + 1) x_poly = center[0] + radius * np.cos(theta_poly) y_poly = center[1] + radius * np.sin(theta_poly) plt.figure(figsize=(6,6)) plt.plot(x_circle, y_circle, label="Original Circle", color="blue") plt.plot(x_poly, y_poly, label="Polygonal Approximation", color="red", linestyle="--", marker="o") plt.gca().set_aspect("equal") plt.legend() plt.title("Comparison of Circle and Polygonal Approximation") plt.show()
すべて明確でしたか?
フィードバックありがとうございます!
セクション 3. 章 6
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください
セクション 3. 章 6