orthogonale Projektion

This commit is contained in:
Leon Zielinski committed 2026-10-20 16:46:39 +02:00
1 parent e4b83bd77d
commit 1f4d735bbf
1 file changed
+38
+38
View File
@@ -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]] 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__": if __name__ == "__main__":
# Beispiel 1: 2x3 × 3x2 # Beispiel 1: 2x3 × 3x2
a = [[1, 2, 3], [4, 5, 6]] 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]]): for row in matmul(r3, [[1.0], [0.0], [0.0]]):
print([round(v, 10) for v in row]) 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. # Docstring und Type Hints sind vorhanden und stimmen mit dem Code überein.
# Fehlerfälle werden behandelt # Fehlerfälle werden behandelt
# Namen sind Aussagekräftig # Namen sind Aussagekräftig