Claw
1.7.3

The claw::math::curve class is a C++ implementation of the parametrized curves known as BÃ©zier curves.
The BÃ©zier curves are defined by a starting point P_{0}, an end point P_{n} and a sequence of points (P_{1}, â€¦, P_{n1}) controlling the direction of the curve between P_{0} and P_{n}. The points of the curve are then defined for a given fraction t âˆˆ [0, 1] of the length of the curve by the following equations:
A curve in Claw is defined by a sequence of points p_{j} through which the curve goes. A section s_{j} of the curve is then defined as two successive points (p_{j}, p_{j+1}). The equations of BÃ©zier, restricted to the cubic case (n=3), are used to describe the shape of each section. This shape is controlled by the output direction o_{j} of its first point and the input direction i_{j+1} of its last point. The equation of a section s_{j} is written as follows:
One can then build complex curves by concatenating several sections.
The library provides the following functionalities:
The curve class is defined as follows:
The curve class is parametrized by the type of the coordinates, named C
, and the traits to use to access their properties, named Traits
.
The class claw::math::coordinate_2d is a good candidate for C
, but any class can be used as long as Traits provides an implementation for the the following interface:
The control point class is the aggregation of a coordinate through which the curve goes (the position of the point), and two points defining the direction from which the curve respectively "enters and leaves" the point. Those input and output points are relative to the same origin than the curve's point (i.e. their coordinates are not relative to the curve's point itself).
The interface of the class is as follows:
Note: building a control point as follows
is equivalent to the following code
The control points of the curve can be accessed using iterators implementing the concept of ForwardIterator and BackwardIterator. The begin()
and end()
methods return an iterator
respectively on the first control point of the curve or just past the last control point of the curve. If the call is done on a const
curve
then a const_iterator
is returned.
Several methods can be used to insert a control point in a curve:
p
before the control point represented by the iterator pos
. If pos
== end(), then p
is inserted at the end of the curve,p
at the end of the curve. This is equivalent to curve::insert
( curve::end(), p ),p
at the beginning of the curve. This is equivalent to curve::insert
( curve::begin(), p ).Note: Please note that inserting a point in the curve between the beginning and the end of a section will invalidate the section.
The resolved point class represents the result of the computation of a point on the curve from an other parameter than t.
The interface of the class is defined as follows:
The interface presents the following methods:
get_position()
returns the coordinates of the points on the curve,get_section()
returns the section on which the point has been found,get_date()
returns a value of t such that for a resolved_point
p, the following applies: A section describes a part of a curve represented by two successive control points. One can access the section starting from the point represented by an iterator it
in the curve c
using this code:
The interface of the section class is as follows:
The main procedure to compute the coordinates of a point of the curve is to obtain a section of the curve and call
to get the coordinates of the point at a given t on the section.
If t is unknown, one can use the method get_point_at_x( value_type x, bool off_domain )
defined in claw::math::curve and claw::math::curve::section to obtain all the points of the curve or section having the given xcoordinate. If the argument off_domain
is set to true, then the following applies:
section::get_point_at_x()
, the resolved points found with a date t such that t < 0 or 1 < t are kept,curve::get_point_at_x()
, the points found at a date t < 0 on the first section of the curve or at a date t > 1 on the last section of the curve are kept.The section::get_tangent_at( double t )
returns the tangent to the curve at a given t on a given section.