Added Rot3D
This commit is contained in:
parent
2a7addfcfb
commit
2d209069a3
6
.idea/MatrixMania.iml
generated
6
.idea/MatrixMania.iml
generated
@ -7,4 +7,10 @@
|
|||||||
<orderEntry type="jdk" jdkName="Python 3.12 (MatrixMania)" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="Python 3.12 (MatrixMania)" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="PackageRequirementsSettings">
|
||||||
|
<option name="requirementsPath" value="" />
|
||||||
|
</component>
|
||||||
|
<component name="TestRunnerService">
|
||||||
|
<option name="PROJECT_TEST_RUNNER" value="py.test" />
|
||||||
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@ -74,7 +74,32 @@ def rot_2D(angle: int) -> List[List[float]]:
|
|||||||
|
|
||||||
return [[zahl1, zahl2], [zahl3, zahl4]]
|
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__":
|
if __name__ == "__main__":
|
||||||
"alles selbst gemacht"
|
|
||||||
print(rot_2D())
|
print(rot_3D(90, "x"))
|
||||||
@ -12,4 +12,5 @@ def test_matmul():
|
|||||||
matrix_c = matmul(matrix_a, matrix_b)
|
matrix_c = matmul(matrix_a, matrix_b)
|
||||||
print(f"Matrix A: {matrix_a} mal Matrix B: {matrix_b} = Matrix C: {matrix_c}")
|
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)
|
result = rot_2D(angle)
|
||||||
print(f"Angle:{angle} Rot-Matrix:{result}")
|
print(f"Angle:{angle} Rot-Matrix:{result}")
|
||||||
|
|
||||||
|
assert result == [[6.123233995736766e-17, -1.0], [1.0, 6.123233995736766e-17]]
|
||||||
|
|
||||||
|
|
||||||
1
tests/test_rot3D.py
Normal file
1
tests/test_rot3D.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from matrixmania import rot_3D
|
||||||
1
tests/test_transpose.py
Normal file
1
tests/test_transpose.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from matrixmania import transpose
|
||||||
Loading…
x
Reference in New Issue
Block a user