-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhexagon_util.py
45 lines (32 loc) · 1.76 KB
/
hexagon_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from math import pi
import numpy as np
from hexagon import IntersectingHexagonAngles, NonIntersectingHexagonAngles, HexagonAngles
def create_phis(min_dist=0.4, max_dist=-1) -> IntersectingHexagonAngles:
variable_phis = np.sort(np.random.uniform(0, 2 * pi, 5))
while np.min(np.abs(np.roll(variable_phis, shift=1) - variable_phis)) < min_dist \
or np.max(np.abs(np.roll(variable_phis, shift=1) - variable_phis)) < max_dist \
or variable_phis[0] < variable_phis[4] - 2 * pi + min_dist:
variable_phis = np.sort(np.random.uniform(0, 2 * pi, 5))
phis = HexagonAngles(variable_phis)
return phis
def create_phis_non_intersecting(min_dist=0.4) -> NonIntersectingHexagonAngles:
phis = np.sort(np.random.uniform(0, 2 * pi, 6))
while np.min(np.abs(np.roll(phis, shift=1) - phis)) < min_dist \
or phis[0] < phis[5] - 2 * pi + min_dist:
phis = np.sort(np.random.uniform(0, 2 * pi, 6))
phis = HexagonAngles(phis)
return phis
def create_phi_transition(phi_old: IntersectingHexagonAngles, phi_new: IntersectingHexagonAngles, step_size=10):
assert phi_old.shape == phi_new.shape
transition = np.empty(shape=(step_size, phi_old.shape[0]))
for t in range(step_size):
step_variable_part = phi_old.variable_angles() * (1 - t / step_size) + phi_new.variable_angles() * t / step_size
step = HexagonAngles(step_variable_part)
transition[t] = step
return transition
def create_radius_transition(start_point, step_size=10, end_point=1):
transition = np.empty(shape=(step_size, start_point.shape[0]))
for t in range(step_size):
step_variable_part = start_point * (1 - t / step_size) + end_point * t / step_size
transition[t] = step_variable_part
return transition