Commit 16b5affc authored by JasonChmn's avatar JasonChmn
Browse files

Fix problem in cubic hermite curve extended to any interval (not only [0,1]) /...

Fix problem in cubic hermite curve extended to any interval (not only [0,1]) / Added all conversion between bezier, polynomial, cubic hermite / All test ok
parent 11cfa45c
......@@ -67,7 +67,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
}
for(; it != PointsEnd; ++it)
{
pts_.push_back(*it);
control_points_.push_back(*it);
}
}
......@@ -95,7 +95,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
t_point_t updatedList = add_constraints<In>(PointsBegin, PointsEnd, constraints);
for(cit_point_t cit = updatedList.begin(); cit != updatedList.end(); ++cit)
{
pts_.push_back(*cit);
control_points_.push_back(*cit);
}
}
......@@ -123,7 +123,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
}
if (size_ == 1)
{
return mult_T_*pts_[0];
return mult_T_*control_points_[0];
}else
{
return evalHorner(t);
......@@ -141,7 +141,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
return *this;
}
t_point_t derived_wp;
for(typename t_point_t::const_iterator pit = pts_.begin(); pit != pts_.end()-1; ++pit)
for(typename t_point_t::const_iterator pit = control_points_.begin(); pit != control_points_.end()-1; ++pit)
derived_wp.push_back((num_t)degree_ * (*(pit+1) - (*pit)));
if(derived_wp.empty())
derived_wp.push_back(point_t::Zero(Dim));
......@@ -166,7 +166,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
// recomputing waypoints q_i from derivative waypoints p_i. q_0 is the given constant.
// then q_i = (sum( j = 0 -> j = i-1) p_j) /n+1
n_wp.push_back(current_sum);
for(typename t_point_t::const_iterator pit = pts_.begin(); pit != pts_.end(); ++pit)
for(typename t_point_t::const_iterator pit = control_points_.begin(); pit != control_points_.end(); ++pit)
{
current_sum += *pit;
n_wp.push_back(current_sum / new_degree);
......@@ -184,7 +184,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
///
virtual point_t derivate(const time_t t, const std::size_t order) const
{
bezier_curve_t deriv =compute_derivate(order);
bezier_curve_t deriv = compute_derivate(order);
return deriv(t);
}
......@@ -200,11 +200,11 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
{
const Numeric u = (t-T_min_)/(T_max_-T_min_);
point_t res = point_t::Zero(Dim);
typename t_point_t::const_iterator pts_it = pts_.begin();
typename t_point_t::const_iterator control_points_it = control_points_.begin();
for(typename std::vector<Bern<Numeric> >::const_iterator cit = bernstein_.begin();
cit !=bernstein_.end(); ++cit, ++pts_it)
cit !=bernstein_.end(); ++cit, ++control_points_it)
{
res += cit->operator()(u) * (*pts_it);
res += cit->operator()(u) * (*control_points_it);
}
return res*mult_T_;
}
......@@ -224,22 +224,22 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
point_t evalHorner(const Numeric t) const
{
const Numeric u = (t-T_min_)/(T_max_-T_min_);
typename t_point_t::const_iterator pts_it = pts_.begin();
typename t_point_t::const_iterator control_points_it = control_points_.begin();
Numeric u_op, bc, tn;
u_op = 1.0 - u;
bc = 1;
tn = 1;
point_t tmp =(*pts_it)*u_op; ++pts_it;
for(unsigned int i=1; i<degree_; i++, ++pts_it)
point_t tmp =(*control_points_it)*u_op; ++control_points_it;
for(unsigned int i=1; i<degree_; i++, ++control_points_it)
{
tn = tn*u;
bc = bc*((num_t)(degree_-i+1))/i;
tmp = (tmp + tn*bc*(*pts_it))*u_op;
tmp = (tmp + tn*bc*(*control_points_it))*u_op;
}
return (tmp + tn*u*(*pts_it))*mult_T_;
return (tmp + tn*u*(*control_points_it))*mult_T_;
}
const t_point_t& waypoints() const {return pts_;}
const t_point_t& waypoints() const {return control_points_;}
/// \brief Evaluate the curve value at time t using deCasteljau algorithm.
/// The algorithm will compute the \f$N-1\f$ centroids of parameters \f${t,1-t}\f$ of consecutive \f$N\f$ control points
......@@ -304,8 +304,8 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
}
t_point_t wps_first(size_),wps_second(size_);
const Numeric u = (t-T_min_)/(T_max_-T_min_);
wps_first[0] = pts_.front();
wps_second[degree_] = pts_.back();
wps_first[0] = control_points_.front();
wps_second[degree_] = control_points_.back();
t_point_t casteljau_pts = waypoints();
size_t id = 1;
while(casteljau_pts.size() > 1)
......@@ -391,9 +391,7 @@ struct bezier_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
/*const*/ std::size_t size_;
/*const*/ std::size_t degree_;
/*const*/ std::vector<Bern<Numeric> > bernstein_;
private:
t_point_t pts_;
/*const*/ t_point_t control_points_;
public:
static bezier_curve_t zero(const time_t T=1.)
......
......@@ -38,6 +38,7 @@ struct cubic_hermite_spline : public curve_abc<Time, Numeric, Dim, Safe, Point>
typedef std::pair<Point, Tangent> pair_point_tangent_t;
typedef std::vector< pair_point_tangent_t ,Eigen::aligned_allocator<Point> > t_pair_point_tangent_t;
typedef std::vector<Time> vector_time_t;
typedef Numeric num_t;
typedef int Index;
/*Attributes*/
......@@ -48,18 +49,19 @@ struct cubic_hermite_spline : public curve_abc<Time, Numeric, Dim, Safe, Point>
/// Exemple : \f$( 0., 0.5, 0.9, ..., 4.5 )\f$ with values corresponding to times for \f$P_0, P_1, P_2, ..., P_N\f$ respectively.
vector_time_t time_control_points_;
private:
/// Vector of Time corresponding to time duration of each subspline.<br>
/// For N control points with time \f$T_{P_0}, T_{P_1}, T_{P_2}, ..., T_{P_N}\f$ respectively,
/// duration of each subspline is : ( T_{P_1}-T_{P_0}, T_{P_2}-T_{P_1}, ..., T_{P_N}-T_{P_{N-1} )<br>
/// It contains \f$N-1\f$ durations.
vector_time_t duration_splines_;
/// Starting time of cubic hermite spline : T_min_ is equal to first time of control points.
Time T_min_;
/*const*/ Time T_min_;
/// Ending time of cubic hermite spline : T_max_ is equal to last time of control points.
Time T_max_;
/// Number of control points.
/*const*/ Time T_max_;
/// Number of control points (pairs).
std::size_t size_;
/// Degree (Cubic so degree 3)
const std::size_t degree_ = 3;
/*Attributes*/
public:
......@@ -143,29 +145,6 @@ struct cubic_hermite_spline : public curve_abc<Time, Numeric, Dim, Safe, Point>
}
}
/// \brief Set duration by default of each spline.
/// Set a linear time from 0 to 1 for each control point with a \f$step=1.0/N\f$
/// where \f$N\f$ is the number of control points.<br>
/// Exemple for 5 control points : vector time_control_points_ will contain \f$(0., 0.25, 0.5, 0.75, 1.0)\f$
/// corresponding to time for \f$P_0\f$, \f$P_1\f$, \f$P_2\f$, \f$P_3\f$ and \f$P_4\f$ respectively.
///
void setTimeSplinesDefault()
{
time_control_points_.clear();
T_min_ = 0.;
T_max_ = 1.;
Time timestep = (T_max_- T_min_) / (control_points_.size()-1);
Time time = 0.;
Index i = 0;
for (i=0; i<size(); i++)
{
//time_control_points_.push_back(time);
time_control_points_.push_back(time);
time += timestep;
}
computeDurationSplines();
}
/// \brief Get vector of pair (positition, derivative) corresponding to control points.
/// \return vector containing control points.
///
......@@ -240,8 +219,13 @@ struct cubic_hermite_spline : public curve_abc<Time, Numeric, Dim, Safe, Point>
assert(0. <= alpha <= 1. && "alpha must be in [0,1]");
Numeric h00, h10, h01, h11;
evalCoeffs(alpha,h00,h10,h01,h11,order_derivative);
//std::cout << "for val t="<<t<<" coef : h00="<<h00<<" h10="<<h10<<" h01="<<h01<<" h11="<<h11<<std::endl;
Point p_ = (h00 * Pair0.first + h10 * Pair0.second + h01 * Pair1.first + h11 * Pair1.second);
//std::cout << "for val t="<<t<<" alpha="<<alpha<<" coef : h00="<<h00<<" h10="<<h10<<" h01="<<h01<<" h11="<<h11<<std::endl;
Point p_ = (h00 * Pair0.first + h10 * dt * Pair0.second + h01 * Pair1.first + h11 * dt * Pair1.second);
// if derivative, divide by dt^order_derivative
for (int i=0; i<order_derivative; i++)
{
p_ /= dt;
}
return p_;
}
......
......@@ -15,37 +15,21 @@
namespace curves
{
/// \brief Converts a Bezier curve to a polynomial.
/// \param curve : the Bezier curve defined between [0,1] to convert.
/// \brief Converts a cubic hermite spline or a bezier curve to a polynomial.
/// \param curve : the bezier curve/cubic hermite spline defined between [Tmin,Tmax] to convert.
/// \return the equivalent polynomial.
template<typename Bezier, typename Polynomial>
Polynomial polynom_from_bezier(const Bezier& curve)
template<typename Polynomial, typename curveTypeToConvert>
Polynomial polynomial_from_curve(const curveTypeToConvert& curve)
{
typedef typename Polynomial::t_point_t t_point_t;
typedef typename Polynomial::num_t num_t;
t_point_t coefficients;
Bezier current (curve);
curveTypeToConvert current (curve);
coefficients.push_back(curve(curve.min()));
num_t T = curve.max()-curve.min();
num_t T_div = 1.0;
num_t fact = 1;
for(std::size_t i = 1; i<= curve.degree_; ++i)
{
current = current.compute_derivate(1);
fact *= (num_t)i;
coefficients.push_back(current(current.min())/fact);
}
return Polynomial(coefficients,curve.min(),curve.max());
}
template<typename Hermite, typename Polynomial>
Polynomial polynom_from_hermite(const Hermite& curve)
{
typedef typename Polynomial::t_point_t t_point_t;
typedef typename Polynomial::num_t num_t;
t_point_t coefficients;
Hermite current (curve);
coefficients.push_back(curve(curve.min()));
num_t fact = 1;
for(std::size_t i = 1; i<= 3; ++i)
{
fact *= (num_t)i;
coefficients.push_back(current.derivate(current.min(),i)/fact);
......@@ -53,44 +37,83 @@ Polynomial polynom_from_hermite(const Hermite& curve)
return Polynomial(coefficients,curve.min(),curve.max());
}
/// \brief Converts a Cubic Hermite curve to a cubic bezier.
/// \param curve : the cubic hermite curve defined between [0,1] to convert.
/// \brief Converts a cubic hermite spline or polynomial to a cubic bezier curve.
/// \param curve : the polynomial of order 3 or less/cubic hermite spline defined between [Tmin,Tmax] to convert.
/// \return the equivalent cubic bezier curve.
template<typename Hermite, typename Bezier>
Bezier bezier_from_hermite(const Hermite& curve)
template<typename Bezier, typename curveTypeToConvert>
Bezier bezier_from_curve(const curveTypeToConvert& curve)
{
typedef typename Hermite::pair_point_tangent_t pair_point_tangent_t;
typedef typename Bezier::point_t point_t;
typedef typename Bezier::t_point_t t_point_t;
typedef typename Bezier::num_t num_t;
Hermite current (curve);
assert(current.control_points_.size() >= 2);
typedef typename Bezier::point_t point_t;
typedef typename Bezier::t_point_t t_point_t;
typedef typename Bezier::num_t num_t;
curveTypeToConvert current (curve);
assert(current.order_>0);
pair_point_tangent_t pair0 = current.control_points_.at(0);
pair_point_tangent_t pair1 = current.control_points_.at(1);
num_t T_min = current.min();
num_t T_max = current.max();
num_t T = T_max-T_min;
// Positions/Velocities of hermite curve
point_t h_p0 = pair0.first;
point_t h_m0 = pair0.second;
point_t h_p1 = pair1.first;
point_t h_m1 = pair1.second;
// Positions and derivatives
point_t p0 = current(T_min);
point_t p1 = current(T_max);
point_t m0 = current.derivate(T_min,1);
point_t m1 = current.derivate(T_max,1);
// Convert to bezier control points
// for t in [0,1] : x'(0)=3(b_p1-b_p0) and x'(1)=3(b_p3-b_p2)
// so : h_m0=3(b_p1-b_p0) and h_m1=3(b_p3-b_p2)
// <=> b_p1=(h_m0/3)+b_p0 and b_p2=-(h_m1/3)+b_p3
point_t b_p0 = h_p0;
point_t b_p3 = h_p1;
point_t b_p1 = (h_m0/3)+b_p0;
point_t b_p2 = -(h_m1/3)+b_p3;
// for t in [Tmin,Tmax] and T=Tmax-Tmin : x'(0)=3(b_p1-b_p0)/T and x'(1)=3(b_p3-b_p2)/T
// so : m0=3(b_p1-b_p0)/T and m1=3(b_p3-b_p2)/T
// <=> b_p1=T(m0/3)+b_p0 and b_p2=-T(m1/3)+b_p3
point_t b_p0 = p0;
point_t b_p3 = p1;
point_t b_p1 = T*m0/3+b_p0;
point_t b_p2 = -T*m1/3+b_p3;
t_point_t control_points;
control_points.push_back(b_p0);
control_points.push_back(b_p1);
control_points.push_back(b_p2);
control_points.push_back(b_p3);
return Bezier(control_points.begin(), control_points.end());
return Bezier(control_points.begin(), control_points.end(), current.min(), current.max());
}
/// \brief Converts a polynomial of order 3 or less/cubic bezier curve to a cubic hermite spline.
/// \param curve : the polynomial of order 3 or less/cubic bezier curve defined between [Tmin,Tmax] to convert.
/// \return the equivalent cubic hermite spline.
template<typename Hermite, typename curveTypeToConvert>
Hermite hermite_from_curve(const curveTypeToConvert& curve)
{
typedef typename Hermite::pair_point_tangent_t pair_point_tangent_t;
typedef typename Hermite::t_pair_point_tangent_t t_pair_point_tangent_t;
typedef typename Hermite::point_t point_t;
typedef typename Hermite::num_t num_t;
curveTypeToConvert current (curve);
assert(current.order_>0);
num_t T_min = current.min();
num_t T_max = current.max();
num_t T = T_max-T_min;
// Positions and derivatives
point_t p0 = current(T_min);
point_t p1 = current(T_max);
point_t m0 = current.derivate(T_min,1);
point_t m1 = current.derivate(T_max,1);
pair_point_tangent_t pair0(p0,m0);
pair_point_tangent_t pair1(p1,m1);
t_pair_point_tangent_t control_points;
control_points.push_back(pair0);
control_points.push_back(pair1);
std::vector< double > time_control_points;
time_control_points.push_back(T_min);
time_control_points.push_back(T_max);
return Hermite(control_points.begin(), control_points.end(), time_control_points);
}
} // namespace curve
......
......@@ -394,9 +394,12 @@ BOOST_PYTHON_MODULE(curves)
/** END bernstein polynomial**/
/** BEGIN curves conversion**/
def("polynom_from_bezier", polynom_from_bezier<bezier3_t,polynomial_t>);
def("bezier_from_hermite", bezier_from_hermite<cubic_hermite_spline_t,bezier3_t>);
def("polynom_from_hermite", polynom_from_hermite<cubic_hermite_spline_t,polynomial_t>);
def("polynomial_from_bezier", polynomial_from_curve<polynomial_t,bezier3_t>);
def("polynomial_from_hermite", polynomial_from_curve<polynomial_t,cubic_hermite_spline_t>);
def("bezier_from_hermite", bezier_from_curve<bezier3_t,cubic_hermite_spline_t>);
def("bezier_from_polynomial", bezier_from_curve<bezier3_t,polynomial_t>);
def("hermite_from_bezier", hermite_from_curve<cubic_hermite_spline_t, bezier3_t>);
def("hermite_from_polynomial", hermite_from_curve<cubic_hermite_spline_t, polynomial_t>);
/** END curves conversion**/
......
......@@ -11,7 +11,9 @@ import unittest
from curves import bezier3, bezier6
from curves import curve_constraints, polynomial, piecewise_polynomial_curve, exact_cubic, cubic_hermite_spline
from curves import polynom_from_bezier, bezier_from_hermite, polynom_from_hermite
from curves import polynomial_from_bezier, polynomial_from_hermite
from curves import bezier_from_hermite, bezier_from_polynomial
from curves import hermite_from_bezier, hermite_from_polynomial
class TestCurves(unittest.TestCase):
#def print_str(self, inStr):
......@@ -145,39 +147,6 @@ class TestCurves(unittest.TestCase):
a = exact_cubic(waypoints, time_waypoints, c)
return
def test_polynom_from_bezier(self):
# converting bezier to polynomial
__EPS = 1e-6
waypoints = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
a = bezier3(waypoints)
a_pol = polynom_from_bezier(a)
self.assertTrue (norm(a(0.3) - a_pol(0.3)) < __EPS)
return
def test_bezier_from_cubic_hermite(self):
# converting cubic hermite to cubic bezier
__EPS = 1e-6
points = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
tangents = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
time_points = matrix([0., 1.]).transpose()
a_hermite = cubic_hermite_spline(points, tangents, time_points)
a_bezier = bezier_from_hermite(a_hermite)
self.assertTrue (norm(a_hermite(0.3) - a_bezier(0.3)) < __EPS)
return
def test_polynom_from_cubic_hermite(self):
# converting cubic hermite to polynom
__EPS = 1e-6
points = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
tangents = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
time_points = matrix([0., 1.]).transpose()
a_hermite = cubic_hermite_spline(points, tangents, time_points)
a_pol = polynom_from_hermite(a_hermite)
self.assertTrue (norm(a_hermite(0.3) - a_pol(0.3)) < __EPS)
return
def test_cubic_hermite_spline(self):
points = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
tangents = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
......@@ -190,5 +159,31 @@ class TestCurves(unittest.TestCase):
a.derivate(0.4, 2)
return
def test_conversion_curves(self):
__EPS = 1e-6
waypoints = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
a = bezier3(waypoints)
# converting bezier to polynomial
a_pol = polynomial_from_bezier(a)
self.assertTrue (norm(a(0.3) - a_pol(0.3)) < __EPS)
# converting polynomial to hermite
a_chs = hermite_from_polynomial(a_pol);
self.assertTrue (norm(a_chs(0.3) - a_pol(0.3)) < __EPS)
# converting hermite to bezier
a_bc = bezier_from_hermite(a_chs);
self.assertTrue (norm(a_chs(0.3) - a_bc(0.3)) < __EPS)
self.assertTrue (norm(a(0.3) - a_bc(0.3)) < __EPS)
# converting bezier to hermite
a_chs = hermite_from_bezier(a);
self.assertTrue (norm(a(0.3) - a_chs(0.3)) < __EPS)
# converting hermite to polynomial
a_pol = polynomial_from_hermite(a_chs)
self.assertTrue (norm(a_pol(0.3) - a_chs(0.3)) < __EPS)
# converting polynomial to bezier
a_bc = bezier_from_polynomial(a_pol)
self.assertTrue (norm(a_bc(0.3) - a_pol(0.3)) < __EPS)
self.assertTrue (norm(a(0.3) - a_bc(0.3)) < __EPS)
return
if __name__ == '__main__':
unittest.main()
......@@ -73,6 +73,31 @@ void ComparePoints(const Eigen::VectorXd& pt1, const Eigen::VectorXd& pt2, const
}
}
template<typename curve1, typename curve2>
void compareCurves(curve1 c1, curve2 c2, const std::string& errMsg, bool& error)
{
double T_min = c1.min();
double T_max = c1.max();
if (T_min!=c2.min() || T_max!=c2.max())
{
std::cout << "compareCurves, time min and max of curves does not match ["<<T_min<<","<<T_max<<"] "
<< " and ["<<c2.min()<<","<<c2.max()<<"] "<<std::endl;
error = true;
}
else
{
// derivative in T_min and T_max
ComparePoints(c1.derivate(T_min,1),c2.derivate(T_min,1),errMsg, error, false);
ComparePoints(c1.derivate(T_max,1),c2.derivate(T_max,1),errMsg, error, false);
// Test values on curves
for(double i =T_min; i<T_max; i+=0.02)
{
ComparePoints(c1(i),c2(i),errMsg, error, false);
ComparePoints(c1(i),c2(i),errMsg, error, false);
}
}
}
/*Cubic Function tests*/
void CubicFunctionTest(bool& error)
{
......@@ -267,8 +292,9 @@ void BezierCurveTestCompareHornerAndBernstein(bool&) // error
params.push_back(c);
// 3d curve
bezier_curve_t cf(params.begin(), params.end());
bezier_curve_t cf(params.begin(), params.end()); // defined in [0,1]
// Check all evaluation of bezier curve
clock_t s0,e0,s1,e1,s2,e2,s3,e3;
s0 = clock();
for(std::vector<double>::const_iterator cit = values.begin(); cit != values.end(); ++cit)
......@@ -346,11 +372,12 @@ void BezierCurveTestCompareHornerAndBernstein(bool&) // error
std::cout << "time for bernstein eval " << double(e1 - s1) / CLOCKS_PER_SEC << std::endl;
std::cout << "time for horner eval " << double(e2 - s2) / CLOCKS_PER_SEC << std::endl;
std::cout << "time for deCasteljau eval " << double(e3 - s3) / CLOCKS_PER_SEC << std::endl;
}
void BezierDerivativeCurveTest(bool& error)
{
std::string errMsg("In test BezierDerivativeCurveTest ; unexpected result for x ");
std::string errMsg("In test BezierDerivativeCurveTest ;, Error While checking value of point on curve : ");
point_t a(1,2,3);
point_t b(2,3,4);
point_t c(3,4,5);
......@@ -369,7 +396,7 @@ void BezierDerivativeCurveTest(bool& error)
void BezierDerivativeCurveTimeReparametrizationTest(bool& error)
{
std::string errMsg("In test BezierDerivativeCurveTimeReparametrizationTest ; unexpected result for x ");
std::string errMsg("In test BezierDerivativeCurveTimeReparametrizationTest, Error While checking value of point on curve : ");
point_t a(1,2,3);
point_t b(2,3,4);
point_t c(3,4,5);
......@@ -397,7 +424,7 @@ void BezierDerivativeCurveTimeReparametrizationTest(bool& error)
void BezierDerivativeCurveConstraintTest(bool& error)
{
std::string errMsg("In test BezierDerivativeCurveConstraintTest ; unexpected result for x ");
std::string errMsg("In test BezierDerivativeCurveConstraintTest, Error While checking value of point on curve : ");
point_t a(1,2,3);
point_t b(2,3,4);
point_t c(3,4,5);
......@@ -428,9 +455,10 @@ void BezierDerivativeCurveConstraintTest(bool& error)
}
void BezierToPolynomialConversionTest(bool& error)
void toPolynomialConversionTest(bool& error)
{
std::string errMsg("In test BezierToPolynomialConversionTest ; unexpected result for x => ");
// bezier to polynomial
std::string errMsg("In test BezierToPolynomialConversionTest, Error While checking value of point on curve : ");
point_t a(1,2,3);
point_t b(2,3,4);
point_t c(3,4,5);
......@@ -453,94 +481,69 @@ void BezierToPolynomialConversionTest(bool& error)
control_points.push_back(i);
double T_min = 1.0;
double T_max = 2.0;
bezier_curve_t cf(control_points.begin(), control_points.end(),T_min, T_max);
polynomial_t pol =polynom_from_bezier<bezier_curve_t, polynomial_t>(cf);
for(double i =T_min; i<T_max; i+=0.01)
{
ComparePoints(cf(i),pol(i),errMsg, error, true);
ComparePoints(cf(i),pol(i),errMsg, error, false);
}
double T_max = 3.0;
bezier_curve_t bc(control_points.begin(), control_points.end(),T_min, T_max);
polynomial_t pol = polynomial_from_curve<polynomial_t, bezier_curve_t>(bc);
}
void CubicHermiteToPolynomialTest(bool& error)
void cubicConversionTest(bool& error)
{
std::string errMsg("In test CubicHermiteToPolynomialTest ; unexpected result for x => ");
std::string errMsg0("In test CubicConversionTest - convert hermite to, Error While checking value of point on curve : ");
std::string errMsg1("In test CubicConversionTest - convert bezier to, Error While checking value of point on curve : ");
std::string errMsg2("In test CubicConversionTest - convert polynomial to, Error While checking value of point on curve : ");
// Create cubic hermite spline : Test hermite to bezier/polynomial
point_t p0(1,2,3);
point_t m0(2,3,4);
point_t p1(3,4,5);
point_t m1(3,6,7);
std::vector< double > time_control_points;
time_control_points.push_back(0.);
time_control_points.push_back(1.);
pair_point_tangent_t pair0(p0,m0);
pair_point_tangent_t pair1(p1,m1);
t_pair_point_tangent_t control_points;
control_points.push_back(pair0);
control_points.push_back(pair1);
cubic_hermite_spline_t ch(control_points.begin(), control_points.end(), time_control_points);
polynomial_t pol = polynom_from_hermite<cubic_hermite_spline_t, polynomial_t>(ch);
// Test derivative in t=0 and t=1
ComparePoints(ch.derivate(0.,1),pol.derivate(0.,1),errMsg, error, true);
ComparePoints(ch.derivate(1.,1),pol.derivate(1.,1),errMsg, error, true);
for(double i =0.; i<1.; i+=0.01)
{
ComparePoints(ch(i),pol(i),errMsg, error, true);
ComparePoints(ch(i),pol(i),errMsg, error, false);
}
}
void CubicHermiteToCubicBezierConversionTest(bool& error)
{
std::string errMsg("In test CubicHermiteToCubicBezierConversionTest ; unexpected result for x => ");
point_t p0(1,2,3);
point_t m0(2,3,4);
point_t p1(3,4,5);
point_t m1(3,6,7);
std::vector< double > time_control_points;
time_control_points.push_back(0.);