Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Geom::BezierCurve Class Reference

Two-dimensional Bezier curve of arbitrary order. More...

#include <bezier-curve.h>

Inheritance diagram for Geom::BezierCurve:
Geom::Curve Geom::BezierCurveN< 1 > Geom::BezierCurveN< degree > Geom::BezierCurveN< 0 > Geom::Path::ClosingSegment Geom::Path::StitchSegment

Public Member Functions

 BezierCurve (D2< Bezier > const &b)
 
Point initialPoint () const override
 Retrieve the start of the curve.
 
Point finalPoint () const override
 Retrieve the end of the curve.
 
bool isDegenerate () const override
 Check whether the curve has exactly zero length.
 
bool isLineSegment () const override
 Return false if there are at least 3 distinct control points, true otherwise.
 
void setInitial (Point const &v) override
 Change the starting point of the curve.
 
void setFinal (Point const &v) override
 Change the ending point of the curve.
 
Rect boundsFast () const override
 Quickly compute the curve's approximate bounding box.
 
Rect boundsExact () const override
 Compute the curve's exact bounding box.
 
void expandToTransformed (Rect &bbox, Affine const &transform) const override
 Expand the given rectangle to include the transformed curve, assuming it already contains its initial point.
 
OptRect boundsLocal (OptInterval const &i, unsigned deg) const override
 
Curveduplicate () const override
 Create an exact copy of this curve.
 
Curveportion (Coord f, Coord t) const override
 Create a curve that corresponds to a part of this curve.
 
Curvereverse () const override
 Create a reversed version of this curve.
 
void operator*= (Translate const &tr) override
 
void operator*= (Scale const &s) override
 
void operator*= (Affine const &m) override
 
Curvederivative () const override
 Create a derivative of this curve.
 
int degreesOfFreedom () const override
 Return the number of independent parameters required to represent all variations of this curve.
 
std::vector< Coordroots (Coord v, Dim2 d) const override
 Computes time values at which the curve intersects an axis-aligned line.
 
Coord nearestTime (Point const &p, Coord from=0, Coord to=1) const override
 Compute a time value at which the curve comes closest to a specified point.
 
Coord length (Coord tolerance) const override
 Compute the arc length of this curve.
 
std::vector< CurveIntersectionintersect (Curve const &other, Coord eps=EPSILON) const override
 Compute intersections with another curve.
 
Point pointAt (Coord t) const override
 Evaluate the curve at a specified time value.
 
std::vector< PointpointAndDerivatives (Coord t, unsigned n) const override
 Evaluate the curve and its derivatives.
 
Coord valueAt (Coord t, Dim2 d) const override
 Evaluate one of the coordinates at the specified time value.
 
D2< SBasistoSBasis () const override
 Convert the curve to a symmetric power basis polynomial.
 
bool isNear (Curve const &c, Coord precision) const override
 Test whether two curves are approximately the same.
 
void feed (PathSink &sink, bool) const override
 Feed the curve to a PathSink.
 
std::vector< CoordtimesWithRadiusOfCurvature (double radius) const
 Computes the times where the radius of curvature of the bezier curve equals the given radius.
 
virtual void operator*= (Translate const &tr)
 
virtual void operator*= (Scale const &s)
 
virtual void operator*= (Rotate const &r)
 
virtual void operator*= (HShear const &hs)
 
virtual void operator*= (VShear const &vs)
 
virtual void operator*= (Zoom const &z)
 
virtual void operator*= (Affine const &m)=0
 
Access and modify control points
unsigned order () const
 Get the order of the Bezier curve.
 
unsigned size () const
 Get the number of control points.
 
Point controlPoint (unsigned ix) const
 Access control points of the curve.
 
Point operator[] (unsigned ix) const
 
std::vector< PointcontrolPoints () const
 Get the control points.
 
D2< Bezier > const & fragment () const
 
void setPoint (unsigned ix, Point const &v)
 Modify a control point.
 
