Compare commits

..
11 Commits
Author SHA1 Message Date
marcelbls f77f3cabc4 new Version eingetragen 2025-11-20 14:40:34 +01:00
marcelbls 757562ede9 alle tests klappen 2025-11-20 14:39:41 +01:00
marcelbls a50e9bfb91 add project_ortho tests 2025-11-20 14:26:30 +01:00
marcelbls 130e6c36f4 add project_ortho 2025-11-20 14:20:08 +01:00
marcelbls 3a027799d1 some changes 2025-11-06 16:56:00 +01:00
marcelbls 7973718285 added rot3d test 2025-11-06 16:36:09 +01:00
marcelbls 2d209069a3 Added Rot3D 2025-11-06 16:32:30 +01:00
marcelbls 2a7addfcfb Added Tests 2025-11-06 16:14:43 +01:00
marcelbls ecf8123f1e new version 2025-11-06 15:39:09 +01:00
marcelbls 1634544150 new version 2025-11-06 15:37:20 +01:00
marcelbls 48caafb0d6 new version 2025-11-06 15:36:04 +01:00
11 changed files with 101 additions and 4 deletions
+6
View File
@@ -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>
+5
View File
@@ -14,3 +14,8 @@ Gibt die Transponierte einer gegebenen Matrix zurück (Zeilen und Spalten werden
Erzeugt eine 2D-Rotationsmatrix für einen gegebenen Winkel (in Grad). Erzeugt eine 2D-Rotationsmatrix für einen gegebenen Winkel (in Grad).
Diese Matrix kann verwendet werden, um Punkte in der Ebene um den Ursprung zu rotieren. Diese Matrix kann verwendet werden, um Punkte in der Ebene um den Ursprung zu rotieren.
**rot_3D(angle, axis):**
Erzeugt eine 3D-Rotationsmatrix für gegebenen Winkel und der gegebenen Achse.
Achse x, y oder z und Wikel zwischen 0 und 360
+1 -1
View File
@@ -1 +1 @@
from .compute import matmul, transpose, rot_2D from .compute import matmul, transpose, rot_2D, rot_3D , project_ortho
+30 -2
View File
@@ -1,6 +1,7 @@
from typing import List from typing import List
import math import math
from tabulate import tabulate from tabulate import tabulate
from typing import Tuple
def matmul(matrix_a: List[List[int]], matrix_b: List[List[int]]) -> List[List[int]]: def matmul(matrix_a: List[List[int]], matrix_b: List[List[int]]) -> List[List[int]]:
""" """
@@ -74,7 +75,34 @@ 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
"""
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'.")
def project_ortho(point: Tuple[float, float, float], scale: float = 1) -> Tuple[float, float]:
return (point[0]*scale, point[1]*scale)
if __name__ == "__main__": if __name__ == "__main__":
"alles selbst gemacht"
print(rot_2D()) print(rot_3D(-90, "x"))
print(transpose([
[1, 2, 3],
[4, 5, 6]
]))
@@ -1,6 +1,6 @@
[project] [project]
name = "matrixmania_marcel" name = "matrixmania_marcel"
version = "0.1.0" version = "0.3.0"
description = "MatrixMania: Simple linear algebra functions for teaching (matmul, transpose, rot_2D)." description = "MatrixMania: Simple linear algebra functions for teaching (matmul, transpose, rot_2D)."
authors = [ authors = [
+16
View File
@@ -0,0 +1,16 @@
from matrixmania.compute import matmul
def test_matmul():
matrix_a = [[3, 4, -1, 4],
[-2, 2, 5, 1]
]
matrix_b = [[1, 3, -2],
[2, 5, 1],
[-1, 4, -4],
[2, 3, 6]
]
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]]
+11
View File
@@ -0,0 +1,11 @@
from matrixmania.compute import project_ortho
def test_projection():
point = (1.0, 2.0, 3.0)
scale = 100
result1 = project_ortho(point, scale)
result2 = project_ortho(point)
assert result1 == (100, 200)
assert result2 == (1, 2)
+10
View File
@@ -0,0 +1,10 @@
from matrixmania.compute import rot_2D
def test_rot_2D():
angle = 90
result = rot_2D(angle)
print(f"Angle:{angle} Rot-Matrix:{result}")
assert result == [[6.123233995736766e-17, -1.0], [1.0, 6.123233995736766e-17]]
+11
View File
@@ -0,0 +1,11 @@
from matrixmania.compute import rot_3D
def test_rot_3D():
angle = 90
result = rot_3D(angle,"x")
print(f"Angle:{angle} Rot-Matrix:{result}")
assert result == [[1, 0, 0], [0, 6.123233995736766e-17, -1.0], [0, 1.0, 6.123233995736766e-17]]
+10
View File
@@ -0,0 +1,10 @@
from matrixmania.compute import transpose
def test_transpose():
matrix = [
[1, 2, 3],
[4, 5, 6]
]
matrix = transpose(matrix)
assert matrix == [[1, 4],[2, 5],[3, 6]]