MCPcopy Create free account
hub / github.com/NanoComp/meep / intersect_volume_volume

Function intersect_volume_volume

python/visualization.py:183–237  ·  view source on GitHub ↗
(volume1: Volume, volume2: Volume)

Source from the content-addressed store, hash-verified

181# Volumes must be a line, plane, or rectangular prism
182# (since they are volume objects)
183def intersect_volume_volume(volume1: Volume, volume2: Volume) -> List[Vector3]:
184 # volume1 ............... [volume]
185 # volume2 ............... [volume]
186
187 # Represent the volumes by an "upper" and "lower" coordinate
188 U1 = [
189 volume1.center.x + volume1.size.x / 2,
190 volume1.center.y + volume1.size.y / 2,
191 volume1.center.z + volume1.size.z / 2,
192 ]
193 L1 = [
194 volume1.center.x - volume1.size.x / 2,
195 volume1.center.y - volume1.size.y / 2,
196 volume1.center.z - volume1.size.z / 2,
197 ]
198
199 U2 = [
200 volume2.center.x + volume2.size.x / 2,
201 volume2.center.y + volume2.size.y / 2,
202 volume2.center.z + volume2.size.z / 2,
203 ]
204 L2 = [
205 volume2.center.x - volume2.size.x / 2,
206 volume2.center.y - volume2.size.y / 2,
207 volume2.center.z - volume2.size.z / 2,
208 ]
209
210 # Evaluate intersection
211 U = np.min([U1, U2], axis=0)
212 L = np.max([L1, L2], axis=0)
213
214 # For single points we have to check manually
215 if np.all(U - L == 0):
216 if (not volume1.pt_in_volume(Vector3(*U))) or (
217 not volume2.pt_in_volume(Vector3(*U))
218 ):
219 return []
220
221 # Check for two volumes that don't intersect
222 if np.any(U - L < 0):
223 return []
224
225 # Pull all possible vertices
226 vertices = []
227 for x_vals in [L[0], U[0]]:
228 for y_vals in [L[1], U[1]]:
229 for z_vals in [L[2], U[2]]:
230 vertices.append(Vector3(x_vals, y_vals, z_vals))
231
232 # Remove any duplicate points caused by coplanar lines
233 vertices = [
234 vertices[i] for i, x in enumerate(vertices) if x not in vertices[i + 1 :]
235 ]
236
237 return vertices
238
239
240# All of the 2D plotting routines need an output plane over which to plot.

Callers 2

get_2D_dimensionsFunction · 0.85
plot_volumeFunction · 0.85

Calls 2

Vector3Class · 0.90
pt_in_volumeMethod · 0.80

Tested by

no test coverage detected