Added Rot3D

This commit is contained in:
marcelbls
2025-11-06 16:32:30 +01:00
parent 2a7addfcfb
commit 2d209069a3
6 changed files with 38 additions and 2 deletions
+6
View File
@@ -7,4 +7,10 @@
<orderEntry type="jdk" jdkName="Python 3.12 (MatrixMania)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PackageRequirementsSettings">
<option name="requirementsPath" value="" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="py.test" />
</component>
</module>
+27 -2
View File
@@ -74,7 +74,32 @@ def rot_2D(angle: int) -> List[List[float]]:
return [[zahl1, zahl2], [zahl3, zahl4]]
def rot_3D(angle: float, axis: str) -> List[List[float]]:
"""
Rotation matrix 3D
:param angle: between 0 and 360 degrees
:param axis: x,y,z axis of rotation matrix
:return: 3D rotation matrix
"""
if angle > 360:
raise ValueError("angle must be less than 360")
elif angle < 0:
raise ValueError("angle must be greater than 0")
cos = math.cos(math.radians(angle))
sin = math.sin(math.radians(angle))
if axis == "x":
return [[1,0,0],[0, cos, -sin],[0, sin, cos]]
elif axis == "y":
return [[cos, 0, sin],[0,1,0],[-sin,0,cos]]
elif axis == "z":
return [[cos, -sin, 0],[sin, cos, 0],[0, 0, 1]]
else:
raise ValueError("Not a valid axis. Choose from 'x', 'y', 'z'.")
if __name__ == "__main__":
"alles selbst gemacht"
print(rot_2D())
print(rot_3D(90, "x"))
+1
View File
@@ -12,4 +12,5 @@ def test_matmul():
matrix_c = matmul(matrix_a, matrix_b)
print(f"Matrix A: {matrix_a} mal Matrix B: {matrix_b} = Matrix C: {matrix_c}")
assert matrix_c == [[20, 37, 26], [-1, 27, -8]]
@@ -5,4 +5,6 @@ def test_rot_2D():
result = rot_2D(angle)
print(f"Angle:{angle} Rot-Matrix:{result}")
assert result == [[6.123233995736766e-17, -1.0], [1.0, 6.123233995736766e-17]]
+1
View File
@@ -0,0 +1 @@
from matrixmania import rot_3D
+1
View File
@@ -0,0 +1 @@
from matrixmania import transpose