From cbbe92c5ee8ebb385af993650d5d94eb5530636d Mon Sep 17 00:00:00 2001 From: rapplu93184 Date: Tue, 20 Oct 2026 17:17:32 +0200 Subject: [PATCH] =?UTF-8?q?ordnerstruktur=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/pyproject.toml => pyproject.toml | 0 src/matrixmania/compute.py | 56 +++++++++++++++++++++++++++ test/test_matrixmania/__init__.py | 0 test/test_matrixmania/test_rot.py | 0 4 files changed, 56 insertions(+) rename test/pyproject.toml => pyproject.toml (100%) create mode 100644 test/test_matrixmania/__init__.py create mode 100644 test/test_matrixmania/test_rot.py diff --git a/test/pyproject.toml b/pyproject.toml similarity index 100% rename from test/pyproject.toml rename to pyproject.toml diff --git a/src/matrixmania/compute.py b/src/matrixmania/compute.py index 3238529..a66646f 100644 --- a/src/matrixmania/compute.py +++ b/src/matrixmania/compute.py @@ -98,6 +98,62 @@ def rot_2D(m: Matrix | float) -> Matrix: return [[m[row][col] for row in reversed(range(rows))] for col in range(cols)] +def rot_3D(angle: float, axis: str) -> list[list[float]]: + """Gibt die Rotationsmatrix für eine Drehung um eine Achse im 3D-Raum zurück. + + Die Drehung erfolgt im rechtshändigen Koordinatensystem um den Winkel + ``angle`` (in Bogenmaß) um die angegebene Achse. + + Formeln (rechtshändiges Koordinatensystem): + Rotation um x-Achse: + [[1, 0, 0], + [0, cos(a), -sin(a)], + [0, sin(a), cos(a)]] + Rotation um y-Achse: + [[ cos(a), 0, sin(a)], + [ 0, 1, 0], + [-sin(a), 0, cos(a)]] + Rotation um z-Achse: + [[cos(a), -sin(a), 0], + [sin(a), cos(a), 0], + [0, 0, 1]] + + Args: + angle: Drehwinkel in Bogenmaß. + axis: Drehachse, muss ``'x'``, ``'y'`` oder ``'z'`` sein. + + Returns: + 3x3-Rotationsmatrix. + + Raises: + ValueError: Wenn ``axis`` kein gültiger Achsenwert ist. + """ + theta = float(angle) + c = math.cos(theta) + s = math.sin(theta) + + if axis == "x": + return [ + [1.0, 0.0, 0.0], + [0.0, c, -s], + [0.0, s, c], + ] + if axis == "y": + return [ + [c, 0.0, s], + [0.0, 1.0, 0.0], + [-s, 0.0, c], + ] + if axis == "z": + return [ + [c, -s, 0.0], + [s, c, 0.0], + [0.0, 0.0, 1.0], + ] + + raise ValueError("Achse muss 'x', 'y' oder 'z' sein.") + + diff --git a/test/test_matrixmania/__init__.py b/test/test_matrixmania/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_matrixmania/test_rot.py b/test/test_matrixmania/test_rot.py new file mode 100644 index 0000000..e69de29