Skip to main content

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.

Returns: List of bezier segments inside the 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]]

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.

Returns: Quadratic bezier (p0, p1, p2).

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]

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.
ReturnsNone

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.

Returns: Bounding rectangle as (x_min, y_min, x_max, y_max).

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.Rect

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.

Returns: Flatness squared value.

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).
Returnsfloat

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.

Returns: Arc length.

ParameterTypeDescription
p0types.PointStart point (x, y).
c1types.PointFirst control point (x, y).
c2types.PointSecond control point (x, y).
p1types.PointEnd point (x, y).
Returnsfloat

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.

Returns: Point on the bezier curve (x, y).

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.Point

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.

Returns: List of t-values where the bezier intersects.

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]

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.

Returns: 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).
Returnsfloat

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.

Returns: True if the bezier is inside all 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.
Returnsbool

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.

Returns: List of (p1, p2) segment pairs.

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]]

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.

Returns: List of linearized points (x, y).

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.Polygon

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.

Returns: List of linearized points (x, y, z).

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]

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.

Returns: Two bezier curves (left, right).

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]]