From 848326ab4d73140fb5bd183f4ac673f2047e09da Mon Sep 17 00:00:00 2001 From: Mona Benkert Date: Tue, 4 Nov 2025 16:57:28 +0100 Subject: [PATCH] neuer commit --- matrixmania/compute.py | 34 +++++++++++++++++++++++++++++++--- test/__init__py.py | 0 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 test/__init__py.py diff --git a/matrixmania/compute.py b/matrixmania/compute.py index 4c0c7cf..eb0d0c7 100644 --- a/matrixmania/compute.py +++ b/matrixmania/compute.py @@ -49,9 +49,37 @@ def transpose(matrix:List[List[int]]) -> List[List[int]]: def rot_2D(angle: float) -> List[List[float]]: - rot_matrix = [[math.cos(angle), -math.sin(angle)], - [math.sin(angle), math.cos(angle)]] - return rot_matrix + ''' + calculates the rotation matrix in 2D + :param angle: the angle + :return: rotation matrix + ''' + return [[math.cos(angle), -math.sin(angle)], + [math.sin(angle), math.cos(angle)]] + +def rot_3D(angle: float, axis: str) -> List[List[float]]: + ''' + calculates the rotation matrix for one 3D axis + :param angle: the angle + :param axis: the axis + :return: rotation matrix for the wanted axis + ''' + axis = axis.lower() + if axis == "x": + return [[1, 0, 0], + [0, math.cos(angle), -math.sin(angle)], + [0, math.sin(angle), math.cos(angle)]] + elif axis == "y": + return [[math.cos(angle), 0, math.sin(angle)], + [0, 1, 0], + [-math.sin(angle), 0, math.cos(angle)]] + elif axis == "z": + return [[math.cos(angle), -math.sin(angle), 0], + [math.sin(angle), math.cos(angle), 0], + [0, 0, 1]] + else: + raise ValueError("Axis not valid") + if __name__ == "__main__": diff --git a/test/__init__py.py b/test/__init__py.py new file mode 100644 index 0000000..e69de29