pysdic.intersect_rays#

intersect_rays(seq_rays)[source]#

Compute the point closest to several rays in the least squares sense (for example to triangulate points seen by several cameras, see pysdic.compute_rays()).

Lets consider \(N\) rays with origins \(\vec{O}_i\) and unit directions \(\vec{d}_i\). The distance between a point \(\vec{X}\) and the ray \(i\) is the norm of the component of \(\vec{X} - \vec{O}_i\) orthogonal to \(\vec{d}_i\), so the searched point is:

\[\vec{X} = \arg\min_{\vec{X}} \sum_{i=1}^{N} \left\| M_i (\vec{X} - \vec{O}_i) \right\|^2 \quad \text{with} \quad M_i = I - \vec{d}_i \vec{d}_i^T\]

Since \(M_i\) is a projection (\(M_i^T M_i = M_i\)), the solution is given by the \(3 \times 3\) linear system:

\[\left( \sum_i M_i \right) \vec{X} = \sum_i M_i \vec{O}_i\]

With two rays, \(\vec{X}\) is the middle of their common perpendicular.

The computation is done independently for each point of the batch: seq_rays[i] contains the ray \(i\) of all the points, with the same batch shape for all the elements of seq_rays.

Note

If the rays of a point are parallel (or contain NaN values), the system is singular and the point is set to NaN.

See also

Parameters:

seq_rays (Sequence[pysdic.Rays]) – At least two pysdic.Rays objects with the same batch shape \((\dots)\).

Returns:

The intersection points in world coordinates with shape \((\dots, 3)\).

Return type:

numpy.ndarray

Examples

Triangulate the points seen by two cameras:

rays_0 = compute_rays(image_points_0, intrinsic_0, distortion_0, extrinsic_0)
rays_1 = compute_rays(image_points_1, intrinsic_1, distortion_1, extrinsic_1)

world_points = intersect_rays([rays_0, rays_1])  # (..., 3)