Skip to main content

raygeo.geo.algo.interp

Segment interpolation utilities for parameter-based point projection, clipping, and scanline data slicing along 3D line segments.

Functions

barycentric_interpolate()

barycentric_interpolate(
p: tuple[float, float],
va: tuple[float, float],
vb: tuple[float, float],
vc: tuple[float, float],
ua: float,
ub: float,
uc: float,
) -> float

Interpolate a scalar field at a point inside a triangle.

Given triangle vertices (va, vb, vc) with scalar values (ua, ub, uc), returns the linearly interpolated value at point p using barycentric coordinates.

ParameterTypeDescription
ptuple[float, float]Query point (x, y).
vatuple[float, float]First triangle vertex (x, y).
vbtuple[float, float]Second triangle vertex (x, y).
vctuple[float, float]Third triangle vertex (x, y).
uafloatScalar value at vertex a.
ubfloatScalar value at vertex b.
ucfloatScalar value at vertex c.
ReturnsfloatInterpolated scalar value. Outside the triangle, the barycentric coordinates are clamped to [0, 1].
ComplexityO(1) time, O(1) space

compute_segment_delta_3d()

compute_segment_delta_3d(
start: tuple[float, float, float],
end: tuple[float, float, float],
) -> tuple[float, float, float, float]

Compute delta vector and squared length between two 3D points.

ParameterTypeDescription
starttuple[float, float, float]Starting point (x, y, z).
endtuple[float, float, float]Ending point (x, y, z).
Returnstuple[float, float, float, float](dx, dy, dz, len_sq).
ComplexityO(1) time, O(1) space

compute_t_range()

compute_t_range(
origin: tuple[float, float, float],
new_start: tuple[float, float, float],
new_end: tuple[float, float, float],
delta: tuple[float, float, float, float],
) -> tuple[float, float]

Compute parameter range (t_start, t_end) for a clipped sub-segment.

ParameterTypeDescription
origintuple[float, float, float]Start of original segment (x, y, z).
new_starttuple[float, float, float]Start of clipped sub-segment (x, y, z).
new_endtuple[float, float, float]End of clipped sub-segment (x, y, z).
deltatuple[float, float, float, float]Segment delta from compute_segment_delta_3d.
Returnstuple[float, float](t_start, t_end) in [0, 1].
ComplexityO(1) time, O(1) space

get_barycentric_weights()

get_barycentric_weights(
p: tuple[float, float],
va: tuple[float, float],
vb: tuple[float, float],
vc: tuple[float, float],
) -> tuple[float, float, float]

Compute raw barycentric coordinates for a point in a triangle.

Returns (r, s, t) where r is the weight for va, s for vb, t for vc. Weights are unclamped — the point is strictly inside (or on the boundary of) the triangle iff all three are in [0, 1].

ParameterTypeDescription
ptuple[float, float]Query point (x, y).
vatuple[float, float]First triangle vertex (x, y).
vbtuple[float, float]Second triangle vertex (x, y).
vctuple[float, float]Third triangle vertex (x, y).
Returnstuple[float, float, float]Tuple (r, s, t) of raw barycentric coordinates.
ComplexityO(1) time, O(1) space

project_t_along_segment()

project_t_along_segment(
origin: tuple[float, float, float],
point: tuple[float, float, float],
delta: tuple[float, float, float, float],
) -> float

Project a point onto a line segment, returning t in [0, 1].

ParameterTypeDescription
origintuple[float, float, float]Start of segment (x, y, z).
pointtuple[float, float, float]Point to project (x, y, z).
deltatuple[float, float, float, float]Segment delta from compute_segment_delta_3d.
ReturnsfloatParameter t clamped to [0, 1].
ComplexityO(1) time, O(1) space

slice_scanline_data()

slice_scanline_data(data: list[int], t_start: float, t_end: float) -> list[int]

Slice a scanline power array by parameter range [t_start, t_end).

ParameterTypeDescription
datalist[int]Full scanline power values.
t_startfloatStart parameter in [0, 1].
t_endfloatEnd parameter in [0, 1].
Returnslist[int]Sliced power values.
ComplexityO(n) time, O(n) space where n is the length of the data slice

solve_quadratic()

solve_quadratic(
a: float,
b: float,
c: float,
) -> tuple[float | None, float | None]

Solve quadratic equation a x^2 + b x + c = 0.

ParameterTypeDescription
afloatQuadratic coefficient.
bfloatLinear coefficient.
cfloatConstant term.
Returnstuple[float | None, float | None](root1, root2), each None if no real root.
ComplexityO(1) time, O(1) space