Bezier
Fast and lightweight class for using the Bezier curves of any order in C++
|
23 #include "declarations.h"
44 Curve(Eigen::MatrixX2d points);
61 unsigned order()
const;
80 std::pair<Point, Point>
endPoints()
const;
100 double length(
double t)
const;
108 double length(
double t1,
double t2)
const;
169 Eigen::MatrixX2d
valueAt(
const std::vector<double>& t_vector)
const;
234 std::vector<double>
roots()
const;
240 std::vector<double>
extrema()
const;
253 std::pair<Curve, Curve>
splitCurve(
double z = 0.5)
const;
300 using Coeffs = Eigen::MatrixXd;
304 using CoeffsMap = std::map<unsigned, Coeffs>;
307 mutable std::unique_ptr<const Curve> cached_derivative_;
308 mutable std::unique_ptr<std::vector<double>> cached_roots_;
309 mutable std::unique_ptr<BoundingBox> cached_bounding_box_;
310 mutable std::unique_ptr<PointVector> cached_polyline_;
311 mutable double cached_polyline_flatness_{};
312 mutable std::unique_ptr<Eigen::VectorXd>
313 cached_projection_polynomial_part_;
314 mutable Eigen::MatrixXd
315 cached_projection_polynomial_derivative_;
316 mutable std::unique_ptr<Eigen::VectorXd> cached_chebyshev_coeffs_;
319 static CoeffsMap bernstein_coeffs_;
320 static CoeffsMap splitting_coeffs_left_;
321 static CoeffsMap splitting_coeffs_right_;
322 static CoeffsMap elevate_order_coeffs_;
323 static CoeffsMap lower_order_coeffs_;
325 static Coeffs bernsteinCoeffs(
unsigned n);
328 static Coeffs splittingCoeffsLeft(
unsigned n,
double z = 0.5);
330 static Coeffs splittingCoeffsRight(
unsigned n,
double z = 0.5);
332 static Coeffs elevateOrderCoeffs(
unsigned n);
334 static Coeffs lowerOrderCoeffs(
unsigned n);
Eigen::AlignedBox2d BoundingBox
Bounding box class.
Definition: declarations.h:74
A Bezier curve class.
Definition: bezier.h:35
std::vector< double > extrema() const
Get all extrema of the curve.
BoundingBox boundingBox() const
Get the bounding box of curve.
std::pair< Curve, Curve > splitCurve(double z=0.5) const
Split the curve into two subcurves.
Eigen::Vector2d Point
Point in xy plane.
Definition: declarations.h:59
void lowerOrder()
Lower the curve order by 1.
std::pair< Point, Point > endPoints() const
Get first and last control points.
void setControlPoint(unsigned idx, const Point &point)
Set the new coordinates to a control point.
Vector normalAt(double t, bool normalize=true) const
Get the normal of the curve for a given t.
Vector tangentAt(double t, bool normalize=true) const
Get the tangent of the curve for a given t.
double iterateByLength(double t, double s) const
Compute parameter t which is S distance from given t.
PointVector intersections(const Curve &curve) const
Get the points of intersection with another curve.
unsigned order() const
Get order of the curve (Nth order curve is described with N+1 points);.
Point valueAt(double t) const
Get the point on curve for a given t.
void reverse()
Reverse order of control points.
void resetCache()
Reset all privately cached data.
PointVector polyline(double flatness=0.5) const
Get a polyline representation of the curve as a vector of points on curve.
std::vector< Point > PointVector
A vector of Points.
Definition: declarations.h:64
const Curve & derivative() const
Get the derivative of a curve.
void applyContinuity(const Curve &source_curve, const std::vector< double > &beta_coeffs)
applyContinuity Apply geometric continuity based on the another curve.
std::vector< double > roots() const
Get roots of the curve on both axes.
void manipulateCurvature(double t, const Point &point)
Manipulate the curve so that it passes through wanted point for given 't'.
Vector derivativeAt(double t) const
Get value of a derivative for a given t.
void elevateOrder()
Raise the curve order by 1.
Eigen::MatrixX2d control_points_
N x 2 matrix where each row corresponds to control Point.
Definition: bezier.h:288
double curvatureDerivativeAt(double t) const
Get curvature derivative of the curve for a given t.
Curve(Eigen::MatrixX2d points)
Create the Bezier curve.
Eigen::Vector2d Vector
A Vector in xy plane.
Definition: declarations.h:69
double distance(const Point &point) const
Get distance of the point to the curve.
PointVector controlPoints() const
Get a vector of control points.
double curvatureAt(double t) const
Get curvature of the curve for a given t.
Point controlPoint(unsigned idx) const
Get the control point at index idx.
double projectPoint(const Point &point) const
Get the parameter t where curve is closest to given point.
double length() const
Compute exact arc length using Chebyshev polynomials.