project_perspective + tests laufen

This commit is contained in:
kreischeran103444 committed 2026-11-05 00:16:10 +01:00
1 parent ff9289c767
commit 8052919012
7 files changed
+41 -11

No files matched your search

+2 -2
View File
@@ -1,2 +1,2 @@
from .compute import matmul, transpose, rot_2D, rot_3D
from .projection import project_ortho
from .compute import matmul, rot_2D, rot_3D, transpose
from .projection import project_ortho, project_perspective
+1 -2
View File
@@ -1,8 +1,7 @@
from __future__ import annotations
import pygame
from compute import rot_2D, matmul
from compute import matmul, rot_2D
from moon import Moon
# Apollo visual parameters
+1 -1
View File
@@ -1,7 +1,7 @@
from __future__ import annotations
from collections.abc import Sequence
import math
from collections.abc import Sequence
Matrix = Sequence[Sequence[float]]
+1 -2
View File
@@ -13,10 +13,9 @@ from __future__ import annotations
import pygame
from src.matrixmania.compute import rot_2D, matmul
from src.matrixmania.compute import matmul, rot_2D
from src.matrixmania.game import Game
EARTH_RADIUS = 30
MOON_RADIUS = 10
BLACK = (0, 0, 0)
+7 -1
View File
@@ -9,4 +9,10 @@ def project_ortho(point: tuple[float, float, float], scale: float = 1) -> tuple[
Scaling factor applied (default 1)
"""
x, y, _ = point
return (x * scale, y * scale)
return (x * scale, y * 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]:
x, y, z = point
x_2d = x * focal_length / (z + camera_distance) * scale
y_2d = y * focal_length / (z + camera_distance) * scale
return (x_2d, y_2d)
+25 -2
View File
@@ -1,6 +1,7 @@
import pytest
from matrixmania import project_ortho
from matrixmania import project_ortho, project_perspective
def test_project_ortho_ohne_skalierung():
# Arrange
@@ -13,7 +14,6 @@ def test_project_ortho_ohne_skalierung():
# Assert
assert ergebnis == pytest.approx(erwartet)
def test_project_ortho_mit_skalierung_100():
# Arrange
punkt = (1.0, 2.0, 3.0)
@@ -26,3 +26,26 @@ def test_project_ortho_mit_skalierung_100():
# Assert
assert ergebnis == pytest.approx(erwartet) #würde hier auch ohne approx gehen
def test_project_perspective_ohne_skalierung():
# Arrange
punkt = (1.0, 2.0, 3.0)
erwartet = (1 / 7, 2 / 7) # 1*1/7*1 und 2*1/7*1
# Act
ergebnis = project_perspective(punkt, scale=1, focal_length=1)
# Assert
assert ergebnis == pytest.approx(erwartet)
def test_project_perspective_mit_skalierung_und_brennweite():
# Arrange
punkt = (1.0, 2.0, 3.0)
erwartet = (200 / 7, 400 / 7) # 1*2/7*100 und 2*2/7*100
# Act
ergebnis = project_perspective(punkt, scale=100, focal_length=2)
# Assert
assert ergebnis == pytest.approx(erwartet)
+4 -1
View File
@@ -1,7 +1,10 @@
import math, pytest
import math
import pytest
from matrixmania import rot_2D, rot_3D
def test_rot2D(): # gibt Rotationsmatrix für 90 grad
# Arrange
theta = math.pi / 2 # 90 Grad in Radiant