added projection functin
This commit is contained in:
parent
e0891258d2
commit
bd962791ff
@ -1 +1 @@
|
|||||||
from .compute import matmul, transpose, rot_2D, rot_3D
|
from .compute import matmul, transpose, rot_2D, rot_3D, project_ortho
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import math
|
import math
|
||||||
from typing import List
|
from typing import List, Tuple
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
|
|
||||||
def matmul(matrix_a:List[List[float]], matrix_b:List[List[float]]) -> List[List[float]]:
|
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:
|
else:
|
||||||
raise ValueError("Axis not valid")
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
@ -133,3 +135,6 @@ if __name__ == "__main__":
|
|||||||
print("rotation matrix for 90° on the y axis:")
|
print("rotation matrix for 90° on the y axis:")
|
||||||
print(tabulate(R))
|
print(tabulate(R))
|
||||||
|
|
||||||
|
print("Projection:")
|
||||||
|
print(project_ortho((0.5, -0.5, 10), scale=200)) # -> (100, -100)
|
||||||
|
|
||||||
|
|||||||
10
test/test_projection.py
Normal file
10
test/test_projection.py
Normal 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)
|
||||||
Loading…
x
Reference in New Issue
Block a user