Added uv and also some comments for the angle calculation
This commit is contained in:
@@ -1 +1 @@
|
|||||||
3.13
|
3.12
|
||||||
|
|||||||
6
main.py
Normal file
6
main.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
def main():
|
||||||
|
print("Hello from solarmotor!")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -7,6 +7,7 @@ pkgs.mkShell {
|
|||||||
(pkgs.python313.withPackages (ps: with ps; [
|
(pkgs.python313.withPackages (ps: with ps; [
|
||||||
matplotlib
|
matplotlib
|
||||||
numpy
|
numpy
|
||||||
|
ty
|
||||||
]))
|
]))
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
# Einheitsvektoren
|
||||||
unit_x = np.array([1, 0, 0])
|
unit_x = np.array([1, 0, 0])
|
||||||
unit_y = np.array([0, 1, 0])
|
unit_y = np.array([0, 1, 0])
|
||||||
unit_z = np.array([0, 0, 1])
|
unit_z = np.array([0, 0, 1])
|
||||||
|
|
||||||
# Axis are numbered from 1 to 3 from x to z
|
|
||||||
|
|
||||||
def get_axis(axis):
|
def get_axis(axis):
|
||||||
|
"Axis are numbered from 1 to 3 from x to z."
|
||||||
match axis:
|
match axis:
|
||||||
case 1:
|
case 1:
|
||||||
ax = unit_x
|
ax = unit_x
|
||||||
@@ -18,9 +18,9 @@ def get_axis(axis):
|
|||||||
ax = unit_x
|
ax = unit_x
|
||||||
return ax
|
return ax
|
||||||
|
|
||||||
def proj(vec, axis=1):
|
def proj(vec, axis: int =1):
|
||||||
|
"""Simple vector projection onto an axis."""
|
||||||
ax = get_axis(axis)
|
ax = get_axis(axis)
|
||||||
|
|
||||||
return np.dot(vec, ax) * ax
|
return np.dot(vec, ax) * ax
|
||||||
|
|
||||||
def abs_custom(vec):
|
def abs_custom(vec):
|
||||||
@@ -29,8 +29,8 @@ def abs_custom(vec):
|
|||||||
l += vec[i] ** 2
|
l += vec[i] ** 2
|
||||||
return np.sqrt(l)
|
return np.sqrt(l)
|
||||||
|
|
||||||
|
|
||||||
def rotate(v, angle=90, axis=1):
|
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
|
angle = angle/180 * np.pi
|
||||||
k = get_axis(axis)
|
k = get_axis(axis)
|
||||||
|
|
||||||
@@ -41,6 +41,7 @@ def rotate(v, angle=90, axis=1):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def agl(a, b):
|
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)
|
return np.round(np.acos(np.dot(a, b)/(abs_custom(a) * abs_custom(b)))/(2 * np.pi) * 360)
|
||||||
|
|
||||||
def normalize(vec):
|
def normalize(vec):
|
||||||
@@ -48,6 +49,9 @@ def normalize(vec):
|
|||||||
return vec/l
|
return vec/l
|
||||||
|
|
||||||
def get_angles(source, target):
|
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)
|
source_planar = source - proj(source, 3)
|
||||||
target_planar = target - proj(target, 3)
|
target_planar = target - proj(target, 3)
|
||||||
|
|
||||||
@@ -80,10 +84,20 @@ def get_angles(source, target):
|
|||||||
|
|
||||||
GRID_SIZE = 10
|
GRID_SIZE = 10
|
||||||
|
|
||||||
source_orig = np.array([30, 20, 50])
|
# Aufbau der Koordinaten
|
||||||
target_orig = np.array([30, 20, 20])
|
# 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):
|
for y in range(2):
|
||||||
x_size = x * GRID_SIZE
|
x_size = x * GRID_SIZE
|
||||||
y_size = y * GRID_SIZE
|
y_size = y * GRID_SIZE
|
||||||
|
|||||||
Reference in New Issue
Block a user