Added uv and also some comments for the angle calculation

This commit is contained in:
Jonas Hahn
2025-12-20 10:29:23 +01:00
parent 209dca235f
commit 460b874651
4 changed files with 30 additions and 9 deletions

View File

@@ -1 +1 @@
3.13
3.12

6
main.py Normal file
View File

@@ -0,0 +1,6 @@
def main():
print("Hello from solarmotor!")
if __name__ == "__main__":
main()

View File

@@ -7,6 +7,7 @@ pkgs.mkShell {
(pkgs.python313.withPackages (ps: with ps; [
matplotlib
numpy
ty
]))
];
}

View File

@@ -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