virtual void setPoints (std::vector< Point > const &ps)
 Set new control points.
 
- Public Member Functions inherited from Geom::Curve
virtual ~Curve ()
 
virtual Interval timeRange () const
 Get the interval of allowed time values.
 
virtual Point operator() (Coord t) const
 Evaluate the function at the specified time value.
 
OptRect boundsLocal (OptInterval const &a) const
 Compute the bounding box of a part of the curve.
 
void transform (Affine const &m)
 Transform this curve by an affine transformation.
 
virtual Curvetransformed (Affine const &m) const
 Create a curve transformed by an affine transformation.
 
Curveportion (Interval const &i) const
 A version of that accepts an Interval.
 
Coord nearestTime (Point const &p, Interval const &i) const
 A version that takes an Interval.
 
virtual std::vector< CoordallNearestTimes (Point const &p, Coord from=0, Coord to=1) const
 Compute time values at which the curve comes closest to a specified point.
 
std::vector< CoordallNearestTimes (Point const &p, Interval const &i)
 A version that takes an Interval.
 
virtual int winding (Point const &p) const
 Compute the partial winding number of this curve.
 
virtual std::vector< CurveIntersectionintersectSelf (Coord eps=EPSILON) const
 Compute intersections of this curve with itself.
 
virtual Point unitTangentAt (Coord t, unsigned n=3) const
 Compute a vector tangent to the curve.
 
bool operator== (Curve const &c) const
 Test equality of two curves.
 

Static Public Member Functions

Construct a Bezier curve with runtime-determined order.
static BezierCurvecreate (std::vector< Point > const &pts)
 Construct a curve from a vector of control points.
 

Protected Member Functions

 BezierCurve ()
 
 BezierCurve (Bezier const &x, Bezier const &y)
 
 BezierCurve (std::vector< Point > const &pts)
 
bool _equalTo (Curve const &c) const override
 

Protected Attributes

D2< Bezierinner
 

Related Symbols

(Note that these are not member symbols.)

Coord bezier_length (std::vector< Point > const &points, Coord tolerance)
 Compute the length of a bezier curve given by a vector of its control points.
 

Detailed Description

Two-dimensional Bezier curve of arbitrary order.

Bezier curves are an expansion of the concept of linear interpolation to n points. Linear segments in 2Geom are in fact Bezier curves of order 1.

Let \(\mathbf{B}_{\mathbf{p}_0\mathbf{p}_1\ldots\mathbf{p}_n}\) denote a Bezier curve of order \(n\) defined by the points \(\mathbf{p}_0, \mathbf{p}_1, \ldots, \mathbf{p}_n\). Bezier curve of order 1 is a linear interpolation curve between two points, defined as

\[ \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1}(t) = (1-t)\mathbf{p}_0 + t\mathbf{p}_1 \]

If we now substitute points \(\mathbf{p_0}\) and \(\mathbf{p_1}\) in this definition by linear interpolations, we get the definition of a Bezier curve of order 2, also called a quadratic Bezier curve.

\begin{align*} \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1\mathbf{p}_2}(t) &= (1-t) \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1}(t) + t \mathbf{B}_{\mathbf{p}_1\mathbf{p}_2}(t) \\ \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1\mathbf{p}_2}(t) &= (1-t)^2\mathbf{p}_0 + 2(1-t)t\mathbf{p}_1 + t^2\mathbf{p}_2 \end{align*}

By substituting points for quadratic Bezier curves in the original definition, we get a Bezier curve of order 3, called a cubic Bezier curve.

\begin{align*} \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1\mathbf{p}_2\mathbf{p}_3}(t) &= (1-t) \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1\mathbf{p}_2}(t) + t \mathbf{B}_{\mathbf{p}_1\mathbf{p}_2\mathbf{p}_3}(t) \\ \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1\mathbf{p}_2\mathbf{p}_3}(t) &= (1-t)^3\mathbf{p}_0+3(1-t)^2t\mathbf{p}_1+3(1-t)t^2\mathbf{p}_2+t^3\mathbf{p}_3 \end{align*}

