From 460b8746512bf2bedef9ec30495558c5094ab324 Mon Sep 17 00:00:00 2001 From: Jonas Hahn Date: Sat, 20 Dec 2025 10:29:23 +0100 Subject: [PATCH] Added uv and also some comments for the angle calculation --- .python-version | 2 +- main.py | 6 ++++++ shell.nix | 1 + simple-angle.py | 30 ++++++++++++++++++++++-------- 4 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 main.py diff --git a/.python-version b/.python-version index 24ee5b1..e4fba21 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.13 +3.12 diff --git a/main.py b/main.py new file mode 100644 index 0000000..1e3c83d --- /dev/null +++ b/main.py @@ -0,0 +1,6 @@ +def main(): + print("Hello from solarmotor!") + + +if __name__ == "__main__": + main() diff --git a/shell.nix b/shell.nix index 65c0ab9..835e429 100644 --- a/shell.nix +++ b/shell.nix @@ -7,6 +7,7 @@ pkgs.mkShell { (pkgs.python313.withPackages (ps: with ps; [ matplotlib numpy + ty ])) ]; } diff --git a/simple-angle.py b/simple-angle.py index 9540223..c46a11f 100644 --- a/simple-angle.py +++ b/simple-angle.py @@ -1,12 +1,12 @@ import numpy as np +# Einheitsvektoren unit_x = np.array([1, 0, 0]) unit_y = np.array([0, 1, 0]) unit_z = np.array([0, 0, 1]) -# Axis are numbered from 1 to 3 from x to z - def get_axis(axis): + "Axis are numbered from 1 to 3 from x to z." match axis: case 1: ax = unit_x @@ -18,9 +18,9 @@ def get_axis(axis): ax = unit_x return ax -def proj(vec, axis=1): +def proj(vec, axis: int =1): + """Simple vector projection onto an axis.""" ax = get_axis(axis) - return np.dot(vec, ax) * ax def abs_custom(vec): @@ -29,8 +29,8 @@ def abs_custom(vec): l += vec[i] ** 2 return np.sqrt(l) - def rotate(v, angle=90, axis=1): + "Rotate a vector with an angle around a axis with the right hand rule." angle = angle/180 * np.pi k = get_axis(axis) @@ -41,6 +41,7 @@ def rotate(v, angle=90, axis=1): ) def agl(a, b): + "Get the angle between two vectors. This is always between 0 and 180 degree." return np.round(np.acos(np.dot(a, b)/(abs_custom(a) * abs_custom(b)))/(2 * np.pi) * 360) def normalize(vec): @@ -48,6 +49,9 @@ def normalize(vec): return vec/l def get_angles(source, target): + """Main function to get the phi and theta angles for a source and a target vector. Both vectors must lie on the front half sphere. + Phi is from 0 to 180 where 0 means left when you look at the mirrors. The hardware is bounded between 45 and 135 degree. Thus the here provided angle needs to be subtracted by 45 and then doubled. + Theta is from 0 to 90 where 0 means up.""" source_planar = source - proj(source, 3) target_planar = target - proj(target, 3) @@ -80,10 +84,20 @@ def get_angles(source, target): GRID_SIZE = 10 -source_orig = np.array([30, 20, 50]) -target_orig = np.array([30, 20, 20]) +# Aufbau der Koordinaten +# Das Zentrum des Spiegels hinten rechts bildet den Ursprung +# Dann geht die x-Achse nach links und die y-Achse nach vorne -for x in range(2): +# X, Y, Z +source_orig = np.array([0, 20, 0]) +target_orig = np.array([0, 20, 0]) + +# Strategie des Programms +# 1. Iteration ueber jeden Spiegel +# 2. Berechnung des Quellvektors und des Targetvektors fuer die Position des Spiegels +# 3. Berechne + +for x in range(4): for y in range(2): x_size = x * GRID_SIZE y_size = y * GRID_SIZE