diff --git a/compute.py b/compute.py index 7d7c6df..ee4d6da 100644 --- a/compute.py +++ b/compute.py @@ -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 diff --git a/install_dependencies.py b/install_dependencies.py index 5a20e39..44c21c5 100644 --- a/install_dependencies.py +++ b/install_dependencies.py @@ -141,6 +141,5 @@ def main() -> int: finally: tmp_path.unlink(missing_ok=True) - if __name__ == "__main__": raise SystemExit(main()) diff --git a/test_matrixmania/test_projection.py b/test_matrixmania/test_projection.py new file mode 100644 index 0000000..c995459 --- /dev/null +++ b/test_matrixmania/test_projection.py @@ -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 \ No newline at end of file diff --git a/test_rot.py b/test_matrixmania/test_rot.py similarity index 100% rename from test_rot.py rename to test_matrixmania/test_rot.py