added projection functin

This commit is contained in:
Mona Benkert 2025-11-25 14:24:33 +01:00
parent e0891258d2
commit bd962791ff
3 changed files with 18 additions and 3 deletions

View File

@ -1 +1 @@
from .compute import matmul, transpose, rot_2D, rot_3D
from .compute import matmul, transpose, rot_2D, rot_3D, project_ortho

View File

@ -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)

10
test/test_projection.py Normal file
View File

@ -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)