Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:05

0001 import numpy as np
0002 import plotly.graph_objects as go
0003 
0004 
0005 def mesh(tri, vtx, visible=True):
0006     # close triangles and create edge coordinates
0007     tri_close = np.hstack((tri, tri[:,0][:,np.newaxis]))
0008     tri_sides = np.array([[None]*3 if i is None else vtx[i].tolist() for t in tri_close for i in list(t)+[None]], dtype=float)
0009 
0010     faces = go.Mesh3d(x=vtx.T[0], y=vtx.T[1], z=vtx.T[2], i=tri.T[0], j=tri.T[1], k=tri.T[2], color='green', opacity=0.2, showlegend=True, visible=visible)
0011     edges = go.Scatter3d(x=tri_sides.T[0], y=tri_sides.T[1], z=tri_sides.T[2], mode='lines', line_color='red', line_width=5, opacity=0.2, visible='legendonly')
0012 
0013     return faces, edges
0014 
0015 
0016 def rays(rec, single_trace=True):
0017     positions = rec[:, :, 0, :3]
0018     mask = ~np.all(positions == 0, axis=2)
0019     positions = positions[mask]
0020     num_bounces = np.count_nonzero(mask, axis=1)
0021     idx_bounces = np.cumsum(num_bounces[:-1])
0022 
0023     return [go.Scatter3d(x=r.T[0], y=r.T[1], z=r.T[2], mode='lines', line_color='blue', line_width=5, opacity=0.2, showlegend=True) for r in np.split(positions, idx_bounces)]