From 043440e38c891c0a1cc7271f58e9e44f1eca7211 Mon Sep 17 00:00:00 2001 From: Tia Lechner Date: Tue, 20 Oct 2026 17:10:07 +0200 Subject: [PATCH] fourth commit: test_rot added --- src/matrixmania/compute.py | 52 +++++++++++++++++++++++++++++++ test/test_matrixmania/__init__.py | 1 + test/test_matrixmania/test_rot.py | 9 ++++++ 3 files changed, 62 insertions(+) create mode 100644 test/test_matrixmania/__init__.py create mode 100644 test/test_matrixmania/test_rot.py diff --git a/src/matrixmania/compute.py b/src/matrixmania/compute.py index 1dfa002..55d9c96 100644 --- a/src/matrixmania/compute.py +++ b/src/matrixmania/compute.py @@ -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__": #matmul prüfung diff --git a/test/test_matrixmania/__init__.py b/test/test_matrixmania/__init__.py new file mode 100644 index 0000000..2eeb846 --- /dev/null +++ b/test/test_matrixmania/__init__.py @@ -0,0 +1 @@ +from compute import matmul, transpose, rot_2D \ No newline at end of file diff --git a/test/test_matrixmania/test_rot.py b/test/test_matrixmania/test_rot.py new file mode 100644 index 0000000..26f6a69 --- /dev/null +++ b/test/test_matrixmania/test_rot.py @@ -0,0 +1,9 @@ + +def test_matrixmania(): + #Arrange + + + #Act + + + #Assert \ No newline at end of file