fourth commit: test_rot added
This commit is contained in:
1 parent
cd3da3dde1
commit
043440e38c
3 files changed
+62
No files matched your search
@@ -91,6 +91,58 @@ def rot_2D(theta: float) -> list[list[float]]:
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def rot_3D(angle: float, axis: str) -> list[list[float]]:
|
||||||
|
"""Return a 3‑D rotation matrix.
|
||||||
|
|
||||||
|
The function converts *angle* from degrees to radians and builds the
|
||||||
|
standard rotation matrix around the requested *axis*.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
angle: Rotationswinkel in Grad.
|
||||||
|
axis: ``"x"``, ``"y"`` oder ``"z"`` – der Drehachse.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
3x3 Rotationsmatrix als verschachtelte Listen.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError: Wenn *axis* keinen gültigen Wert hat.
|
||||||
|
"""
|
||||||
|
# Validate axis
|
||||||
|
axis_lower = axis.lower()
|
||||||
|
if axis_lower not in {"x", "y", "z"}:
|
||||||
|
raise ValueError(
|
||||||
|
f"Unbekannte Achse '{axis}'. Erwartet: 'x', 'y' oder 'z'."
|
||||||
|
)
|
||||||
|
|
||||||
|
# Convert degrees to radians for math functions
|
||||||
|
rad = math.radians(angle)
|
||||||
|
c = math.cos(rad)
|
||||||
|
s = math.sin(rad)
|
||||||
|
|
||||||
|
if axis_lower == "x":
|
||||||
|
return [
|
||||||
|
[1, 0, 0],
|
||||||
|
[0, c, -s],
|
||||||
|
[0, s, c],
|
||||||
|
]
|
||||||
|
if axis_lower == "y":
|
||||||
|
return [
|
||||||
|
[c, 0, s],
|
||||||
|
[0, 1, 0],
|
||||||
|
[
|
||||||
|
-s,
|
||||||
|
0,
|
||||||
|
c,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
# z
|
||||||
|
return [
|
||||||
|
[c, -s, 0],
|
||||||
|
[s, c, 0],
|
||||||
|
[0, 0, 1],
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
#matmul prüfung
|
#matmul prüfung
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
from compute import matmul, transpose, rot_2D
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
def test_matrixmania():
|
||||||
|
#Arrange
|
||||||
|
|
||||||
|
|
||||||
|
#Act
|
||||||
|
|
||||||
|
|
||||||
|
#Assert
|
||||||
Reference in new issue
Block a user