From 1f4d735bbf38a3e7ce160bdf0e5528fb73060803 Mon Sep 17 00:00:00 2001 From: Leon Zielinski Date: Tue, 20 Oct 2026 16:46:39 +0200 Subject: [PATCH] orthogonale Projektion --- src/matrixmania/compute.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/matrixmania/compute.py b/src/matrixmania/compute.py index ebea4e0..c56df6f 100644 --- a/src/matrixmania/compute.py +++ b/src/matrixmania/compute.py @@ -220,6 +220,40 @@ def rot_3D(angle: float, axis: str) -> list[list[float]]: return [[c, -s, 0.0], [s, c, 0.0], [0.0, 0.0, 1.0]] +def project_ortho( + point: tuple[float, float, float], scale: float = 1 +) -> tuple[float, float]: + """Orthogonally projects a 3D point onto the 2D plane. + + The viewer looks head‑on onto the plane spanned by the x‑ and + y‑axis, so the z‑coordinate (the distance of the point) is simply + ignored. The remaining coordinates are multiplied with ``scale``, + e.g. to map model coordinates onto screen pixels:: + + project_ortho((0.5, -0.5, 10), scale=200) # -> (100, -100) + + Parameters + ---------- + point : tuple[float, float, float] + 3D point ``(x, y, z)`` in model coordinates. + scale : float, optional + Factor the projected x‑ and y‑coordinates are multiplied with + (default ``1``, i.e. no scaling). + + Returns + ------- + tuple[float, float] + 2D point ``(x * scale, y * scale)`` without the z‑coordinate. + + Notes + ----- + * Orthogonal projection means there is no perspective foreshortening: + distant points have the same size as nearby ones. + """ + x, y, _z = point + return (x * scale, y * scale) + + if __name__ == "__main__": # Beispiel 1: 2x3 × 3x2 a = [[1, 2, 3], [4, 5, 6]] @@ -265,6 +299,10 @@ if __name__ == "__main__": for row in matmul(r3, [[1.0], [0.0], [0.0]]): print([round(v, 10) for v in row]) + # Beispiel 6: Orthogonale Projektion eines 3D-Punktes auf 2D + print("\nBeispiel 6 Projektion (0.5, -0.5, 10) mit scale=200:") + print(project_ortho((0.5, -0.5, 10), scale=200)) + # Docstring und Type Hints sind vorhanden und stimmen mit dem Code überein. # Fehlerfälle werden behandelt # Namen sind Aussagekräftig