new ways to project

This commit is contained in:
Phexi committed 2026-10-29 12:15:39 +01:00
1 parent 4a838bfdc8
commit 9b09fc2aac
3 files changed
+60 -2

No files matched your search

+10 -2
View File
@@ -140,8 +140,16 @@ def rot_3D(angle:float, axis: str) -> list[list[float]]:
return [row_1, row_2, row_3]
def project_ortho(point: tuple[float, float, float], scale: float = 1) -> tuple[float, float, float]:
return
def project_ortho(point: tuple[float, float, float], scale: float = 1) -> 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]:
x2 = ((point[0] * focal_length) / (point[2] + camera_distance)) * scale
y2 = ((point[1] * focal_length) / (point[2] + camera_distance)) * scale
return x2, y2
def transpose(matrix: list[list[float]]) -> list[list[float]]:
+1
View File
@@ -31,3 +31,4 @@ def test_get_3D_rotation_matrix():
#Assert
assert rot == expected_matrix
+49
View File
@@ -0,0 +1,49 @@
from src.compute import project_ortho, project_perspective
def test_ortho_proj_unscaled():
#Arrange
point = (1.0, 2.0, 3.0)
expected = (1.0, 2.0)
#Act
result = project_ortho(point)
#Assert
assert result == expected
def test_ortho_proj_scaled():
# Arrange
point = (1.0, 2.0, 3.0)
scale = 100.0
expected = (100.0, 200.0)
# Act
result = project_ortho(point, scale)
# Assert
assert result == expected
def test_perspective_proj_unscaled():
# Arrange
point = (1.0, 2.0, 3.0)
expected = (1/7, 2/7)
# Act
result = project_perspective(point)
# Assert
assert result == expected
def test_perspective_proj_scaled():
# Arrange
point = (1.0, 2.0, 3.0)
scale = 100.0
focal_length = 2
expected = (200/7, 400/7)
# Act
result = project_perspective(point, scale, focal_length)
# Assert
assert result == expected