Description

Definition of a piece-wise cubic Bezier approximation of a 3D curve.

This class encapsulates a piece-wise cubic Bezier approximation of a 3D curve, represented as a set of three arrays of locations. For each point on the curve, we also define a vector 'inCV' which represents the vertex of the control polygon prior to the point and a vector 'outCV' which represents the vertex of the control polygon following the point. This class provides methods for evaluating the value, as well as the first and second derivatives of a point on a specified interval of the piece-wise 3D curve (using the Bernstein polynomial representation of Bezier curves). In addition, it provides a method for calculating the closest point on a specified interval of the curve to a specified location.

#include <ChBezierCurve.h>

Public Member Functions

 ChBezierCurve (const std::vector< ChVector3d > &points, const std::vector< ChVector3d > &inCV, const std::vector< ChVector3d > &outCV, bool closed=false)
 Constructor from specified nodes and control points.
 
 ChBezierCurve (const std::vector< ChVector3d > &points, bool closed=false)
 Constructor from specified nodes. More...
 
 ChBezierCurve ()
 Default constructor (required by serialization)
 
 ~ChBezierCurve ()
 Destructor for ChBezierCurve.
 
void setPoints (const std::vector< ChVector3d > &points, const std::vector< ChVector3d > &inCV, const std::vector< ChVector3d > &outCV)
 Set the nodes and control points.
 
size_t GetNumPoints () const
 Return the number of knot points.
 
size_t GetNumSegments () const
 Return the number of intervals (segments).
 
bool IsClosed () const
 Return true if path is closed and false otherwise.
 
const ChVector3dGetPoint (size_t i) const
 Return the knot point with specified index.
 
const std::vector< ChVector3dGetPoints () const
 Return all curve knots.
 
ChVector3d Eval (double t) const
 Evaluate the value of the Bezier curve. More...
 
ChVector3d Eval (size_t i, double t) const
 Evaluate the value of the Bezier curve. More...
 
ChVector3d EvalDer (size_t i, double t) const
 Evaluate the tangent vector to the Bezier curve. More...
 
ChVector3d EvalDer2 (size_t i, double t) const
 Evaluate the second derivative vector to the Bezier curve. More...
 
ChVector3d CalcClosestPoint (const ChVector3d &loc, size_t i, double &t) const
 Calculate the closest point on the curve to the given location. More...
 
void Write (const std::string &filename)
 Write the knots and control points to the specified file.
 
void ArchiveOut (ChArchiveOut &archive_out)
 Method to allow serialization of transient data to archives.
 
void ArchiveIn (ChArchiveIn &archive_in)
 Method to allow de-serialization of transient data from archives.
 

Static Public Member Functions

static std::shared_ptr< ChBezierCurveRead (const std::string &filename, bool closed=false)
 Create a ChBezierCurve using data in the specified file. More...
 

Friends

class ChBezierCurveTracker
 

Constructor & Destructor Documentation

◆ ChBezierCurve()

chrono::ChBezierCurve::ChBezierCurve ( const std::vector< ChVector3d > &  points,
bool  closed = false 
)

Constructor from specified nodes.

In this case, we evaluate the control polygon vertices inCV and outCV so that we obtain a piecewise cubic spline interpolant of the given knots.

std::cout << "curv diff: " << (m_inCV[1] - 2.0 * m_outCV[0] + m_points[0]) - (m_points[n] - 2.0 * m_inCV[n]

  • m_outCV[n-1]) << std::endl;

Member Function Documentation

◆ CalcClosestPoint()

ChVector3d chrono::ChBezierCurve::CalcClosestPoint ( const ChVector3d loc,
size_t  i,
double &  t 
) const

Calculate the closest point on the curve to the given location.

This function calculates and returns the point on the curve in the specified interval that is closest to the specified location. On input, the value 't' is an initial guess. On return, it contains the curve parameter corresponding to the closest point.

◆ Eval() [1/2]

ChVector3d chrono::ChBezierCurve::Eval ( double  t) const

Evaluate the value of the Bezier curve.

This function calculates and returns the point on the curve at the given curve parameter (assumed to be in [0,1]). A value t=0 returns the first point on the curve. A value t=1 returns the last point on the curve.

◆ Eval() [2/2]

ChVector3d chrono::ChBezierCurve::Eval ( size_t  i,
double  t 
) const

Evaluate the value of the Bezier curve.

This function calculates and returns the point on the curve in the specified interval between two knot points and at the given curve parameter (assumed to be in [0,1]). A value t-0 returns the first end of the specified interval. A value t=1 return the second end of the specified interval. It uses the Bernstein polynomial representation of a Bezier curve.

◆ EvalDer()

ChVector3d chrono::ChBezierCurve::EvalDer ( size_t  i,
double  t 
) const

Evaluate the tangent vector to the Bezier curve.

This function calculates and returns the first derivative (tangent vector) to the curve in the specified interval between two knot points and at the given curve parameter (assumed to be in [0,1]). It uses the Bernstein polynomial representation of a Bezier curve.

◆ EvalDer2()

ChVector3d chrono::ChBezierCurve::EvalDer2 ( size_t  i,
double  t 
) const

Evaluate the second derivative vector to the Bezier curve.

This function calculates and returns the second derivative vector to the curve in the specified interval between two knot points and at the given curve parameter (assumed to be in [0,1]). It uses the Bernstein polynomial representation of a Bezier curve.

◆ Read()

std::shared_ptr< ChBezierCurve > chrono::ChBezierCurve::Read ( const std::string &  filename,
bool  closed = false 
)
static

Create a ChBezierCurve using data in the specified file.

The input file is assumed to contain on the first line the number of data points and the number of data columns. The latter can be one of 3 or 9. In the first case, subsequent lines should contain the coordinates of the curve knots (one point per line). The returned Bezier curve is a piecewise cubic spline through the specified points. In the second case, subsequent lines should contain the coordinates of the curve knot, the coordinates of the "incoming" control point, and the coordinates of the "outgoing" control point (i.e. 9 values per line). The returned curve is a general Bezier curve using the specified knots and control polygons.


The documentation for this class was generated from the following files:
  • /builds/uwsbel/chrono/src/chrono/core/ChBezierCurve.h
  • /builds/uwsbel/chrono/src/chrono/core/ChBezierCurve.cpp