First, get the planes out of your view matrix .
Then use your points to define the vector and min / max as (0, 1), then iterate over the planes and intersect them with the segment, updating min / max, speeding up early if min > max .
Here is an example of a pure Python function, no external fingerprints.
def clip_segment_v3_plane_n(p1, p2, planes): """ - p1, p2: pair of 3d vectors defining a line segment. - planes: a sequence of (4 floats): `(x, y, z, d)`. Returns 2 vector triplets (the clipped segment) or (None, None) then segment is entirely outside. """ dp = sub_v3v3(p2, p1) p1_fac = 0.0 p2_fac = 1.0 for p in planes: div = dot_v3v3(p, dp) if div != 0.0: t = -plane_point_side_v3(p, p1) if div > 0.0:
source share