mathematik2/matrix/rotation.py

70 lines
2.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#%%
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()
# %%