-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sphere.py
51 lines (43 loc) · 1.59 KB
/
Sphere.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
46
47
48
49
50
51
#
# Algorithm for cutting the petals for a sphere
#
# Dmitriy Makhnovskiy, September 2024
#
import csv
import numpy as np
pi = np.pi # pi-constant 3.1415....
# Design parameters
R = 1000.0 # dish radius; your units (mm, cm, or m)
N = 10 # number of petals used for the sphere
M = 50 # number of points on the petal template for drawing its profile
# Calculated parameters
theta = 2.0 * pi / N # angular width of the petal
L = pi * R / 2.0 # petal length
l = [0.0] * M # points along the petal
l[M - 1] = L
r = [0.0] * M # array of r corresponding to the array of l
r[M - 1] = R
eff = [0.0] * M # array of the opening angles
eff[M - 1] = 0.0
q = [0.0] * M # meridian displacements with respect to the l-points
q[M - 1] = 0.0
s = [0.0] * M # array of the meridian coordinates
s[M - 1] = L
w = [0.0] * M # array of the widths corresponding to the array of s
w[M - 1] = theta * R / 2.0
for i in range(0, M-1):
length = i * L / (M - 1)
l[i] = length
r[i] = R * np.sin(length / R)
sqroot = np.sqrt(R ** 2 - r[i] ** 2)
eff[i] = theta * sqroot / (2.0 * R)
q[i] = r[i] * (1.0 - np.cos(eff[i]) - eff[i] ** 2 / 2.0) / sqroot + r[i] * theta ** 2 * sqroot / (8.0 * R)
s[i] = l[i] - q[i]
w[i] = r[i] * (np.sin(eff[i]) - eff[i]) / sqroot + r[i] * theta / 2.0
# Saving the profile data to a CSV file
data = np.column_stack((l, r, eff, q, s, w))
header = ['l', 'r', 'eff', 'q', 's', 'w']
with open('Spherical_profile_data.csv', 'w', newline='') as csv_file:
writer = csv.writer(csv_file)
writer.writerow(header)
writer.writerows(data)