pysdic.Mesh.cast_rays#

Mesh.cast_rays(rays, *, n_subdivisions=None, max_iteration=20, tolerance=1e-10, retry_neighbors=False)[source]#

Compute the first intersection of rays with a 3D surface mesh (\(K = 2\), \(E = 3\)).

Shortcut for pysdic.fem.cast_rays() with the coordinates, connectivity and element type of the mesh (see this function for the method and the parameters).

The rays are flattened in C order: the ray rays.rays[i, j] of a batch of shape \((H, W)\) gives the point i * W + j. Reshape the outputs with rays.batch_shape. The rays with non-finite components (e.g. invalid pixels) are unlocated.

Important

Requires the optional package open3d (pip install open3d).

Parameters:
  • rays (pysdic.Rays) – The rays, with any batch shape \((\dots)\) (see pysdic.compute_rays()).

  • n_subdivisions (Optional[Integral], optional (default: None)) – The number of segments per edge of the reference element for the first approximation (ignored for triangle_3).

  • max_iteration (Integral, optional (default: 20)) – The maximum number of Newton iterations (ignored for triangle_3).

  • tolerance (Real, optional (default: 1e-10)) – The convergence tolerance on the natural coordinates (ignored for triangle_3).

  • retry_neighbors (bool, optional (default: False)) – If True, the rays rejected by the Newton iterations are searched again in the elements at a distance \(\leq 1\) of their first element (ignored for triangle_3).

Returns:

One point per ray, \(N_p = \prod (\dots)\). The rays without intersection are unlocated (element index -1).

Return type:

pysdic.IntegrationPoints

Examples

1from pysdic import Mesh, Rays
2
3mesh = Mesh([[0, 0, 0], [1, 0, 0], [0, 1, 0]], [[0, 1, 2]], element_type="triangle_3")
4rays = Rays([[0.2, 0.3, 1.0, 0.0, 0.0, -1.0]])
5
6integration_points = mesh.cast_rays(rays)
7print(integration_points.natural_coordinates, integration_points.element_indices)  # [[0.2 0.3]] [0]