Compare commits

...
14 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
marcelbls 33cd450bf8 Getting ready for Testing 2025-11-06 14:36:42 +01:00
marcelbls 606b65d42a Merge remote-tracking branch 'origin/main'
# Conflicts:
#	compute..py
2025-11-05 14:58:39 +01:00
marcelbls 75ddfae44e alles selbst geamcht 2025-11-05 14:57:53 +01:00
11 changed files with 136 additions and 4 deletions
+1
View File
@@ -0,0 +1 @@
/matrixmania/dist/
+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>
+21
View File
@@ -0,0 +1,21 @@
## Compute.py
### Functions:
**matmul(matrix_a, matrix_b):**
Multipliziert zwei Matrizen miteinander und gibt das Produkt als neue Matrix zurück.
Wirft einen ValueError, wenn die Matrizen aufgrund unpassender Dimensionen nicht multiplizierbar sind.
**transpose(matrix):**
Gibt die Transponierte einer gegebenen Matrix zurück (Zeilen und Spalten werden vertauscht).
Überprüft, ob die Matrix leer oder fehlerhaft aufgebaut ist, und wirft in diesem Fall einen ValueError.
**rot_2D(angle):**
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.
**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
View File
@@ -0,0 +1 @@
from .compute import matmul, transpose, rot_2D, rot_3D , project_ortho
+32 -4
View File
@@ -1,6 +1,7 @@
from typing import List
import math
from tabulate import tabulate
from typing import Tuple
def matmul(matrix_a: List[List[int]], matrix_b: List[List[int]]) -> List[List[int]]:
"""
@@ -61,10 +62,10 @@ def transpose(matrix: list[list[int]]) -> list[list[int]]:
return ergebnis2
def rot_2D(angle: int) -> List[List[int]]:
def rot_2D(angle: int) -> List[List[float]]:
"""
Rotation matrix
:param angle: any angle
:param angle: any angle in degrees
:return: rotation matrix
"""
zahl1 = math.cos(math.radians(angle))
@@ -74,7 +75,34 @@ def rot_2D(angle: int) -> List[List[int]]:
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__":
#made by chatGBT
print(rot_2D())
print(rot_3D(-90, "x"))
print(transpose([
[1, 2, 3],
[4, 5, 6]
]))
+17
View File
@@ -0,0 +1,17 @@
[project]
name = "matrixmania_marcel"
version = "0.3.0"
description = "MatrixMania: Simple linear algebra functions for teaching (matmul, transpose, rot_2D)."
authors = [
{ name="Dein Name", email="deine.mail@th-nuernberg.de" }
]
readme = "README.md"
license = { text = "MIT" }
requires-python = ">=3.7"
dependencies = ["tabulate"]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.build.targets.wheel]
packages = ["matrixmania"]
+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]]