In general, a Bezier curve or order \(n\) can be recursively defined as

\[ \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1\ldots\mathbf{p}_n}(t) = (1-t) \mathbf{B}_{\mathbf{p}_0\mathbf{p}_1\ldots\mathbf{p}_{n-1}}(t) + t \mathbf{B}_{\mathbf{p}_1\mathbf{p}_2\ldots\mathbf{p}_n}(t) \]

This substitution can be repeated an arbitrary number of times. To picture this, imagine the evaluation of a point on the curve as follows: first, all control points are joined with straight lines, and a point corresponding to the selected time value is marked on them. Then, the marked points are joined with straight lines and the point corresponding to the time value is marked. This is repeated until only one marked point remains, which is the point at the selected time value.

Evaluation of the Bezier curve

An important property of the Bezier curves is that their parameters (control points) have an intuitive geometric interpretation. Because of this, they are frequently used in vector graphics editors.

Every Bezier curve is contained in its control polygon (the convex polygon composed of its control points). This fact is useful for sweepline algorithms and intersection.

Implementation notes
The order of a Bezier curve is immuable once it has been created. Normally, you should know the order at compile time and use the BezierCurveN template. If you need to determine the order at runtime, use the BezierCurve::create() function. It will create a BezierCurveN for orders 1, 2 and 3 (up to cubic Beziers), so you can later dynamic_cast to those types, and for higher orders it will create an instance of BezierCurve.

Definition at line 47 of file bezier-curve.h.

Constructor & Destructor Documentation

◆ BezierCurve() [1/4]

Geom::BezierCurve::BezierCurve ( )
inlineprotected

Definition at line 50 of file bezier-curve.h.

Referenced by create(), derivative(), duplicate(), portion(), and reverse().

◆ BezierCurve() [2/4]

Geom::BezierCurve::BezierCurve ( Bezier const &  x,
Bezier const &  y 
)
inlineprotected

Definition at line 51 of file bezier-curve.h.

◆ BezierCurve() [3/4]

Geom::BezierCurve::BezierCurve ( std::vector< Point > const &  pts)
protected

Definition at line 111 of file bezier-curve.cpp.

◆ BezierCurve() [4/4]

Geom::BezierCurve::BezierCurve ( D2< Bezier > const &  b)
inlineexplicit

Definition at line 55 of file bezier-curve.h.

Member Function Documentation

◆ _equalTo()

bool Geom::BezierCurve::_equalTo ( Curve const &  c) const
overrideprotectedvirtual

Implements Geom::Curve.

Definition at line 261 of file bezier-curve.cpp.

References c, controlPoint(), and size().

◆ boundsExact()

Rect Geom::BezierCurve::boundsExact ( ) const
inlineoverridevirtual

Compute the curve's exact bounding box.

This method can be dramatically slower than boundsFast() depending on the curve type.

Returns
The smallest possible rectangle containing all of the curve's points.

Implements Geom::Curve.

Definition at line 112 of file bezier-curve.h.

References Geom::bounds_exact(), and inner.

◆ boundsFast()

Rect Geom::BezierCurve::boundsFast ( ) const
inlineoverridevirtual

Quickly compute the curve's approximate bounding box.

The resulting rectangle is guaranteed to contain all points belonging to the curve, but it might not be the smallest such rectangle. This method is usually fast.

Returns
A rectangle that contains all points belonging to the curve.

Implements Geom::Curve.

Definition at line 111 of file bezier-curve.h.

References Geom::bounds_fast(), and inner.

Referenced by boundsLocal(), and Geom::Ellipse::intersect().

◆ boundsLocal()

OptRect Geom::BezierCurve::boundsLocal ( OptInterval const &  i,
unsigned  deg 
) const
inlineoverridevirtual

Implements Geom::Curve.

