Ir al contenido principal

raygeo.geo.shape.bezier

Cubic bezier curve queries and conversions.

Provides point evaluation at a parameter t, splitting into two halves, bounding rectangle computation, flattening to line segments (both fixed-step and adaptive subdivision), rectangle clipping, flatness testing, perpendicular distance measurement, and conversion from cubic to quadratic form.

Functions

clip_bezier_with_rect()

clip_bezier_with_rect(
p0: types.Point,
p1: types.Point,
p2: types.Point,
p3: types.Point,
rect: types.Rect,
) -> list[tuple[types.Point, types.Point, types.Point, types.Point]]

Clip a cubic bezier with a rectangle.

ParameterTypeDescription
p0types.PointStart control point (x, y).
p1types.PointFirst control point (x, y).
p2types.PointSecond control point (x, y).
p3types.PointEnd control point (x, y).
recttypes.RectClipping rectangle (x_min, y_min, x_max, y_max).
Returnslist[tuple[types.Point, types.Point, types.Point, types.Point]]List of bezier segments inside the rectangle.
ComplexityO(n)

convert_cubic_bezier_to_quadratic()

convert_cubic_bezier_to_quadratic(
p0: types.Point,
p1: types.Point,
p2: types.Point,
p3: types.Point,
) -> tuple[types.Point, types.Point, types.Point]

Convert a cubic bezier to a quadratic bezier.

ParameterTypeDescription
p0types.PointStart control point (x, y).
p1types.PointFirst control point (x, y).
p2types.PointSecond control point (x, y).
p3types.PointEnd control point (x, y).
Returnstuple[types.Point, types.Point, types.Point]Quadratic bezier (p0, p1, p2).
ComplexityO(1)

fit_cubic_bezier()

fit_cubic_bezier(
points: list[tuple[float, float]],
) -> Optional[types.CubicBezier]

Fit a cubic Bezier curve to a sequence of points (least-squares).

ParameterTypeDescription
pointslist[tuple[float, float]]List of (x, y) points.
ReturnsOptional[types.CubicBezier](p0, c1, c2, p3) or None if fewer than 2 points.

Cubic Bezier curves fitted to sample points — sine, cosine hump, quarter-circle, and shallow wave

Cubic Bezier curves fitted to sample points — sine, cosine hump, quarter-circle, and shallow wave

flatten_bezier()

flatten_bezier(
p0: types.Point3D,
p1: types.Point3D,
p2: types.Point3D,
p3: types.Point3D,
tolerance: float,
max_subdivisions: int,
pts: list,
) -> None

Flatten a bezier curve into points.

ParameterTypeDescription
p0types.Point3DStart control point (x, y, z).
p1types.Point3DFirst control point (x, y, z).
p2types.Point3DSecond control point (x, y, z).
p3types.Point3DEnd control point (x, y, z).
tolerancefloatFlattening tolerance.
max_subdivisionsintMaximum recursion depth.
ptslistOutput list to append points to.
ReturnsNoneList of (x, y) points along the flattened bezier.
ComplexityO(n)

Bezier flattening: adaptive subdivision at varied tolerances

Bezier flattening: adaptive subdivision at varied tolerances

get_bezier_bounds()

get_bezier_bounds(
p0: types.Point,
p1: types.Point,
p2: types.Point,
p3: types.Point,
) -> types.Rect

Get the bounding rectangle of a cubic bezier.

ParameterTypeDescription
p0types.PointStart control point (x, y).
p1types.PointFirst control point (x, y).
p2types.PointSecond control point (x, y).
p3types.PointEnd control point (x, y).
Returnstypes.RectBounding rectangle as (x_min, y_min, x_max, y_max).
ComplexityO(1)

get_bezier_flatness_sq()

get_bezier_flatness_sq(
a: types.Point3D,
b: types.Point3D,
c: types.Point3D,
d: types.Point3D,
) -> float

Compute the flatness squared of a cubic bezier.

ParameterTypeDescription
atypes.Point3DStart point (x, y, z).
btypes.Point3DFirst control point (x, y, z).
ctypes.Point3DSecond control point (x, y, z).
dtypes.Point3DEnd point (x, y, z).
ReturnsfloatFlatness squared value.
ComplexityO(1)

get_bezier_length()

get_bezier_length(
p0: types.Point,
c1: types.Point,
c2: types.Point,
p1: types.Point,
) -> float

Compute the arc length of a cubic Bezier curve.

ParameterTypeDescription
p0types.PointStart point (x, y).
c1types.PointFirst control point (x, y).
c2types.PointSecond control point (x, y).
p1types.PointEnd point (x, y).
ReturnsfloatArc length.
ComplexityO(n)

get_bezier_point_at()

get_bezier_point_at(
p0: types.Point,
p1: types.Point,
p2: types.Point,
p3: types.Point,
t: float,
) -> types.Point

Get a point on a cubic bezier at parameter t.

ParameterTypeDescription
p0types.PointStart control point (x, y).
p1types.PointFirst control point (x, y).
p2types.PointSecond control point (x, y).
p3types.PointEnd control point (x, y).
tfloatParameter value (0..1).
Returnstypes.PointPoint on the bezier curve (x, y).
ComplexityO(1)

Bezier point evaluation at parameter t

Bezier point evaluation at parameter t

get_bezier_rect_intersections()

get_bezier_rect_intersections(
p0: types.Point,
p1: types.Point,
p2: types.Point,
p3: types.Point,
rect: types.Rect,
) -> list[float]

Get intersection t-values of a bezier with a rectangle.

