Compare commits
11
Commits
33cd450bf8
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f77f3cabc4 | ||
|
|
757562ede9 | ||
|
|
a50e9bfb91 | ||
|
|
130e6c36f4 | ||
|
|
3a027799d1 | ||
|
|
7973718285 | ||
|
|
2d209069a3 | ||
|
|
2a7addfcfb | ||
|
|
ecf8123f1e | ||
|
|
1634544150 | ||
|
|
48caafb0d6 |
Generated
+6
@@ -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>
|
||||||
@@ -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 @@
|
|||||||
from .compute import matmul, transpose, rot_2D
|
from .compute import matmul, transpose, rot_2D, rot_3D , project_ortho
|
||||||
+30
-2
@@ -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 = [
|
||||||
@@ -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