Definition at line 114 of file bezier-curve.h.

References Geom::bounds_local(), boundsFast(), Geom::derivative(), inner, order(), Geom::X, and Geom::Y.

◆ controlPoint()

Point Geom::BezierCurve::controlPoint ( unsigned  ix) const
inline

Access control points of the curve.

Parameters
ixThe (zero-based) index of the control point. Note that the caller is responsible for checking that this value is <= order().
Returns
The control point. No-reference return, use setPoint() to modify control points.

Definition at line 67 of file bezier-curve.h.

References inner, Geom::X, and Geom::Y.

Referenced by _equalTo(), feed(), feed_curve_to_cairo(), isLineSegment(), and operator*=().

◆ controlPoints()

std::vector< Point > Geom::BezierCurve::controlPoints ( ) const
inline

Get the control points.

Returns
Vector with order() + 1 control points.

Definition at line 71 of file bezier-curve.h.

References Geom::bezier_points(), and inner.

Referenced by length(), and wrap_rq_to_cubic_l().

◆ create()

BezierCurve * Geom::BezierCurve::create ( std::vector< Point > const &  pts)
static

Construct a curve from a vector of control points.

This will construct the appropriate specialization of BezierCurve (i.e. LineSegment, QuadraticBezier or Cubic Bezier) if the number of control points in the passed vector does not exceed 4.

Definition at line 310 of file bezier-curve.cpp.

References BezierCurve().

◆ degreesOfFreedom()

int Geom::BezierCurve::degreesOfFreedom ( ) const
inlineoverridevirtual

Return the number of independent parameters required to represent all variations of this curve.

For example, for Bezier curves it returns the curve's order multiplied by 2.

Reimplemented from Geom::Curve.

Definition at line 155 of file bezier-curve.h.

References order().

◆ derivative()

Curve * Geom::BezierCurve::derivative ( ) const
inlineoverridevirtual

Create a derivative of this curve.

It's best to think of the derivative in physical terms: if the curve describes the position of some object on the plane from time \(t=0\) to \(t=1\) as said in the introduction, then the curve's derivative describes that object's speed at the same times. The second derivative refers to its acceleration, the third to jerk, etc.

