Core 1.0
Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
CubicCurve2 Class Reference

Cubic curves in the plane. More...

#include <curve.h>

Public Member Functions

 CubicCurve2 ()
 Empty.
 
 CubicCurve2 (const Cubic &, const Cubic &)
 Creates a cubic curve. More...
 
 CubicCurve2 (const CubicCurve &)
 Creates a cubic curve. More...
 
 ~CubicCurve2 ()
 Empty.
 
Cubicoperator[] (int)
 Access curve components.
 
Cubic operator[] (int) const
 Access curve components.
 
CubicCurve ToCubicCurve (const Cubic &=Cubic(0.0, 0.0, 0.0, 0.0)) const
 Convert a planar cubic curve to a cubic curve. More...
 
CubicCurve2 operator- () const
 Negative curve unary operator.
 
QuadricCurve2 Tangent () const
 Computes the quadric curve whose components are the derivatives of the curve. More...
 
Vector2 Tangent (const double &) const
 Computes the tangent to the cubic curve at a given position on the curve. More...
 
Vector2 Normal (const double &) const
 Computes the normal vector to the cubic curve at a given position on the curve. More...
 
double S (const double &, int=256) const
 Compute the curvilign absisca of a point on the curve. More...
 
double U (const double &, int=256) const
 Compute the parameter corresponding to the argument curvilign absisca of a point on the curve. More...
 
int Intersect (const Ray2 &, double[3]) const
 Compute the intersection between the curve and a ray. More...
 
double Length (int=256) const
 Computes the length of the cubic curve. Integration is performed over interval [0,1]. More...
 
double Length (const double &, const double &, int=256) const
 Computes the length of the cubic curve over interval [a,b]. More...
 
double InverseArcLength (const double &, int=256) const
 Compute the parameter t corresponding to a given input arc length. More...
 
Vector2 operator() (const double &) const
 Evaluates curve point at a given location. More...
 
Vector2 Eval (const double &) const
 Evaluates curve point at a given location. More...
 
double Curvature (const double &) const
 Computes the signed curvature of the curve at a given point p(t). More...
 
double Curvature (const double &, const double &) const
 Compute the maximum curvature over a given interval. More...
 
Box2 GetBox () const
 Compute the bounding box of the cubic curve with parameter interval [0,1].
 
double R (const Vector2 &, double &) const
 Compute the squared distance between a point in the plane and the cubic curve. More...
 
Vector2 Normal (const Vector2 &, double &) const
 Compute the projection of a point on the curve. More...
 
double UV (const Vector2 &, double &, double &) const
 Compute the inverse mapping for a given input point. More...
 
Vector2 UV (const Vector2 &) const
 Compute the inverse mapping for a given input point. More...
 
Matrix2 GetMatrix (const double &) const
 Compute the Frenet vectors (tangent and normal) at a given point on the curve. More...
 
Frame2 GetFrame (const double &) const
 Compute the frame at a given point on the curve. More...
 
Vector2 BezierControl (int) const
 Compute the i-th Bézier control point of the curve. More...
 
void Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const
 Draw a cubic curve. More...
 

Static Public Member Functions

static CubicCurve2 Hermite (const Vector2 &, const Vector2 &, const Vector2 &, const Vector2 &)
 Creates an Hermite cubic curve on interval [0,1] given vertex locations and tangent vectors (in that order). More...
 
static CubicCurve2 Bezier (const Vector2 &, const Vector2 &, const Vector2 &, const Vector2 &)
 Creates a Bezier cubic curve on interval [0,1] given four vertex locations. More...
 

Protected Attributes

Cubic y
 Cubic polynomial functions for every coordinate.
 

Friends

std::ostream & operator<< (std::ostream &, const CubicCurve2 &)
 Overloaded. More...
 

Detailed Description

Cubic curves in the plane.

Constructor & Destructor Documentation

◆ CubicCurve2() [1/2]

CubicCurve2::CubicCurve2 ( const Cubic x,
const Cubic y 
)
explicit

Creates a cubic curve.

Parameters
x,yCubic parametric equations of the corresponding x, y coordinates.

◆ CubicCurve2() [2/2]

CubicCurve2::CubicCurve2 ( const CubicCurve c)
explicit

Creates a cubic curve.

Parameters
cCubic curve.

Member Function Documentation

◆ Bezier()

CubicCurve2 CubicCurve2::Bezier ( const Vector2 a,
const Vector2 b,
const Vector2 c,
const Vector2 d 
)
static

Creates a Bezier cubic curve on interval [0,1] given four vertex locations.

Parameters
a,b,c,dVertices of the Bezier curve.

◆ BezierControl()

Vector2 CubicCurve2::BezierControl ( int  i) const
inline

Compute the i-th Bézier control point of the curve.

Computations have been optimized.

Parameters
iIndex.

◆ Curvature() [1/2]

double CubicCurve2::Curvature ( const double &  t) const

Computes the signed curvature of the curve at a given point p(t).

Parameters
tParameter.

◆ Curvature() [2/2]

double CubicCurve2::Curvature ( const double &  a,
const double &  b 
) const

Compute the maximum curvature over a given interval.

Compute the analytic equation of the numerator of the curvature expression, search the roots, find extrema and returns the maximum.

Parameters
a,bInterval

◆ Draw()

void CubicCurve2::Draw ( QGraphicsScene &  scene,
const QPen &  pen = QPen(),
const QBrush &  = QBrush() 
) const

Draw a cubic curve.

The brush is not used.

Parameters
sceneGraphics scene.
penThe pen.

◆ Eval()

