Repository navigation
calc_line_triangle_intersect
jaybgager edited this page Sep 29, 2026
·
2 revisions
Calculates the intersection point of a line segment and a triangular plane if one exists. Primarily a utility function used by several others.
Arguments:
-
line((2,3)-shape numpy array of floats, mandatory)- the point coords of the line segment's ends
- e.g.
[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
-
triangle((3,3)-shape numpy array of floats, mandatory)- the point coords of the triangle's vertices
- e.g.
[[1.0, 2.0, 3.0], [4.0 ,5.0, 6.0], [7.0, 8.0, 9.0]]
-
precision(integer, optional, default=0)- maximum number of decimal points to include when calculating intersection points
- default of 0 rounds to nearest integer as this is fine for most neuroglancer uses
Returns:
-
result(varies, see description)- returns a (3)-shape numpy array of floats if an intersection is found, otherwise returns
Nonevalue
- returns a (3)-shape numpy array of floats if an intersection is found, otherwise returns
INPUT:
import tracertools as tt
import numpy as np
intersect = tt.calc_line_triangle_intersect(
line = np.array(
[
[0,0,0],
[1,2,3]
]
),
triangle = np.array(
[
[2,0,0],
[0,3,0],
[0,0,4]
]
),
)
print(intersect)
OUTPUT:
[1.,1.,2.]
INPUT:
import tracertools as tt
import numpy as np
intersect = tt.calc_line_triangle_intersect(
line = np.array(
[
[0,0,0],
[1,2,3]
]
),
triangle = np.array(
[
[2,0,0],
[0,3,0],
[0,0,4]
]
),
precision = 3,
)
print(intersect)
OUTPUT:
[0.522 1.043 1.565]
Note
Using high precision (e.g 16+ digits) with small coord values (e.g. [1,1,1]) can result in false negative results, as the float math involved sometimes produces very tiny discrepancies when checking results.