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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
import os
import sys
dir = os.path.split(os.path.realpath(__file__))[0]
sys.path.append(dir + '/..')
import numpy as np
from geometry import Solid
from make import *
from view import *
import matplotlib.pyplot as plt
from materials import *
f = open('hamamatsu_12inch.txt')
points = []
for line in f:
try:
points.append([float(s) for s in line.split(',')])
except ValueError:
pass
points = np.array(points)
# slice profile in half
points = points[points[:,0] < 0]
points[:,0] = -points[:,0]
# order points from base to face
points = points[np.argsort(points[:,1])]
# set x coordinate to 0.0 for first and last points along the profile
# so that the mesh is closed
points[0,0] = 0.0
points[-1,0] = 0.0
# convert mm -> m
points /= 1000.0
def offset(points, x):
points = np.array([points[0] - (points[1] - points[0])] + list(points) + [points[-1] - (points[-2] - points[-1])])
offset_points = []
for i in range(1,len(points)-1):
print '%i' % i
v1 = np.cross(points[i]-points[i-1], (0,0,1))[:2]
v1 /= np.linalg.norm(v1)
v1 *= x
a = points[i-1] + v1
b = points[i] + v1
v2 = np.cross(points[i+1]-points[i], (0,0,1))[:2]
v2 /= np.linalg.norm(v2)
v2 *= x
c = points[i] + v2
d = points[i+1] + v2
m = np.empty((2,2))
m[:,0] = b-a
m[:,1] = c-d
try:
j = np.linalg.solve(m, c-a)[0]
except np.linalg.linalg.LinAlgError as e:
print e
offset_points.append(b)
continue
offset_points.append((a + j*(b-a)))
return np.array(offset_points)
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
offset_points = offset(points, -.003)
plt.plot(points[:,0], points[:,1], 'b-', offset_points[:,0], offset_points[:,1], 'g-')
plt.show()
pmt_outer_mesh = rotate_extrude(points[:,0], points[:,1], np.pi/8)
pmt_inner_mesh = rotate_extrude(offset_points[:,0], offset_points[:,1], np.pi/8)
# cutaway view
pmt_outer_mesh.triangles = pmt_outer_mesh.triangles[np.mean(pmt_outer_mesh[:], axis=1)[:,0] > 0]
#pmt_outer_mesh.triangles = pmt_outer_mesh.triangles[np.mean(pmt_outer_mesh[:], axis=1)[:,1] > -1e-3]
#pmt_inner_mesh.triangles = pmt_inner_mesh.triangles[np.mean(pmt_inner_mesh[:], axis=1)[:,1] > -1e-3]
pmt_outer_solid = Solid(pmt_outer_mesh)
pmt_inner_solid = Solid(pmt_inner_mesh, color=0x00ff00)
def get_lc_profile(radii, a, b, d, rmin, rmax):
c = -b*np.sqrt(1 - (rmin-d)**2/a**2)
return -c - b*np.sqrt(1-(radii-d)**2/a**2)
lc_radii = np.linspace(152.4e-3, 209.672e-3 + 152.4e-3 - 127e-3, 10)
lc_profile = get_lc_profile(lc_radii, 165.97e-3, 584.525e-3, 95.48e-3, 152.4e-3, 209.672e-3 + 152.4e-3 - 127e-3)
face_points = points[points[:,1] > -1e-3]
lc_offset = np.interp(lc_radii[0], list(reversed(face_points[:,0])), list(reversed(face_points[:,1])))
lc_mesh = rotate_extrude(lc_radii, lc_profile + lc_offset, np.pi/8)
lc_solid = Solid(lc_mesh, color=0xff0000, surface=shiny_surface)
pmt_solid_lc = pmt_inner_solid + pmt_outer_solid + lc_solid
view(pmt_solid_lc)
|