Vector2 CubicCurve2::Eval ( const double &  t) const

Evaluates curve point at a given location.

Parameters
tParameter.

◆ GetFrame()

Frame2 CubicCurve2::GetFrame ( const double &  u) const

Compute the frame at a given point on the curve.

Parameters
uParameter.

◆ GetMatrix()

Matrix2 CubicCurve2::GetMatrix ( const double &  u) const

Compute the Frenet vectors (tangent and normal) at a given point on the curve.

Parameters
uParameter.

◆ Hermite()

CubicCurve2 CubicCurve2::Hermite ( const Vector2 a,
const Vector2 b,
const Vector2 ta,
const Vector2 tb 
)
static

Creates an Hermite cubic curve on interval [0,1] given vertex locations and tangent vectors (in that order).

Parameters
a,bEnd vertices of the Hermite cubic curve.
ta,tbTangent vectors at the end vertices.

◆ Intersect()

int CubicCurve2::Intersect ( const Ray2 ray,
double  t[3] 
) const

Compute the intersection between the curve and a ray.

Parameters
rayThe ray.
tIntersection depths.

◆ InverseArcLength()

double CubicCurve2::InverseArcLength ( const double &  s,
int  n = 256 
) const

Compute the parameter t corresponding to a given input arc length.

Parameters
sArc length, which should be positive.
nDiscretization of the curve.

◆ Length() [1/2]

double CubicCurve2::Length ( const double &  a,
const double &  b,
int  n = 256 
) const

Computes the length of the cubic curve over interval [a,b].

Since we have the parametric equations of the coordinates of the points on the curve, then the length is the integral of the square root of the sum of the squared derivatives where the limits of integration are [a,b].

In the general case, the function we end up with is not integrable in closed form, leading to an elliptic integral or some such. Thus we evaluate the integral numerically.

Parameters
a,bInterval.
nDiscretization of the integration interval.

◆ Length() [2/2]

double CubicCurve2::Length ( int  n = 256) const

Computes the length of the cubic curve. Integration is performed over interval [0,1].

Simply call CubicCurve::Length(0.0,1.0,n) with n as the passed argument parameter.

Parameters
nDiscretization of the curve.

◆ Normal() [1/2]

Vector2 CubicCurve2::Normal ( const double &  t) const

Computes the normal vector to the cubic curve at a given position on the curve.

The normal is the obtained by evaluating the second derivative.

Parameters
tPosition.

◆ Normal() [2/2]

Vector2 CubicCurve2::Normal ( const Vector2 p,
double &  u 
) const

Compute the projection of a point on the curve.

Parameters
pPoint.
uParameter defining the projected point.

◆ operator()()

Vector2 CubicCurve2::operator() ( const double &  t) const

Evaluates curve point at a given location.

Parameters
tParameter.

◆ R()

double CubicCurve2::R ( const Vector2 p,
double &  u 
) const

Compute the squared distance between a point in the plane and the cubic curve.

This function computes the projection of a point p onto the curve by minimizing the distance function along the curve, expressed as a degree 5 polynomial.

Most of the coefficients of this polynomial are constant, and could be pre-processed in the constructor.

Parameters
pPoint.
uParameter defining the coordinate of the projection of the argument vertex onto the curve.

◆ S()

double CubicCurve2::S ( const double &  t,
int  n = 256 
) const

Compute the curvilign absisca of a point on the curve.

Parameters
tParameter that should be within [0,1] interval.
nDiscretization of the integration interval.

◆ Tangent() [1/2]

QuadricCurve2 CubicCurve2::Tangent ( ) const

Computes the quadric curve whose components are the derivatives of the curve.

This function is useful for preprocessing tangent computations.

◆ Tangent() [2/2]

Vector2 CubicCurve2::Tangent ( const double &  t) const

Computes the tangent to the cubic curve at a given position on the curve.

The tangent is the obtained by evaluating the first derivative.

Parameters
tPosition.

◆ ToCubicCurve()

CubicCurve CubicCurve2::ToCubicCurve ( const Cubic z = Cubic(0.0, 0.0, 0.0, 0.0)) const
inline

Convert a planar cubic curve to a cubic curve.

This is a convenience function, which is basically the same as:

CubicCurve2 c; // Curve in the plane
Cubic z; // Cubic for the z coordinate
CubicCurve3 c3=CubicCurve(c[0],c[1],z);
Cubic curves in the plane.
Definition: curve.h:239
Cubic curves.
Definition: curve.h:85
Cubic polynomials.
Definition: cubic.h:8
Parameters
zMissing cubic.

◆ U()

double CubicCurve2::U ( const double &  s,
int  n = 256 
) const

Compute the parameter corresponding to the argument curvilign absisca of a point on the curve.

Parameters
sArgument curvilign absisca (should be between 0.0 and the length of the curve).
nDiscretization of the integration interval.

◆ UV() [1/2]

Vector2 CubicCurve2::UV ( const Vector2 p) const

Compute the inverse mapping for a given input point.

See also
CubicCurve2::UV(const Vector2&, double&, double&)
Parameters
pPoint.
Returns
Inverse uv coordinates compacted into a Vector2.

◆ UV() [2/2]

double CubicCurve2::UV ( const Vector2 p,
double &  u,
double &  v 
) const

Compute the inverse mapping for a given input point.

Parameters
pPoint.
u,vInverse Coordinates, u will denote the position along the curve and v the signed distance to the curve.
Returns
Squared distance to the curve.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const CubicCurve2 curve 
)
friend

Overloaded.

Parameters
sStream.
curveThe cubic curve.