Add orthogonal projection and unit tests
This commit is contained in:
1 parent
05ea67eed0
commit
521c35f621
2 files changed
+40
No files matched your search
@@ -143,6 +143,31 @@ def rot_3D(angle: float, axis: str) -> list[list[float]]:
|
||||
]
|
||||
raise ValueError("Axis must be one of 'x', 'y', or 'z'.")
|
||||
|
||||
def project_ortho(point: tuple[float, float, float], scale: float = 1.0) -> tuple[float, float]:
|
||||
"""Orthogonal projection of a 3‑D point onto the xy‑plane.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
point : tuple[float, float, float]
|
||||
Cartesian coordinates (x, y, z).
|
||||
scale : float, optional
|
||||
Scaling factor applied to x and y after projection. Defaults to 1.
|
||||
|
||||
Returns
|
||||
-------
|
||||
tuple[float, float]
|
||||
Projected 2‑D coordinates (x_scaled, y_scaled).
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> project_ortho((1, 2, 3))
|
||||
(1, 2)
|
||||
"""
|
||||
if len(point) != 3:
|
||||
raise ValueError("Point must be a 3‑tuple.")
|
||||
return (point[0] * scale, point[1] * scale)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import pytest
|
||||
|
||||
from matrixmania.compute import project_ortho
|
||||
|
||||
|
||||
def test_project_ortho_default():
|
||||
"""Projektionsfunktion ohne Skalierung"""
|
||||
point = (1.0, 2.0, 3.0)
|
||||
assert project_ortho(point) == (1.0, 2.0)
|
||||
|
||||
|
||||
def test_project_ortho_scaled():
|
||||
"""Projektionsfunktion mit Skalierung"""
|
||||
point = (1.0, 2.0, 3.0)
|
||||
assert project_ortho(point, scale=100) == (100.0, 200.0)
|
||||
Reference in new issue
Block a user