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
bezier_flatness_sq()
bezier_flatness_sq(a: Point3D, b: Point3D, c: Point3D, d: Point3D) -> float
Compute the flatness squared of a cubic bezier.
Returns: Flatness squared value.
| Parameter | Type | Description |
|---|---|---|
a | Point3D | Start point (x, y, z). |
b | Point3D | First control point (x, y, z). |
c | Point3D | Second control point (x, y, z). |
d | Point3D | End point (x, y, z). |
| Returns | float |
clip_bezier_with_rect()
clip_bezier_with_rect(p0: Point, p1: Point, p2: Point, p3: Point, rect: Rect) -> list[tuple[Point, Point, Point, Point]]
Clip a cubic bezier with a rectangle.
Returns: List of bezier segments inside the rectangle.
| Parameter | Type | Description |
|---|---|---|
p0 | Point | Start control point (x, y). |
p1 | Point | First control point (x, y). |
p2 | Point | Second control point (x, y). |
p3 | Point | End control point (x, y). |
rect | Rect | Clipping rectangle (x_min, y_min, x_max, y_max). |
| Returns | list[tuple[Point, Point, Point, Point]] |
convert_cubic_bezier_to_quadratic()
convert_cubic_bezier_to_quadratic(p0: Point, p1: Point, p2: Point, p3: Point) -> tuple[Point, Point, Point]
Convert a cubic bezier to a quadratic bezier.
Returns: Quadratic bezier (p0, p1, p2).
| Parameter | Type | Description |
|---|---|---|
p0 | Point | Start control point (x, y). |
p1 | Point | First control point (x, y). |
p2 | Point | Second control point (x, y). |
p3 | Point | End control point (x, y). |
| Returns | tuple[Point, Point, Point] |
flatten_bezier()
flatten_bezier(p0: Point3D, p1: Point3D, p2: Point3D, p3: Point3D, tolerance: float, max_subdivisions: int, pts: list) -> None
Flatten a bezier curve into points.
| Parameter | Type | Description |
|---|---|---|
p0 | Point3D | Start control point (x, y, z). |
p1 | Point3D | First control point (x, y, z). |
p2 | Point3D | Second control point (x, y, z). |
p3 | Point3D | End control point (x, y, z). |
tolerance | float | Flattening tolerance. |
max_subdivisions | int | Maximum recursion depth. |
pts | list | Output list to append points to. |
| Returns | None |
get_bezier_bounds()
get_bezier_bounds(p0: Point, p1: Point, p2: Point, p3: Point) -> Rect
Get the bounding rectangle of a cubic bezier.
Returns: Bounding rectangle as (x_min, y_min, x_max, y_max).
| Parameter | Type | Description |
|---|---|---|
p0 | Point | Start control point (x, y). |
p1 | Point | First control point (x, y). |
p2 | Point | Second control point (x, y). |
p3 | Point | End control point (x, y). |
| Returns | Rect |
get_bezier_point_at()
get_bezier_point_at(p0: Point, p1: Point, p2: Point, p3: Point, t: float) -> Point
Get a point on a cubic bezier at parameter t.
Returns: Point on the bezier curve (x, y).
| Parameter | Type | Description |
|---|---|---|
p0 | Point | Start control point (x, y). |
p1 | Point | First control point (x, y). |
p2 | Point | Second control point (x, y). |
p3 | Point | End control point (x, y). |
t | float | Parameter value (0..1). |
| Returns | Point |
get_bezier_rect_intersections()
get_bezier_rect_intersections(p0: Point, p1: Point, p2: Point, p3: Point, rect: Rect) -> list[float]
Get intersection t-values of a bezier with a rectangle.
Returns: List of t-values where the bezier intersects.
| Parameter | Type | Description |
|---|---|---|
p0 | Point | Start control point (x, y). |
p1 | Point | First control point (x, y). |
p2 | Point | Second control point (x, y). |
p3 | Point | End control point (x, y). |
rect | Rect | Rectangle (x_min, y_min, x_max, y_max). |
| Returns | list[float] |
is_bezier_inside_polygons()
is_bezier_inside_polygons(p0: Point, p1: Point, p2: Point, p3: Point, polygons: Any) -> bool
Check if a bezier curve is inside a set of polygons.
Returns: True if the bezier is inside all polygons.
| Parameter | Type | Description |
|---|---|---|
p0 | Point | Start control point (x, y). |
p1 | Point | First control point (x, y). |
p2 | Point | Second control point (x, y). |
p3 | Point | End control point (x, y). |
polygons | Any | List of polygons to check against. |
| Returns | bool |
linearize_bezier()
linearize_bezier(p0: Point3D, p1: Point3D, p2: Point3D, p3: Point3D, num_steps: int) -> list[tuple[Point3D, Point3D]]
Linearize a bezier into line segments.
Returns: List of (p1, p2) segment pairs.
| Parameter | Type | Description |
|---|---|---|
p0 | Point3D | Start control point (x, y, z). |
p1 | Point3D | First control point (x, y, z). |
p2 | Point3D | Second control point (x, y, z). |
p3 | Point3D | End control point (x, y, z). |
num_steps | int | Number of linearization steps. |
| Returns | list[tuple[Point3D, Point3D]] |
linearize_bezier_adaptive()
linearize_bezier_adaptive(p0: Point, p1: Point, p2: Point, p3: Point, tolerance_sq: float, max_subdivisions: int = 20) -> Polygon
Adaptively linearize a bezier curve.
Returns: List of linearized points (x, y).
| Parameter | Type | Description |
|---|---|---|
p0 | Point | Start control point (x, y). |
p1 | Point | First control point (x, y). |
p2 | Point | Second control point (x, y). |
p3 | Point | End control point (x, y). |
tolerance_sq | float | Squared tolerance for subdivision. |
max_subdivisions | int = 20 | Maximum recursion depth. |
| Returns | Polygon |
linearize_bezier_segment()
linearize_bezier_segment(p0: Point3D, p1: Point3D, p2: Point3D, p3: Point3D, tolerance: float = 0.1) -> list[Point3D]
Linearize a single bezier segment.
Returns: List of linearized points (x, y, z).
| Parameter | Type | Description |
|---|---|---|
p0 | Point3D | Start control point (x, y, z). |
p1 | Point3D | First control point (x, y, z). |
p2 | Point3D | Second control point (x, y, z). |
p3 | Point3D | End control point (x, y, z). |
tolerance | float = 0.1 | Linearization tolerance. |
| Returns | list[Point3D] |
perp_dist_sq()
perp_dist_sq(pt: Point3D, origin: Point3D, vx: float, vy: float, vz: float = 0, norm_sq: float = 0) -> float
Compute the perpendicular distance squared.
Returns: Perpendicular distance squared.
| Parameter | Type | Description |
|---|---|---|
pt | Point3D | Point to measure from. |
origin | Point3D | Origin of the line. |
vx | float | X component of line direction. |
vy | float | Y component of line direction. |
vz | float = 0 | Z component of line direction. |
norm_sq | float = 0 | Precomputed squared norm (optional). |
| Returns | float |
split_bezier()
split_bezier(p0: Point, p1: Point, p2: Point, p3: Point, t: float) -> tuple[tuple[Point, Point, Point, Point], tuple[Point, Point, Point, Point]]
Split a cubic bezier at parameter t.
Returns: Two bezier curves (left, right).
| Parameter | Type | Description |
|---|---|---|
p0 | Point | Start control point (x, y). |
p1 | Point | First control point (x, y). |
p2 | Point | Second control point (x, y). |
p3 | Point | End control point (x, y). |
t | float | Split parameter (0..1). |
| Returns | tuple[tuple[Point, Point, Point, Point], tuple[Point, Point, Point, Point]] |