Refactor all and add some tests for the calculations

This commit is contained in:
2026-01-15 16:12:08 +01:00
parent cc3371b73b
commit 2d067013b4
11 changed files with 161 additions and 102 deletions

55
objects/world.py Normal file
View File

@@ -0,0 +1,55 @@
"""
Alle gemessenen Koordinaten der Quelle und der Sonne haben den Ursprung in der rechten
oberen Ecke des Clusters in einem rechtshaendigen flachen System.
Achsen in der Welt mit der z-Achse nach oben.
Alles in cm gemessen.
Der phi Winkel wird zur x-Achse gemessen.
Der thetha Winkel wird zur z-Achse gemessen.
So sind y und z Koordinaten immer positiv.
x (2,0) (1,0) (0,0)
<-----S----S----S O:z
|
S S S (0,1)
|
v y
"""
from objects.generic import Source, Target
from objects.mirror import Mirror
import numpy as np
import math
class World:
def __init__(self, board, tilt_deg=0.0):
self.board = board
self.grid_size = 10 # In cm
self.tilt_deg = tilt_deg # Tilt of the grid system around y-axis
self.mirrors: list[Mirror] = []
def add_mirror(self, mirror):
self.mirrors.append(mirror)
def update_mirrors_from_source_target(self, source: Source, target: Target):
for mirror in self.mirrors:
mirror.set_angle_from_source_target(source, target)
def rotate_point_y(self, point):
"""Rotate a point around the y-axis by the world's tilt angle."""
x, y, z = point
theta = math.radians(self.tilt_deg)
cos_t = np.cos(theta)
sin_t = np.sin(theta)
x_rot = x * cos_t + z * sin_t
y_rot = y
z_rot = -x * sin_t + z * cos_t
return np.array([x_rot, y_rot, z_rot])