Bezier
Fast and lightweight class for using the Bezier curves of any order in C++
|
#include <bezier.h>
Public Member Functions | |
Curve (Eigen::MatrixX2d points) | |
Create the Bezier curve. More... | |
Curve (const PointVector &points) | |
Create the Bezier curve. More... | |
Curve (const Curve &curve) | |
Curve (Curve &&)=default | |
Curve & | operator= (const Curve &) |
Curve & | operator= (Curve &&)=default |
unsigned | order () const |
Get order of the curve (Nth order curve is described with N+1 points);. More... | |
PointVector | controlPoints () const |
Get a vector of control points. More... | |
Point | controlPoint (unsigned idx) const |
Get the control point at index idx. More... | |
std::pair< Point, Point > | endPoints () const |
Get first and last control points. More... | |
PointVector | polyline (double flatness=0.5) const |
Get a polyline representation of the curve as a vector of points on curve. More... | |
double | length () const |
Compute exact arc length using Chebyshev polynomials. More... | |
double | length (double t) const |
Compute exact arc length using Chebyshev polynomials. More... | |
double | length (double t1, double t2) const |
Compute exact arc length using Chebyshev polynomials. More... | |
double | iterateByLength (double t, double s) const |
Compute parameter t which is S distance from given t. More... | |
void | reverse () |
Reverse order of control points. | |
void | setControlPoint (unsigned idx, const Point &point) |
Set the new coordinates to a control point. More... | |
void | manipulateCurvature (double t, const Point &point) |
Manipulate the curve so that it passes through wanted point for given 't'. More... | |
void | elevateOrder () |
Raise the curve order by 1. More... | |
void | lowerOrder () |
Lower the curve order by 1. More... | |
Point | valueAt (double t) const |
Get the point on curve for a given t. More... | |
Eigen::MatrixX2d | valueAt (const std::vector< double > &t_vector) const |
Get the point vector on curve for given parameters. More... | |
double | curvatureAt (double t) const |
Get curvature of the curve for a given t. More... | |
double | curvatureDerivativeAt (double t) const |
Get curvature derivative of the curve for a given t. More... | |
Vector | tangentAt (double t, bool normalize=true) const |
Get the tangent of the curve for a given t. More... | |
Vector | normalAt (double t, bool normalize=true) const |
Get the normal of the curve for a given t. More... | |
const Curve & | derivative () const |
Get the derivative of a curve. More... | |
const Curve & | derivative (unsigned n) const |
Get the nth derivative of a curve. More... | |
Vector | derivativeAt (double t) const |
Get value of a derivative for a given t. More... | |
Vector | derivativeAt (unsigned n, double t) const |
Get value of an nth derivative for a given t. More... | |
std::vector< double > | roots () const |
Get roots of the curve on both axes. More... | |
std::vector< double > | extrema () const |
Get all extrema of the curve. More... | |
BoundingBox | boundingBox () const |
Get the bounding box of curve. More... | |
std::pair< Curve, Curve > | splitCurve (double z=0.5) const |
Split the curve into two subcurves. More... | |
PointVector | intersections (const Curve &curve) const |
Get the points of intersection with another curve. More... | |
double | projectPoint (const Point &point) const |
Get the parameter t where curve is closest to given point. More... | |
double | distance (const Point &point) const |
Get distance of the point to the curve. More... | |
void | applyContinuity (const Curve &source_curve, const std::vector< double > &beta_coeffs) |
applyContinuity Apply geometric continuity based on the another curve. More... | |
Protected Member Functions | |
void | resetCache () |
Reset all privately cached data. | |
Protected Attributes | |
Eigen::MatrixX2d | control_points_ |
N x 2 matrix where each row corresponds to control Point. More... | |
A Bezier curve class.
A class for storing and using any-order Bezier curve. It uses private and static caching for storing often accessed data. Private caching is used for data concerning individual curve, while static caching is used for common data (coefficient matrices)
Curve | ( | Eigen::MatrixX2d | points | ) |
Create the Bezier curve.
points | Nx2 matrix where each row is one of N control points that define the curve |
Curve | ( | const PointVector & | points | ) |
Create the Bezier curve.
points | A vector of control points that define the curve |
void applyContinuity | ( | const Curve & | source_curve, |
const std::vector< double > & | beta_coeffs | ||
) |
applyContinuity Apply geometric continuity based on the another curve.
locked_curve | Curve on which calculation are based. |
beta_coeffs | Beta-constraints used to calculate continuity. Size defines continuity order. |
BoundingBox boundingBox | ( | ) | const |
Get the bounding box of curve.
Point controlPoint | ( | unsigned | idx | ) | const |
Get the control point at index idx.
idx | Index of chosen control point |
PointVector controlPoints | ( | ) | const |
Get a vector of control points.
double curvatureAt | ( | double | t | ) | const |
Get curvature of the curve for a given t.
t | Curve parameter |
double curvatureDerivativeAt | ( | double | t | ) | const |
Get curvature derivative of the curve for a given t.
t | Curve parameter |
const Curve& derivative | ( | ) | const |
Get the derivative of a curve.
const Curve& derivative | ( | unsigned | n | ) | const |
Get the nth derivative of a curve.
n | Desired number of derivative |
Vector derivativeAt | ( | double | t | ) | const |
Vector derivativeAt | ( | unsigned | n, |
double | t | ||
) | const |
Get value of an nth derivative for a given t.
n | Desired number of derivative |
t | Curve parameter |
double distance | ( | const Point & | point | ) | const |
Get distance of the point to the curve.
point | Point to project on curve |
void elevateOrder | ( | ) |
Get first and last control points.
std::vector<double> extrema | ( | ) | const |
Get all extrema of the curve.
PointVector intersections | ( | const Curve & | curve | ) | const |
Get the points of intersection with another curve.
curve | Curve to intersect with |
double iterateByLength | ( | double | t, |
double | s | ||
) | const |
Compute parameter t which is S distance from given t.
t | Curve parameter |
s | Distance to iterate |
double length | ( | ) | const |
Compute exact arc length using Chebyshev polynomials.
double length | ( | double | t | ) | const |
Compute exact arc length using Chebyshev polynomials.
t | Curve parameter to which length is computed |
double length | ( | double | t1, |
double | t2 | ||
) | const |
void lowerOrder | ( | ) |
Lower the curve order by 1.
If current shape cannot be described by lower order, it will be best aproximation
void manipulateCurvature | ( | double | t, |
const Point & | point | ||
) |
Manipulate the curve so that it passes through wanted point for given 't'.
t | Curve parameter |
point | Point where curve should pass for a given t |
Vector normalAt | ( | double | t, |
bool | normalize = true |
||
) | const |
Get the normal of the curve for a given t.
t | Curve parameter |
normalize | If the resulting normal should be normalized |
unsigned order | ( | ) | const |
Get order of the curve (Nth order curve is described with N+1 points);.
PointVector polyline | ( | double | flatness = 0.5 | ) | const |
Get a polyline representation of the curve as a vector of points on curve.
flatness | Error tolerance of approximation |
double projectPoint | ( | const Point & | point | ) | const |
Get the parameter t where curve is closest to given point.
point | Point to project on curve |
std::vector<double> roots | ( | ) | const |
Get roots of the curve on both axes.
void setControlPoint | ( | unsigned | idx, |
const Point & | point | ||
) |
Set the new coordinates to a control point.
idx | Index of chosen control point |
point | New control point |
Split the curve into two subcurves.
z | double t at which to split the curve |
Vector tangentAt | ( | double | t, |
bool | normalize = true |
||
) | const |
Get the tangent of the curve for a given t.
t | Curve parameter |
normalize | If the resulting tangent should be normalized |
Eigen::MatrixX2d valueAt | ( | const std::vector< double > & | t_vector | ) | const |
Get the point vector on curve for given parameters.
t_vector | Curve parameters |
Point valueAt | ( | double | t | ) | const |
Get the point on curve for a given t.
t | Curve parameter |
|
protected |
N x 2 matrix where each row corresponds to control Point.