Add orthogonal projection and tests

This commit is contained in:
Amalia Sucipto committed 2026-10-28 23:00:08 +01:00
1 parent 17eff74d0c
commit 4931d5e7dc
4 files changed
+46 -2

No files matched your search

+18 -1
View File
@@ -135,7 +135,7 @@ def rot_2D(theta: float) -> Matrix:
[sin(theta), cos(theta)],
]
def rot_3D(angle: float, axis: str) -> list[list[float]]:
def rot_3D(angle: float, axis: str) -> Matrix:
"""Create a 3D rotation matrix around the specified axis.
Args:
@@ -175,6 +175,23 @@ def rot_3D(angle: float, axis: str) -> list[list[float]]:
else:
raise ValueError("Axis must be 'x', 'y', or 'z'.")
def project_ortho(
point: tuple[float, float, float],
scale: float = 1,
) -> tuple[float, float]:
"""Project a 3D point orthogonally onto the xy-plane.
Args:
point: A 3D point containing x, y, and z coordinates.
scale: Scaling factor for the projected coordinates.
Returns:
The scaled 2D coordinates of the projected point.
"""
x, y, z = point
return (x * scale, y * scale)
if __name__ == "__main__":
# Beispiel Multiplikation
-1
View File
@@ -141,6 +141,5 @@ def main() -> int:
finally:
tmp_path.unlink(missing_ok=True)
if __name__ == "__main__":
raise SystemExit(main())
+28
View File
@@ -0,0 +1,28 @@
from compute import project_ortho
def test_project_ortho_without_scaling() -> None:
"""Test orthogonal projection without scaling."""
# Arrange
point = (1.0, 2.0, 3.0)
expected = (1.0, 2.0)
# Act
result = project_ortho(point)
# Assert
assert result == expected
def test_project_ortho_with_scaling() -> None:
"""Test orthogonal projection with a scale factor of 100."""
# Arrange
point = (1.0, 2.0, 3.0)
scale = 100
expected = (100.0, 200.0)
# Act
result = project_ortho(point, scale)
# Assert
assert result == expected
File renamed without changes.