Easy3D 2.6.1
|
Algorithms for evaluating curves. More...
Functions | |
template<template< size_t, class > class Point, size_t N, typename T> | |
void | quadratic (const Point< N, T > &A, const Point< N, T > &B, const Point< N, T > &C, std::vector< Point< N, T > > &curve, unsigned int bezier_steps=4, bool include_end=false) |
Computes a quadratic Bézier curve using De Casteljau’s algorithm. | |
template<template< size_t, class > class Point, size_t N, typename T> | |
void | cubic (const Point< N, T > &A, const Point< N, T > &B, const Point< N, T > &C, const Point< N, T > &D, std::vector< Point< N, T > > &curve, unsigned int bezier_steps=4, bool include_end=false) |
Evaluates a cubic Bézier curve using De Casteljau’s algorithm. | |
Algorithms for evaluating curves.
void cubic | ( | const Point< N, T > & | A, |
const Point< N, T > & | B, | ||
const Point< N, T > & | C, | ||
const Point< N, T > & | D, | ||
std::vector< Point< N, T > > & | curve, | ||
unsigned int | bezier_steps = 4, | ||
bool | include_end = false ) |
Evaluates a cubic Bézier curve using De Casteljau’s algorithm.
Given four control points A
, B
, C
, and D
, this function computes a sequence of points that approximate the cubic Bézier curve defined by these control points. The method works in both 2D and 3D spaces, depending on the template instantiation of Point
.
Point | A templated point class that supports basic arithmetic operations (addition and scalar multiplication). It must be parameterized as Point<N, T> , where N is the number of dimensions, and T is the data type. |
N | The number of dimensions (e.g., 2 for 2D, 3 for 3D). |
T | The scalar type (e.g., float or double ). |
[in] | A | The first control point (curve start). |
[in] | B | The second control point (controls curvature). |
[in] | C | The third control point (controls curvature). |
[in] | D | The fourth control point (curve end). |
[out] | curve | Output vector that will store the computed points along the Bézier curve. |
[in] | bezier_steps | The number of subdivisions used to approximate the curve. A higher value results in a smoother curve but increases computation time. The default value is 4. |
[in] | include_end | If true, the function ensures that the last point in the curve is exactly D . |
The following code demonstrates how to visualize a cubic Bézier curve as a polyline:
void quadratic | ( | const Point< N, T > & | A, |
const Point< N, T > & | B, | ||
const Point< N, T > & | C, | ||
std::vector< Point< N, T > > & | curve, | ||
unsigned int | bezier_steps = 4, | ||
bool | include_end = false ) |
Computes a quadratic Bézier curve using De Casteljau’s algorithm.
This function evaluates a second-degree Bézier curve (also known as a conic curve) given three control points: A
, B
, and C
. The computed curve can be used for smooth interpolation between points in both 2D and 3D spaces, depending on the dimensionality of the Point
type.
Point | A templated point class that supports basic arithmetic operations (addition and scalar multiplication). It must be parameterized as Point<N, T> , where N is the number of dimensions, and T is the data type. |
N | The number of dimensions (e.g., 2 for 2D, 3 for 3D). |
T | The scalar type (e.g., float or double ). |
[in] | A | The first control point (start of the curve). |
[in] | B | The second control point (influences the curvature). |
[in] | C | The third control point (end of the curve). |
[out] | curve | A vector storing the computed points along the curve. |
[in] | bezier_steps | The number of segments used to approximate the curve. A higher value results in a smoother curve at the cost of more points. Suggested default is 4. |
[in] | include_end | If true , the endpoint C is included in the output (i.e., extend the curve to the end point). |
The Bézier curve is computed using De Casteljau’s algorithm, which recursively interpolates between the control points. The interpolation formula is:
\[ P(t) = (1 - t)^2 A + 2(1 - t)t B + t^2 C, \quad t \in [0,1] \]
The function iterates from \( t = 0 \) to \( t = 1 \) in steps of \( 1/\text{bezier_steps} \), generating points along the curve.
The following example computes and visualizes a quadratic Bézier curve: