Aufgabe Orthogonale Projektion

This commit is contained in:
kuehnleinma103760 committed 2026-10-22 17:10:39 +02:00
1 parent 3f7c8b1195
commit 262f0c3dab
3 files changed
+53 -2

No files matched your search

+2 -2
View File
@@ -1,5 +1,5 @@
"""MatrixMania - Paket für Matrixoperationen."""
from .compute import matmul, rot_2d, rot_3d, transpose
from .compute import matmul, project_ortho, rot_2d, rot_3d, transpose
__all__ = ["matmul", "rot_2d", "rot_3d", "transpose"]
__all__ = ["matmul", "project_ortho", "rot_2d", "rot_3d", "transpose"]
+23
View File
@@ -132,6 +132,22 @@ def rot_3d(angle: float, axis: str) -> list[list[float]]:
]
def project_ortho(
point: tuple[float, float, float], scale: float = 1
) -> tuple[float, float]:
"""Projiziert einen 3D-Punkt orthogonal auf eine 2D-Ebene und skaliert ihn.
Die z-Koordinate wird ignoriert und die x- und y-Koordinaten werden
mit dem Skalierungsfaktor multipliziert.
:param point: Der 3D-Punkt als Tupel (x, y, z).
:param scale: Der Skalierungsfaktor für die Projektion (Standardwert 1).
:return: Der skalierte 2D-Punkt als Tupel (x, y).
"""
x, y, _ = point
return x * scale, y * scale
def test_functions() -> None:
"""Testet die mathematischen Hilfsfunktionen für Matrixoperationen."""
a1 = [
@@ -266,6 +282,13 @@ def test_functions() -> None:
except ValueError:
print("Test 13 (rot_3d ungültige Achse) erfolgreich abgefangen!")
# Test 14: project_ortho
projected = project_ortho((0.5, -0.5, 10.0), scale=200)
assert projected == (100.0, -100.0), (
f"Fehler in project_ortho: Erwartet (100.0, -100.0), erhalten {projected}"
)
print("Test 14 (project_ortho) erfolgreich bestanden!")
if __name__ == "__main__":
print(tabulate(rot_2d(1.0)))
+28
View File
@@ -0,0 +1,28 @@
"""Unit-Tests für orthogonale Projektionen in compute.py."""
from matrixmania.compute import project_ortho
def test_project_ortho_default_scale() -> None:
"""Testet die orthogonale Projektion mit Standard-Skalierungsfaktor."""
# Arrange
point = (1.0, 2.0, 3.0)
# Act
result = project_ortho(point)
# Assert
assert result == (1.0, 2.0)
def test_project_ortho_scaled() -> None:
"""Testet die orthogonale Projektion mit einem Skalierungsfaktor von 100."""
# Arrange
point = (1.0, 2.0, 3.0)
scale = 100
# Act
result = project_ortho(point, scale=scale)
# Assert
assert result == (100.0, 200.0)