Add 3D rotation and rotation tests

This commit is contained in:
Amalia Sucipto committed 2026-10-22 14:55:57 +02:00
1 parent ebfe4630ee
commit 17eff74d0c
4 files changed
+231

No files matched your search

+40
View File
@@ -135,6 +135,46 @@ def rot_2D(theta: float) -> Matrix:
[sin(theta), cos(theta)],
]
def rot_3D(angle: float, axis: str) -> list[list[float]]:
"""Create a 3D rotation matrix around the specified axis.
Args:
angle: Rotation angle in radians.
axis: Axis of rotation ('x', 'y', or 'z').
Returns:
A 3x3 rotation matrix.
Raises:
ValueError: If the specified axis is invalid.
"""
c = cos(angle)
s = sin(angle)
if axis == "x":
return [
[1.0, 0.0, 0.0],
[0.0, c, -s],
[0.0, s, c],
]
elif axis == "y":
return [
[c, 0.0, s],
[0.0, 1.0, 0.0],
[-s, 0.0, c],
]
elif axis == "z":
return [
[c, -s, 0.0],
[s, c, 0.0],
[0.0, 0.0, 1.0],
]
else:
raise ValueError("Axis must be 'x', 'y', or 'z'.")
if __name__ == "__main__":
# Beispiel Multiplikation