ParameterTypeDescription
p0types.PointStart control point (x, y).
p1types.PointFirst control point (x, y).
p2types.PointSecond control point (x, y).
p3types.PointEnd control point (x, y).
recttypes.RectRectangle (x_min, y_min, x_max, y_max).
Returnslist[float]List of t-values where the bezier intersects.
ComplexityO(n)

get_perpendicular_dist_sq()

get_perpendicular_dist_sq(
pt: types.Point3D,
origin: types.Point3D,
vx: float,
vy: float,
vz: float = 0,
norm_sq: float = 0,
) -> float

Compute the perpendicular distance squared.

ParameterTypeDescription
pttypes.Point3DPoint to measure from.
origintypes.Point3DOrigin of the line.
vxfloatX component of line direction.
vyfloatY component of line direction.
vzfloat = 0Z component of line direction.
norm_sqfloat = 0Precomputed squared norm (optional).
ReturnsfloatPerpendicular distance squared.
ComplexityO(1)

is_bezier_flat()

is_bezier_flat(
p0: types.Point,
p1: types.Point,
p2: types.Point,
p3: types.Point,
tolerance_sq: float,
) -> bool

Test whether a cubic bezier curve is flat enough to approximate with a line segment.

Uses a chord-distance flatness test. For non-degenerate curves (p0 != p3) it checks whether both control points lie within tolerance_sq of the chord line. For degenerate curves (p0 approx p3) it checks the control point distances from the start point.

ParameterTypeDescription
p0types.PointStart control point (x, y).
p1types.PointFirst control point (x, y).
p2types.PointSecond control point (x, y).
p3types.PointEnd control point (x, y).
tolerance_sqfloatSquared tolerance for flatness.
ReturnsboolTrue if the curve is flat enough.
ComplexityO(1)

is_bezier_inside_polygons()

is_bezier_inside_polygons(
p0: types.Point,
p1: types.Point,
p2: types.Point,
p3: types.Point,
polygons: Any,
) -> bool

Check if a bezier curve is inside a set of polygons.

ParameterTypeDescription
p0types.PointStart control point (x, y).
p1types.PointFirst control point (x, y).
p2types.PointSecond control point (x, y).
p3types.PointEnd control point (x, y).
polygonsAnyList of polygons to check against.
ReturnsboolTrue if the bezier is inside all polygons.
ComplexityO(n * m)

linearize_bezier()

linearize_bezier(
p0: types.Point3D,
p1: types.Point3D,
p2: types.Point3D,
p3: types.Point3D,
num_steps: int,
) -> list[tuple[types.Point3D, types.Point3D]]

Linearize a bezier into line segments.

ParameterTypeDescription
p0types.Point3DStart control point (x, y, z).
p1types.Point3DFirst control point (x, y, z).
p2types.Point3DSecond control point (x, y, z).
p3types.Point3DEnd control point (x, y, z).
num_stepsintNumber of linearization steps.
Returnslist[tuple[types.Point3D, types.Point3D]]List of (p1, p2) segment pairs.
ComplexityO(n)

linearize_bezier_adaptive()

linearize_bezier_adaptive(
p0: types.Point,
p1: types.Point,
p2: types.Point,
p3: types.Point,
tolerance_sq: float,
max_subdivisions: int = 20,
) -> types.Polygon

Adaptively linearize a bezier curve.

ParameterTypeDescription
p0types.PointStart control point (x, y).
p1types.PointFirst control point (x, y).
p2types.PointSecond control point (x, y).
p3types.PointEnd control point (x, y).
tolerance_sqfloatSquared tolerance for subdivision.
max_subdivisionsint = 20Maximum recursion depth.
Returnstypes.PolygonList of linearized points (x, y).
ComplexityO(n)

linearize_bezier_segment()

linearize_bezier_segment(
p0: types.Point3D,
p1: types.Point3D,
p2: types.Point3D,
p3: types.Point3D,
tolerance: float = 0.1,
) -> list[types.Point3D]

Linearize a single bezier segment.

ParameterTypeDescription
p0types.Point3DStart control point (x, y, z).
p1types.Point3DFirst control point (x, y, z).
p2types.Point3DSecond control point (x, y, z).
p3types.Point3DEnd control point (x, y, z).
tolerancefloat = 0.1Linearization tolerance.
Returnslist[types.Point3D]List of linearized points (x, y, z).
ComplexityO(n)

nearest_tangent_circle_on_bezier()

nearest_tangent_circle_on_bezier(
point: types.Point,
bezier: types.CubicBezier,
radius: float,
) -> Optional[tuple[types.Point, types.Point, float]]

Circle through point tangent to a cubic Bezier.

ParameterTypeDescription
pointtypes.PointPoint the circle must pass through.
beziertypes.CubicBezier(p0, c1, c2, p3) control points.
radiusfloatCircle radius.
ReturnsOptional[tuple[types.Point, types.Point, float]](centre, tangent_point, t) or None.

split_bezier()

split_bezier(
p0: types.Point,
p1: types.Point,
p2: types.Point,
p3: types.Point,
t: float,
) -> tuple[tuple[types.Point, types.Point, types.Point, types.Point], tuple[types.Point, types.Point, types.Point, types.Point]]

Split a cubic bezier at parameter t.

ParameterTypeDescription
p0types.PointStart control point (x, y).
p1types.PointFirst control point (x, y).
p2types.PointSecond control point (x, y).
p3types.PointEnd control point (x, y).
tfloatSplit parameter (0..1).
Returnstuple[tuple[types.Point, types.Point, types.Point, types.Point], tuple[types.Point, types.Point, types.Point, types.Point]]Two bezier curves (left, right).
ComplexityO(1)

Bezier split at parameter t

Bezier split at parameter t