From e3fccb6a034bbae35dc8165ba65f9f5b8cc65ec2 Mon Sep 17 00:00:00 2001 From: git-sandro Date: Sat, 31 Oct 2026 14:14:29 +0100 Subject: [PATCH] Graphische beschreibung von Matrix Multiplikation --- matrix/projektion.py | 37 +++++++++++++++++++ matrix/rotation.py | 69 +++++++++++++++++++++++++++++++++++ matrix/streckung_stauchung.py | 34 +++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 matrix/projektion.py create mode 100644 matrix/rotation.py create mode 100644 matrix/streckung_stauchung.py diff --git a/matrix/projektion.py b/matrix/projektion.py new file mode 100644 index 0000000..d69ff17 --- /dev/null +++ b/matrix/projektion.py @@ -0,0 +1,37 @@ +#%% +import matplotlib.pyplot as plt +import numpy as np +from mpl_toolkits.mplot3d import Axes3D + +fig = plt.figure(figsize=(9, 7)) +ax = fig.add_subplot(111, projection='3d') + +# Vektoren definieren +vektoren = { + r'$\vec{a}$': (2, -1, 2), + r'$P \cdot \vec{a}$': (2, -1, 0) +} + +farben = ['#2196F3', '#FF5722'] + +for (name, wert), farbe in zip(vektoren.items(), farben): + ax.quiver(0, 0, 0, *wert, color=farbe, lw=2.5, arrow_length_ratio=0.1) + # Beschriftung am Pfeilende + ax.text(wert[0] * 1.05, wert[1] * 1., wert[2] + 0.1, + name, fontsize=13, color=farbe, fontweight='bold') + +# Projektion von a auf die xy-Ebene gestrichelt +ax.plot([2, 2], [-1, -1], [0, 2], 'k--', lw=1, alpha=0.5) + +# Achsen +ax.set_xlabel('x') +ax.set_ylabel('y') +ax.set_zlabel('z') +ax.set_title('Projektion', fontsize=14) + +# Ansichtswinkel +ax.view_init(elev=20, azim=45) + +plt.tight_layout() +plt.savefig('vektoren_3d.png', dpi=150) +plt.show() \ No newline at end of file diff --git a/matrix/rotation.py b/matrix/rotation.py new file mode 100644 index 0000000..f2e3df2 --- /dev/null +++ b/matrix/rotation.py @@ -0,0 +1,69 @@ +#%% +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.patches import Arc + +fig, ax = plt.subplots(figsize=(7, 7)) + +# Define vectors +a = np.array([2, 2]) +R90_a = np.array([-2, 2]) +R135_a = np.array([-2 * np.sqrt(2), 0]) + +# Draw vectors +vectors = [ + (a, "steelblue", "$\\vec{a}$"), + (R90_a, "coral", "$R(90°)\\vec{a}$"), + (R135_a, "seagreen", "$R(135°)\\vec{a}$"), +] + +for vec, color, label in vectors: + ax.annotate("", xy=vec, xytext=(0, 0), + arrowprops=dict(arrowstyle="->", color=color, lw=2)) + +# Labels (individual placement for fine control) +ax.text(a[0] * 1.1, a[1] * 1.1, "$\\vec{a}$", fontsize=12, color="steelblue", + ha="center", va="center") +ax.text(R90_a[0] * 1.1, R90_a[1] * 1.1, "$R(90°)\\vec{a}$", fontsize=12, color="coral", + ha="center", va="center") +ax.text(R135_a[0] - 0.4, R135_a[1], "$R(135°)\\vec{a}$", fontsize=12, color="seagreen", + ha="center", va="center") + +# Compute angles from x-axis +angle_a = np.degrees(np.arctan2(a[1], a[0])) +angle_R90 = np.degrees(np.arctan2(R90_a[1], R90_a[0])) +angle_R135 = np.degrees(np.arctan2(R135_a[1], R135_a[0])) + +# Arc 1: angle between a and R(90°)×a +arc1 = Arc((0, 0), 2.0, 2.0, angle=0, + theta1=angle_a, theta2=angle_R90, + color="coral", linestyle="--", lw=1.5) +ax.add_patch(arc1) + +mid1 = np.radians((angle_a + angle_R90) / 2) +ax.text(1.2 * np.cos(mid1), 1.2 * np.sin(mid1), + f"{angle_R90 - angle_a:.0f}°", fontsize=11, color="coral", + ha="center", va="center") + +# Arc 2: angle between a and R(135°)×a +arc2 = Arc((0, 0), 3.2, 3.2, angle=0, + theta1=angle_a, theta2=angle_R135, + color="seagreen", linestyle="--", lw=1.5) +ax.add_patch(arc2) + +mid2 = np.radians((angle_a + angle_R135) / 2) +ax.text(1.9 * np.cos(mid2), 1.9 * np.sin(mid2), + f"{angle_R135 - angle_a:.0f}°", fontsize=11, color="seagreen", + ha="center", va="center") + +# Axes +ax.axhline(0, color="lightgray", lw=0.5) +ax.axvline(0, color="lightgray", lw=0.5) +ax.set_xlim(-4, 3) +ax.set_ylim(-0.5, 3) +ax.set_aspect("equal") +ax.grid(True, alpha=0.3) +ax.set_title("Rotation zu $\\vec{a}$") +plt.tight_layout() +plt.show() +# %% diff --git a/matrix/streckung_stauchung.py b/matrix/streckung_stauchung.py new file mode 100644 index 0000000..197ba67 --- /dev/null +++ b/matrix/streckung_stauchung.py @@ -0,0 +1,34 @@ +#%% +import matplotlib.pyplot as plt +import numpy as np + +fig, ax = plt.subplots(figsize=(8, 8)) + +# Vektoren definieren +vektoren = { + r'$\vec{a}$': (2, 1), + r'$S \cdot \vec{a}$': (1, 2), + r'$S \cdot (S \cdot \vec{a})$': (0.5, 4) +} + +farben = ['#2196F3', '#FF5722', '#4CAF50'] + +for (name, wert), farbe in zip(vektoren.items(), farben): + ax.annotate('', xy=wert, xytext=(0, 0), + arrowprops=dict(arrowstyle='->', lw=2.5, color=farbe)) + ax.text(wert[0] * 0.5 + 0.2, wert[1] * 0.5 + 0.2, name, + fontsize=13, color=farbe, fontweight='bold') + +# Achsen und Gitter +ax.axhline(0, color='grey', lw=0.5) +ax.axvline(0, color='grey', lw=0.5) +ax.set_xlim(-0.5, 3) +ax.set_ylim(-0.5, 4.5) +ax.set_aspect('equal') +ax.grid(True, alpha=0.3) +ax.set_title('Strecken / Stauchung', fontsize=14) + +plt.tight_layout() +plt.savefig('vektoren.png', dpi=150) +plt.show() +# %%