line_triangle_intersection#
- regridding.geometry.line_triangle_intersection(line, tuv)[source]#
Compute the 3D point where a line intersects a triangle using the Parametric form described in the Line-plane intersection Wikipedia article.
- Parameters:
- Return type:
See also
line_triangle_intersection_parameters()the function used to compute tuv.
line_intersects_triangle()A function which can be used to check if the intersection exists.
Examples
Compute the intercept between a line and a triangle and plot the result.
import numpy as np import matplotlib.pyplot as plt import regridding # Define a line segment line = ( (1, 1, -1), (-1, -1, 1), ) # Define a triangle triangle = ( (0, 1, 1), (1, -1, -1), (-1, -1, -1), ) # Compute the intercept parameters between the line and triangle tuv = regridding.geometry.line_triangle_intersection_parameters( line=line, triangle=triangle, ) # Compute the actual intercept using the parameters intercept = regridding.geometry.line_triangle_intersection( line=line, tuv=tuv, ) # Plot the result fig, ax = plt.subplots(subplot_kw=dict(projection="3d")) ax.plot( *np.array(line).T ); ax.plot( *np.array(triangle).T.take(np.arange(-1, 3), axis=1) ); ax.scatter( *intercept );