Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::BezierCurve Class Reference

Quadratic and cubic Bézier curves with exact rational arithmetic. More...

#include <geom_algorithms.H>

Classes

struct  SplitResult
 De Casteljau subdivision: split a cubic Bézier at parameter t into two cubic Béziers (left and right). More...
 

Static Public Member Functions

static Point quadratic (const Point &p0, const Point &p1, const Point &p2, const Geom_Number &t)
 Evaluate a quadratic Bézier at parameter t.
 
static Point cubic (const Point &p0, const Point &p1, const Point &p2, const Point &p3, const Geom_Number &t)
 Evaluate a cubic Bézier at parameter t.
 
static Array< Pointsample_quadratic (const Point &p0, const Point &p1, const Point &p2, const size_t n)
 Sample a quadratic Bézier into n+1 points (t = 0, 1/n, ..., 1).
 
static Array< Pointsample_cubic (const Point &p0, const Point &p1, const Point &p2, const Point &p3, const size_t n)
 Sample a cubic Bézier into n+1 points.
 
static SplitResult split_cubic (const Point &p0, const Point &p1, const Point &p2, const Point &p3, const Geom_Number &t)
 
static Rectangle control_bbox (const Point &p0, const Point &p1, const Point &p2, const Point &p3)
 Compute the bounding box of a cubic Bézier's control polygon.
 
static Polygon approximate_quadratic (const Point &p0, const Point &p1, const Point &p2, const size_t n)
 Approximate a quadratic Bézier as a polyline (polygon without closing).
 
static Polygon approximate_cubic (const Point &p0, const Point &p1, const Point &p2, const Point &p3, const size_t n)
 Approximate a cubic Bézier as a polyline.
 

Detailed Description

Quadratic and cubic Bézier curves with exact rational arithmetic.

A Bézier curve is a parametric curve defined by control points.

  • Quadratic (3 control points): B(t) = (1-t)²P₀ + 2t(1-t)P₁ + t²P₂
  • Cubic (4 control points): B(t) = (1-t)³P₀ + 3t(1-t)²P₁ + 3t²(1-t)P₂ + t³P₃

Since the parameter t ∈ [0,1] is rational, evaluation is exact.

Example
Point p = BezierCurve::cubic(Point(0,0), Point(1,2), Point(2,2), Point(3,0),
auto poly = BezierCurve::approximate_cubic(Point(0,0), Point(1,2), Point(2,2), Point(3,0), 32);
static Polygon approximate_cubic(const Point &p0, const Point &p1, const Point &p2, const Point &p3, const size_t n)
Approximate a cubic Bézier as a polyline.
static Point cubic(const Point &p0, const Point &p1, const Point &p2, const Point &p3, const Geom_Number &t)
Evaluate a cubic Bézier at parameter t.
Represents a point with rectangular coordinates in a 2D plane.
Definition point.H:229
mpq_class Geom_Number
Numeric type used by the geometry module.
Definition point.H:115

Definition at line 11133 of file geom_algorithms.H.

Member Function Documentation

◆ approximate_cubic()

static Polygon Aleph::BezierCurve::approximate_cubic ( const Point p0,
const Point p1,
const Point p2,
const Point p3,
const size_t  n 
)
inlinestatic

Approximate a cubic Bézier as a polyline.

Definition at line 11275 of file geom_algorithms.H.

References Aleph::Polygon::add_vertex(), Aleph::divide_and_conquer_partition_dp(), and sample_cubic().

◆ approximate_quadratic()

static Polygon Aleph::BezierCurve::approximate_quadratic ( const Point p0,
const Point p1,
const Point p2,
const size_t  n 
)
inlinestatic

Approximate a quadratic Bézier as a polyline (polygon without closing).

Definition at line 11263 of file geom_algorithms.H.

References Aleph::Polygon::add_vertex(), Aleph::divide_and_conquer_partition_dp(), and sample_quadratic().

◆ control_bbox()

static Rectangle Aleph::BezierCurve::control_bbox ( const Point p0,
const Point p1,
const Point p2,
const Point p3 
)
inlinestatic

Compute the bounding box of a cubic Bézier's control polygon.

Definition at line 11243 of file geom_algorithms.H.

References Aleph::divide_and_conquer_partition_dp(), Aleph::Point::get_x(), and Aleph::Point::get_y().

Referenced by TEST_F().

◆ cubic()

static Point Aleph::BezierCurve::cubic ( const Point p0,
const Point p1,
const Point p2,
const Point p3,
const Geom_Number t 
)
inlinestatic

Evaluate a cubic Bézier at parameter t.

Definition at line 11154 of file geom_algorithms.H.

References Aleph::divide_and_conquer_partition_dp(), Aleph::Point::get_x(), and Aleph::Point::get_y().

Referenced by sample_cubic(), TEST_F(), TEST_F(), and TEST_F().

◆ quadratic()

static Point Aleph::BezierCurve::quadratic ( const Point p0,
const Point p1,
const Point p2,
const Geom_Number t 
)
inlinestatic

Evaluate a quadratic Bézier at parameter t.

Definition at line 11138 of file geom_algorithms.H.

References Aleph::divide_and_conquer_partition_dp(), Aleph::Point::get_x(), and Aleph::Point::get_y().

Referenced by sample_quadratic(), TEST_F(), and TEST_F().

◆ sample_cubic()

static Array< Point > Aleph::BezierCurve::sample_cubic ( const Point p0,
const Point p1,
const Point p2,
const Point p3,
const size_t  n 
)
inlinestatic

Sample a cubic Bézier into n+1 points.

Definition at line 11188 of file geom_algorithms.H.

References ah_domain_error_if, cubic(), Aleph::divide_and_conquer_partition_dp(), and Aleph::Array< T >::reserve().

Referenced by approximate_cubic(), and TEST_F().

◆ sample_quadratic()

static Array< Point > Aleph::BezierCurve::sample_quadratic ( const Point p0,
const Point p1,
const Point p2,
const size_t  n 
)
inlinestatic

Sample a quadratic Bézier into n+1 points (t = 0, 1/n, ..., 1).

Definition at line 11176 of file geom_algorithms.H.

References ah_domain_error_if, Aleph::divide_and_conquer_partition_dp(), quadratic(), and Aleph::Array< T >::reserve().

Referenced by approximate_quadratic(), and TEST_F().

◆ split_cubic()

static SplitResult Aleph::BezierCurve::split_cubic ( const Point p0,
const Point p1,
const Point p2,
const Point p3,
const Geom_Number t 
)
inlinestatic

The documentation for this class was generated from the following file: