diff --git a/matrixmania/__init__.py b/matrixmania/__init__.py index e3601ab..c9175b3 100644 --- a/matrixmania/__init__.py +++ b/matrixmania/__init__.py @@ -1 +1 @@ -from .compute import matmul, transpose, rot_2D, rot_3D +from .compute import matmul, transpose, rot_2D, rot_3D, project_ortho diff --git a/matrixmania/compute.py b/matrixmania/compute.py index 5f285d4..d667f81 100644 --- a/matrixmania/compute.py +++ b/matrixmania/compute.py @@ -1,5 +1,5 @@ import math -from typing import List +from typing import List, Tuple from tabulate import tabulate def matmul(matrix_a:List[List[float]], matrix_b:List[List[float]]) -> List[List[float]]: @@ -80,7 +80,9 @@ def rot_3D(angle: float, axis: str) -> List[List[float]]: else: raise ValueError("Axis not valid") - +def project_ortho(point: Tuple[float, float, float], scale: float = 1) -> Tuple[float, float]: + point_2D = (point[0] * scale, point[1] * scale) + return point_2D if __name__ == "__main__": @@ -133,3 +135,6 @@ if __name__ == "__main__": print("rotation matrix for 90° on the y axis:") print(tabulate(R)) + print("Projection:") + print(project_ortho((0.5, -0.5, 10), scale=200)) # -> (100, -100) + diff --git a/test/test_projection.py b/test/test_projection.py new file mode 100644 index 0000000..e131987 --- /dev/null +++ b/test/test_projection.py @@ -0,0 +1,10 @@ +from matrixmania import project_ortho + +def test_projection_1(): + point = (1.0, 2.0, 3.0) + assert project_ortho(point) == (1.0, 2.0) + +def test_projection_2(): + point = (1.0, 2.0, 3.0) + scale = 100 + assert project_ortho(point, scale) == (100.0, 200.0)