SpatiumLib
Public Member Functions | Friends | List of all members
spatium::gfx2d::BezierCurve Class Reference

2D Bezier curve More...

#include <BezierCurve.h>

Public Member Functions

 BezierCurve (const std::vector< std::array< double, 2 >> &points)
 Constructor. More...
 
std::vector< std::array< double, 2 > > points () const
 Get the points of the curve. More...
 
int degree () const
 Get the degree of the curve. More...
 
std::array< double, 2 > evaluate (double t) const
 Evaluate bezier curve. More...
 
BezierCurve divide () const
 Divide a bezier curve. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const BezierCurve &curve)
 Output to ostream. More...
 

Detailed Description

2D Bezier curve

BezierCurve is a class to represent a parametric Bezier curve.

Constructor & Destructor Documentation

◆ BezierCurve()

spatium::gfx2d::BezierCurve::BezierCurve ( const std::vector< std::array< double, 2 >> &  points)
inline

Constructor.

Parameters
[in]pointsAnchor points (first and last point) and control points (intermediate). Min length = 2.

Member Function Documentation

◆ degree()

int spatium::gfx2d::BezierCurve::degree ( ) const
inline

Get the degree of the curve.

The degree is the number of points - 1. A 1st degree curve (linear) has two points, a 2nd degree curve (cubic) has 3 points, a 3rd degree curve (cubic) has 4 points, etc,

Returns
Degree

◆ divide()

BezierCurve spatium::gfx2d::BezierCurve::divide ( ) const
inline

Divide a bezier curve.

This will increase the degree of the curve without affecting the shape. The new control points are placed in between the existing control points

Returns
Bezier curve with degree + 1
Todo:
This function doesn't work properly yet. Perhaps it should be recursive.

◆ evaluate()

std::array<double, 2> spatium::gfx2d::BezierCurve::evaluate ( double  t) const
inline

Evaluate bezier curve.

Parameters
[in]tParameter along curve. Range [0,1]
Returns
Point coordinates (x,y)

◆ points()

std::vector<std::array<double,2> > spatium::gfx2d::BezierCurve::points ( ) const
inline

Get the points of the curve.

A curve should at least have 2 control points. The first and last control points (anchor points) are the starting point and end point of the line.

Returns
Points

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const BezierCurve curve 
)
friend

Output to ostream.


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