Compare commits
14
Commits
888049460e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f77f3cabc4 | ||
|
|
757562ede9 | ||
|
|
a50e9bfb91 | ||
|
|
130e6c36f4 | ||
|
|
3a027799d1 | ||
|
|
7973718285 | ||
|
|
2d209069a3 | ||
|
|
2a7addfcfb | ||
|
|
ecf8123f1e | ||
|
|
1634544150 | ||
|
|
48caafb0d6 | ||
|
|
33cd450bf8 | ||
|
|
606b65d42a | ||
|
|
75ddfae44e |
@@ -0,0 +1 @@
|
||||
/matrixmania/dist/
|
||||
Generated
+6
@@ -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>
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
from .compute import matmul, transpose, rot_2D, rot_3D , project_ortho
|
||||
@@ -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]
|
||||
]))
|
||||
@@ -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"]
|
||||
@@ -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]]
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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]]
|
||||
|
||||
|
||||
@@ -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]]
|
||||
|
||||
|
||||
|
||||
@@ -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]]
|
||||
Reference in New Issue
Block a user