Praktikum 3: Post Tests
Added DocStrings
This commit is contained in:
1 parent
10e0bd9557
commit
781fab0344
2 files changed
+48
No files matched your search
@@ -103,10 +103,37 @@ def rot_3d(angle: float, axis: str) -> list[list[float]]:
|
||||
|
||||
raise ValueError
|
||||
|
||||
# For Both below add the Doc String!
|
||||
def project_ortho(point: tuple[float, float, float], scale: float = 1) -> tuple[float, float]:
|
||||
"""
|
||||
Projects a 3D Position into an orthogonal 2D View
|
||||
:param point: The 3D Point
|
||||
:type point: tuple[float, float, float]
|
||||
:param scale: The scale by which the point gets scaled; regular is 1.0
|
||||
:type scale: float
|
||||
:return: The 3D Point on a 2D plane
|
||||
:rtype: tuple[float, float]
|
||||
"""
|
||||
return (point[0] * scale,
|
||||
point[1] * scale)
|
||||
|
||||
def project_perspective(point: tuple[float, float, float], focal_length: float = 1.0,
|
||||
scale: float = 1.0, camera_distance: float = 4.0) -> tuple[float, float]:
|
||||
"""
|
||||
Projects a 3D Position into a perspective 2D View
|
||||
:param point: The 3D Point
|
||||
:type point: tuple[float, float, float]
|
||||
:param focal_length: strength of perspective; regular is 1.0
|
||||
:type focal_length: float
|
||||
:param scale: The scale by which the point gets scaled; regular is 1.0
|
||||
:type scale: float
|
||||
:param camera_distance: How far the Camera is away from the point; regular is 4.0
|
||||
:return: The 3D Point on a 2D plane
|
||||
:rtype: tuple[float, float]
|
||||
"""
|
||||
return (point[0] * focal_length * scale / (point[2] + camera_distance),
|
||||
point[1] * focal_length * scale / (point[2] + camera_distance), )
|
||||
|
||||
|
||||
def print_matrix(matrix:list[list[float]]) -> None:
|
||||
for row in matrix:
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
from src.compute import project_perspective
|
||||
|
||||
def test_pers_1():
|
||||
|
||||
point = (1.0, 2.0, 3.0)
|
||||
exp_point = (1/7, 2/7)
|
||||
|
||||
result = project_perspective(point)
|
||||
|
||||
assert result == exp_point
|
||||
|
||||
|
||||
def test_pers_2():
|
||||
|
||||
point = (1.0, 2.0, 3.0)
|
||||
exp_point = (200/7, 400/7)
|
||||
|
||||
result = project_perspective(point, focal_length=2.0, scale=100)
|
||||
|
||||
assert result == exp_point
|
||||
|
||||
Reference in new issue
Block a user