Returns
New curve \(\mathbf{D} = \mathbf{C}'\).

Implements Geom::Curve.

Reimplemented in Geom::BezierCurveN< degree >, Geom::BezierCurveN< 1 >, Geom::BezierCurveN< degree >, Geom::BezierCurveN< 1 >, Geom::BezierCurveN< degree >, and Geom::BezierCurveN< 1 >.

Definition at line 152 of file bezier-curve.h.

References BezierCurve(), Geom::derivative(), inner, Geom::X, and Geom::Y.

◆ duplicate()

Curve * Geom::BezierCurve::duplicate ( ) const
inlineoverridevirtual

Create an exact copy of this curve.

Returns
Pointer to a newly allocated curve, identical to the original

Implements Geom::Curve.

Reimplemented in Geom::BezierCurveN< degree >, Geom::BezierCurveN< 1 >, Geom::Path::ClosingSegment, and Geom::Path::StitchSegment.

Definition at line 123 of file bezier-curve.h.

References BezierCurve().

Referenced by portion().

◆ expandToTransformed()

void Geom::BezierCurve::expandToTransformed ( Rect bbox,
Affine const &  transform 
) const
overridevirtual

Expand the given rectangle to include the transformed curve, assuming it already contains its initial point.

Parameters
bbox[in,out]bbox The rectangle to expand; it is assumed to already contain (initialPoint() * transform).
transformThe transform to apply to the curve before taking its bounding box.

Implements Geom::Curve.

Reimplemented in Geom::BezierCurveN< degree >, Geom::BezierCurveN< 1 >, Geom::BezierCurveN< degree >, Geom::BezierCurveN< 1 >, Geom::BezierCurveN< degree >, Geom::BezierCurveN< 1 >, Geom::BezierCurveN< degree >, Geom::BezierCurveN< 1 >, Geom::BezierCurveN< degree >, Geom::BezierCurveN< 1 >, Geom::BezierCurveN< degree >, Geom::BezierCurveN< 1 >, Geom::BezierCurveN< degree >, and Geom::BezierCurveN< 1 >.

Definition at line 148 of file bezier-curve.cpp.

References Geom::bounds_exact(), inner, and Geom::Curve::transform().

Referenced by Geom::BezierCurveN< degree >::expandToTransformed().

◆ feed()

◆ finalPoint()

Point Geom::BezierCurve::finalPoint ( ) const
inlineoverridevirtual

◆ fragment()

D2< Bezier > const & Geom::BezierCurve::fragment ( ) const
inline

Definition at line 72 of file bezier-curve.h.

References inner.

◆ initialPoint()

Point Geom::BezierCurve::initialPoint ( ) const
inlineoverridevirtual

◆ intersect()

◆ isDegenerate()

bool Geom::BezierCurve::isDegenerate ( ) const
overridevirtual

Check whether the curve has exactly zero length.

Returns
True if the curve's initial point is exactly the same as its final point, and it contains no other points (its value set contains only one element).

Implements Geom::Curve.

Reimplemented in Geom::BezierCurveN< degree >, Geom::BezierCurveN< 1 >, Geom::BezierCurveN< degree >, and Geom::BezierCurveN< 1 >.

Definition at line 119 of file bezier-curve.cpp.

References inner, and size().

Referenced by Geom::BezierCurveN< degree >::isDegenerate().

◆ isLineSegment()

bool Geom::BezierCurve::isLineSegment ( ) const
overridevirtual

Return false if there are at least 3 distinct control points, true otherwise.

Reimplemented from Geom::Curve.

Reimplemented in Geom::BezierCurveN< degree >, Geom::BezierCurveN< 1 >, Geom::BezierCurveN< degree >, and Geom::BezierCurveN< 1 >.

Definition at line 131 of file bezier-curve.cpp.

References controlPoint(), end, size(), and start.

Referenced by intersect(), and Geom::BezierCurveN< degree >::isLineSegment().

◆ isNear()

bool Geom::BezierCurve::isNear ( Curve const &  c,
Coord  precision 
) const
overridevirtual

Test whether two curves are approximately the same.

Implements Geom::Curve.

Definition at line 207 of file bezier-curve.cpp.

References Geom::are_near(), c, inner, isNear(), order(), and size().

Referenced by isNear().

◆ length()

Coord Geom::BezierCurve::length ( Coord  tolerance) const
overridevirtual

Compute the arc length of this curve.

For a curve \(\mathbf{C}(t) = (C_x(t), C_y(t))\), arc length is defined for 2D curves as

\[ \ell = \int_{0}^{1} \sqrt { [C_x'(t)]^2 + [C_y'(t)]^2 }\, \text{d}t \]

In other words, we divide the curve into infinitely small linear segments and add together their lengths. Of course we can't subdivide the curve into infinitely many segments on a computer, so this method returns an approximation. Not that there is usually no closed form solution to such integrals, so this method might be slow.

Parameters
toleranceMaximum allowed error
Returns
Total distance the curve's value travels on the plane when going from 0 to 1

Reimplemented from Geom::Curve.

Definition at line 153 of file bezier-curve.cpp.

References bezier_length(), controlPoints(), Geom::distance(), finalPoint(), initialPoint(), and order().

Referenced by Geom::Ellipse::intersect(), and Geom::Path::snapEnds().

◆ nearestTime()

Coord Geom::BezierCurve::nearestTime ( Point const &  p,
Coord  a = 0,
Coord  b = 1 
) const
overridevirtual

Compute a time value at which the curve comes closest to a specified point.

The first value with the smallest distance is returned if there are multiple such points.

Parameters
pQuery point
aMinimum time value to consider
bMaximum time value to consider; \(a < b\)
Returns
\(q \in [a, b]: ||\mathbf{C}(q) - \mathbf{p}|| = \inf(\{r \in \mathbb{R} : ||\mathbf{C}(r) - \mathbf{p}||\})\)

Reimplemented from Geom::Curve.

Reimplemented in Geom::BezierCurveN< degree >, Geom::BezierCurveN< 1 >, Geom::BezierCurveN< degree >, Geom::BezierCurveN< 1 >, Geom::BezierCurveN< degree >, and Geom::BezierCurveN< 1 >.

Definition at line 276 of file bezier-curve.cpp.

References inner, and Geom::nearest_time().

Referenced by Geom::BezierCurveN< degree >::nearestTime().

◆ operator*=() [1/10]

void Geom::BezierCurve::operator*= ( Affine const &  m)
inlineoverridevirtual

Implements Geom::Curve.

Definition at line 146 of file bezier-curve.h.

References controlPoint(), setPoint(), and size().

◆ operator*=() [2/10]

virtual void Geom::Curve::operator*= ( Affine const &  m)
virtual

Implements Geom::Curve.

◆ operator*=() [3/10]

virtual void Geom::Curve::operator*= ( HShear const &  hs)
inlinevirtual

Reimplemented from Geom::Curve.

Definition at line 200 of file curve.h.

◆ operator*=() [4/10]

virtual void Geom::Curve::operator*= ( Rotate const &  r)
inlinevirtual

Reimplemented from Geom::Curve.

Definition at line 199 of file curve.h.

◆ operator*=() [5/10]

virtual void Geom::Curve::operator*= ( Scale const &  s)
inlinevirtual

Reimplemented from Geom::Curve.

Definition at line 198 of file curve.h.

◆ operator*=() [6/10]

void Geom::BezierCurve::operator*= ( Scale const &  s)
inlineoverridevirtual

Reimplemented from Geom::Curve.

Definition at line 140 of file bezier-curve.h.

References inner, size(), Geom::X, and Geom::Y.

◆ operator*=() [7/10]

virtual void Geom::Curve::operator*= ( Translate const &  tr)
inlinevirtual

Reimplemented from Geom::Curve.

Definition at line 197 of file curve.h.

◆ operator*=() [8/10]

void Geom::BezierCurve::operator*= ( Translate const &  tr)
inlineoverridevirtual

Reimplemented from Geom::Curve.

Definition at line 134 of file bezier-curve.h.

References inner, size(), Geom::X, and Geom::Y.

◆ operator*=() [9/10]

virtual void Geom::Curve::operator*= ( VShear const &  vs)
inlinevirtual

Reimplemented from Geom::Curve.

Definition at line 201 of file curve.h.

◆ operator*=() [10/10]

virtual void Geom::Curve::operator*= ( Zoom const &  z)
inlinevirtual

Reimplemented from Geom::Curve.

Definition at line 202 of file curve.h.

◆ operator[]()

Point Geom::BezierCurve::operator[] ( unsigned  ix) const
inline

Definition at line 68 of file bezier-curve.h.

References inner, Geom::X, and Geom::Y.

◆ order()

unsigned Geom::BezierCurve::order ( ) const
inline

Get the order of the Bezier curve.

A Bezier curve has order() + 1 control points.

Definition at line 61 of file bezier-curve.h.

References inner, and Geom::X.

Referenced by Inkscape::UI::PathManipulator::_createControlPointsFromGeometry(), boundsLocal(), degreesOfFreedom(), isNear(), length(), setFinal(), and setPoints().

◆ pointAndDerivatives()

std::vector< Point > Geom::BezierCurve::pointAndDerivatives ( Coord  t,
unsigned  n 
) const
inlineoverridevirtual

Evaluate the curve and its derivatives.

This will return a vector that contains the value of the curve and the specified number of derivatives. However, the returned vector might contain less elements than specified if some derivatives do not exist.

Parameters
tTime value
nThe number of derivatives to compute
Returns
Vector of at most \(n+1\) elements of the form \([\mathbf{C}(t), \mathbf{C}'(t), \mathbf{C}''(t), \ldots]\)

Implements Geom::Curve.

Definition at line 165 of file bezier-curve.h.

References inner.

Referenced by Geom::BezierFitter::NewtonRaphsonRootFind(), and Geom::EllipticalArc::pointAndDerivatives().

◆ pointAt()

◆ portion()

Curve * Geom::BezierCurve::portion ( Coord  a,
Coord  b 
) const
overridevirtual

Create a curve that corresponds to a part of this curve.

For \(a > b\), the returned portion will be reversed with respect to the original. The returned curve will always be of the same type.

Parameters
aBeginning of the interval specifying the portion of the curve
bEnd of the interval
Returns
New curve \(\mathbf{D}\) such that:
  • \(\mathbf{D}(0) = \mathbf{C}(a)\)
  • \(\mathbf{D}(1) = \mathbf{C}(b)\)
  • \(\mathbf{D}[ [0, 1] ] = \mathbf{C}[ [a?b] ]\), where \([a?b] = [\min(a, b), \max(a, b)]\)

Implements Geom::Curve.

Reimplemented in Geom::BezierCurveN< degree >, and Geom::BezierCurveN< 1 >.

Definition at line 250 of file bezier-curve.cpp.

References BezierCurve(), duplicate(), inner, Geom::portion(), and reverse().

◆ reverse()

Curve * Geom::BezierCurve::reverse ( ) const
inlineoverridevirtual

Create a reversed version of this curve.

The result corresponds to portion(1, 0), but this method might be faster.

Returns
Pointer to a new curve \(\mathbf{D}\) such that \(\forall_{x \in [0, 1]} \mathbf{D}(x) = \mathbf{C}(1-x)\)

Reimplemented from Geom::Curve.

Reimplemented in Geom::BezierCurveN< degree >, Geom::BezierCurveN< 1 >, Geom::Path::ClosingSegment, and Geom::Path::StitchSegment.

Definition at line 129 of file bezier-curve.h.

References BezierCurve(), inner, and Geom::reverse().

Referenced by portion().

◆ roots()

std::vector< Coord > Geom::BezierCurve::roots ( Coord  v,
Dim2  d 
) const
inlineoverridevirtual

Computes time values at which the curve intersects an axis-aligned line.

Parameters
vThe coordinate of the line
dWhich axis the coordinate is on. X means a vertical line, Y a horizontal line.

Implements Geom::Curve.

Definition at line 158 of file bezier-curve.h.

References inner.

Referenced by Geom::EllipticalArc::roots().

◆ setFinal()

void Geom::BezierCurve::setFinal ( Point const &  v)
inlineoverridevirtual

Change the ending point of the curve.

After calling this method, it is guaranteed that \(\mathbf{C}(0) = \mathbf{p}\), and the curve is still continuous. The precise new shape of the curve varies with curve type.

Parameters
pNew ending point of the curve

Implements Geom::Curve.

Definition at line 110 of file bezier-curve.h.

References order(), and setPoint().

Referenced by Geom::Path::clear(), Geom::Path::do_append(), Geom::Path::do_update(), draw_ray(), Geom::Path::Path(), Geom::Path::setInitial(), and Geom::Path::start().

◆ setInitial()

void Geom::BezierCurve::setInitial ( Point const &  v)
inlineoverridevirtual

Change the starting point of the curve.

After calling this method, it is guaranteed that \(\mathbf{C}(0) = \mathbf{p}\), and the curve is still continuous. The precise new shape of the curve varies with curve type.

Parameters
pNew starting point of the curve

Implements Geom::Curve.

Definition at line 109 of file bezier-curve.h.

References setPoint().

Referenced by Geom::Path::clear(), Geom::Path::close(), Geom::Path::do_append(), Geom::Path::do_update(), Inkscape::LivePathEffect::LPEFillBetweenMany::doEffect(), draw_ray(), Geom::Path::Path(), Geom::Path::setFinal(), Geom::Path::snapEnds(), and Geom::Path::start().

◆ setPoint()

void Geom::BezierCurve::setPoint ( unsigned  ix,
Point const &  v 
)
inline

Modify a control point.

Parameters
ixThe zero-based index of the point to modify. Note that the caller is responsible for checking that this value is <= order().
vThe new value of the point

Definition at line 77 of file bezier-curve.h.

References inner, Geom::X, and Geom::Y.

Referenced by SPCurve::last_point_additive_move(), operator*=(), setFinal(), setInitial(), and setPoints().

◆ setPoints()

virtual void Geom::BezierCurve::setPoints ( std::vector< Point > const &  ps)
inlinevirtual

Set new control points.

Parameters
psVector which must contain order() + 1 points. Note that the caller is responsible for checking the size of this vector.
Exceptions
LogicalErrorThrown when the size of the vector does not match the order.

Definition at line 85 of file bezier-curve.h.

References order(), and setPoint().

◆ size()

unsigned Geom::BezierCurve::size ( ) const
inline

Get the number of control points.

Definition at line 63 of file bezier-curve.h.

References inner, and Geom::X.

Referenced by _equalTo(), feed(), isDegenerate(), isLineSegment(), isNear(), operator*=(), operator*=(), operator*=(), TEST(), TEST_F(), TEST_F(), and timesWithRadiusOfCurvature().

◆ timesWithRadiusOfCurvature()

std::vector< Coord > Geom::BezierCurve::timesWithRadiusOfCurvature ( double  radius) const

Computes the times where the radius of curvature of the bezier curve equals the given radius.

The algorithm works as follows: Find the solutions of curvature of curve at t = curvatureValue This is equivalent to (dx*ddy-ddx*dy)/curvatureValue = (dx**2+dy**2)**(3/2) When the left side is positive, taking the square gives ((dx*ddy-ddx*dy)/curvatureValue)**2 - (dx**2+dy**2)**3 = 0 This is a polyomial for BezierCurves and can be solved with root finding algos.

Definition at line 331 of file bezier-curve.cpp.

References Geom::derivative(), inner, size(), Geom::X, and Geom::Y.

◆ toSBasis()

D2< SBasis > Geom::BezierCurve::toSBasis ( ) const
inlineoverridevirtual

Convert the curve to a symmetric power basis polynomial.

Symmetric power basis polynomials (S-basis for short) are numerical representations of curves with excellent numerical properties. Most high level operations provided by 2Geom are implemented in terms of S-basis operations, so every curve has to provide a method to convert it to an S-basis polynomial on two variables. See SBasis class reference for more information.

Implements Geom::Curve.

Definition at line 169 of file bezier-curve.h.

References inner.

Referenced by Geom::xAx::crossings(), Geom::EllipticalArc::toSBasis(), wrap_rq_to_cubic_sb(), and wrap_rq_to_cubic_sb_l().

◆ valueAt()

Coord Geom::BezierCurve::valueAt ( Coord  t,
Dim2  d 
) const
inlineoverridevirtual

Evaluate one of the coordinates at the specified time value.

Parameters
tTime value
dThe dimension to evaluate
Returns
The specified coordinate of \(\mathbf{C}(t)\)

Reimplemented from Geom::Curve.

Definition at line 168 of file bezier-curve.h.

References inner.

Referenced by Geom::EllipticalArc::valueAt().

Friends And Related Symbol Documentation

◆ bezier_length()

Coord bezier_length ( std::vector< Point > const &  points,
Coord  tolerance 
)
related

Compute the length of a bezier curve given by a vector of its control points.

Definition at line 746 of file bezier-curve.cpp.

References Geom::bezier_length_internal().

Referenced by length().

Member Data Documentation

◆ inner


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