diff --git a/__init__.py b/__init__.py index 487bd79..0333d0b 100644 --- a/__init__.py +++ b/__init__.py @@ -1,3 +1,3 @@ -from .compute import matmul, rot_2D, rot_3D, transpose +from .compute import matmul, project_ortho, rot_2D, rot_3D, transpose -__all__ = ["matmul", "rot_2D", "rot_3D", "transpose"] +__all__ = ["matmul", "project_ortho", "rot_2D", "rot_3D", "transpose"] diff --git a/compute.py b/compute.py index 83201b7..71a72f8 100644 --- a/compute.py +++ b/compute.py @@ -95,6 +95,24 @@ def rot_3D(angle: float, axis: str) -> list[list[float]]: 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 onto the xy-plane and apply a scale factor. + + The z-coordinate is ignored. The returned x- and y-coordinates are each + multiplied by ``scale``. + + Args: + point: The 3D point as an (x, y, z) tuple. + scale: The scale factor to apply to x and y. + + Returns: + The scaled 2D point as an (x, y) tuple. + """ + return point[0] * scale, point[1] * scale + + def _validate_matrix(matrix: list[list[float]], name: str) -> None: """Raise ValueError unless matrix is non-empty and rectangular.""" if not matrix: