Bezier
Fast and lightweight class for using the Bezier curves of any order in C++
polycurve.h
1 /*
2  * Copyright 2019 Mirko Kokot
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef POLYCURVE_H
18 #define POLYCURVE_H
19 
20 #include <deque>
21 
22 #include "Bezier/bezier.h"
23 #include "Bezier/declarations.h"
24 
25 namespace Bezier
26 {
27 
37 class PolyCurve
38 {
39 public:
40  PolyCurve() = default;
41  ~PolyCurve() = default;
42 
47  PolyCurve(std::deque<Curve> curves);
48 
49  PolyCurve(const PolyCurve&) = default;
50  PolyCurve(PolyCurve&&) = default;
51  PolyCurve& operator=(const PolyCurve&) = default;
52  PolyCurve& operator=(PolyCurve&&) = default;
53 
59  void insertAt(unsigned idx, Curve curve);
60 
65  void insertFront(Curve curve);
66 
71  void insertBack(Curve curve);
72 
77  void removeAt(unsigned idx);
78 
82  void removeFirst();
83 
87  void removeBack();
88 
93  unsigned size() const;
94 
100  unsigned curveIdx(double t) const;
101 
103 
108  Curve& curve(unsigned idx);
109  const Curve& curve(unsigned idx) const;
111 
113 
117  std::deque<Curve>& curves();
118  const std::deque<Curve>& curves() const;
120 
126  PointVector polyline(double flatness = 0.5) const;
127 
132  double length() const;
133 
139  double length(double t) const;
140 
147  double length(double t1, double t2) const;
148 
155  double iterateByLength(double t, double s) const;
156 
161  std::pair<Point, Point> endPoints() const;
162 
167  PointVector controlPoints() const;
168 
174  void setControlPoint(unsigned idx, const Point& point);
175 
181  Point valueAt(double t) const;
182 
188  PointVector valueAt(const std::vector<double>& t_vector) const;
189 
195  double curvatureAt(double t) const;
196 
202  double curvatureDerivativeAt(double t) const;
203 
210  Vector tangentAt(double t, bool normalize = true) const;
211 
218  Vector normalAt(double t, bool normalize = true) const;
219 
225  Vector derivativeAt(double t) const;
226 
233  Vector derivativeAt(unsigned n, double t) const;
234 
239  BoundingBox boundingBox() const;
240 
246  template <typename Curve_PolyCurve> PointVector intersections(const Curve_PolyCurve& curve) const;
247 
253  double projectPoint(const Point& point) const;
254 
260  std::vector<double> projectPoint(const PointVector& point_vector) const;
261 
267  double distance(const Point& point) const;
268 
274  std::vector<double> distance(const PointVector& point_vector) const;
275 
276 protected:
278  std::deque<Curve> curves_;
279 };
280 
281 } // namespace Bezier
282 #endif // POLYCURVE_H
Bezier::PolyCurve::distance
double distance(const Point &point) const
Get distance of the point to the polycurve.
Bezier::PolyCurve::valueAt
Point valueAt(double t) const
Get the point on polycurve for a given t.
Bezier::BoundingBox
Eigen::AlignedBox2d BoundingBox
Bounding box class.
Definition: declarations.h:74
Bezier::PolyCurve::removeBack
void removeBack()
Remove a subcurve from the end of the polycurve.
Bezier::Curve
A Bezier curve class.
Definition: bezier.h:35
Bezier::Point
Eigen::Vector2d Point
Point in xy plane.
Definition: declarations.h:59
Bezier::PolyCurve::curves_
std::deque< Curve > curves_
Structure for holding underlying Bezier curves.
Definition: polycurve.h:278
Bezier::PolyCurve::tangentAt
Vector tangentAt(double t, bool normalize=true) const
Get the tangent of the polycurve for a given t.
Bezier::PolyCurve::curvatureAt
double curvatureAt(double t) const
Get curvature of the polycurve for a given t.
Bezier::PolyCurve::insertAt
void insertAt(unsigned idx, Curve curve)
Insert new curve into polycurve.
Bezier::PolyCurve::derivativeAt
Vector derivativeAt(double t) const
Get value of a derivative for a given t.
Bezier::PolyCurve::projectPoint
double projectPoint(const Point &point) const
Get the parameter t where polycurve is closest to given point.
Bezier::PolyCurve::curve
Curve & curve(unsigned idx)
Get pointer of a subcurve.
Bezier::PolyCurve::removeFirst
void removeFirst()
Remove a subcurve from the beginning of the polycurve.
Bezier::PointVector
std::vector< Point > PointVector
A vector of Points.
Definition: declarations.h:64
Bezier::PolyCurve::boundingBox
BoundingBox boundingBox() const
Get the bounding box of the polycurve.
Bezier::PolyCurve::polyline
PointVector polyline(double flatness=0.5) const
Get a polyline representation of the polycurve as a vector of points on curve.
Bezier::PolyCurve::endPoints
std::pair< Point, Point > endPoints() const
Get first and last control points.
Bezier::PolyCurve::curveIdx
unsigned curveIdx(double t) const
Resolve polycurve parameter to subcurve index.
Bezier::PolyCurve::setControlPoint
void setControlPoint(unsigned idx, const Point &point)
Set the new coordinates to a control point.
Bezier::PolyCurve
A Bezier polycurve class.
Definition: polycurve.h:37
Bezier::PolyCurve::length
double length() const
Compute exact arc length using Chebyshev polynomials.
Bezier::PolyCurve::removeAt
void removeAt(unsigned idx)
Remove a subcurve from the polycurve.
Bezier::Vector
Eigen::Vector2d Vector
A Vector in xy plane.
Definition: declarations.h:69
Bezier::PolyCurve::controlPoints
PointVector controlPoints() const
Get the control points of all subcurves.
Bezier
Definition: bezier.h:25
Bezier::PolyCurve::curvatureDerivativeAt
double curvatureDerivativeAt(double t) const
Get curvature derivative of curve for a given t.
Bezier::PolyCurve::insertFront
void insertFront(Curve curve)
Insert new curve at the beginning of the polycurve.
Bezier::PolyCurve::size
unsigned size() const
Get number of subcurves.
Bezier::PolyCurve::insertBack
void insertBack(Curve curve)
Insert new curve at the end of the polycurve.
Bezier::PolyCurve::intersections
PointVector intersections(const Curve_PolyCurve &curve) const
Get the points of intersection with another curve or polycurve.
Bezier::PolyCurve::iterateByLength
double iterateByLength(double t, double s) const
Compute parameter t which is S distance from given t.
Bezier::PolyCurve::normalAt
Vector normalAt(double t, bool normalize=true) const
Get the normal of the polycurve for a given t.
Bezier::PolyCurve::curves
std::deque< Curve > & curves()
Get list of all subcurves.