Commit 1277cb5c authored by JasonChmn's avatar JasonChmn
Browse files

[Fix cubic hermite] Cubic hermite in pyhton : Use tangent instead of position...

[Fix cubic hermite] Cubic hermite in pyhton : Use tangent instead of position to build cubic hermite
parent 19cafdde
Pipeline #5649 passed with stage
in 2 minutes
......@@ -134,7 +134,7 @@ t_pair_point_tangent_t getPairsPointTangent(const point_list_t& points, const po
}
for(int i =0;i<points.cols();++i)
{
res.push_back(pair_point_tangent_t(tangents.col(i), tangents.col(i)));
res.push_back(pair_point_tangent_t(points.col(i), tangents.col(i)));
}
return res;
}
......
......@@ -44,6 +44,7 @@ class TestCurves(unittest.TestCase):
a.min()
a.max()
a(0.4)
self.assertTrue ((a(a.min()) == matrix([1., 2., 3.]).transpose()).all())
self.assertTrue ((a.derivate(0.4, 0) == a(0.4)).all())
a.derivate(0.4, 2)
a = a.compute_derivate(100)
......@@ -95,6 +96,7 @@ class TestCurves(unittest.TestCase):
a.min()
a.max()
a(0.4)
self.assertTrue ((a(a.min()) == matrix([1., 2., 3.]).transpose()).all())
self.assertTrue ((a.derivate(0.4, 0) == a(0.4)).all())
a.derivate(0.4, 2)
return
......@@ -106,15 +108,16 @@ class TestCurves(unittest.TestCase):
waypoints2 = matrix([[1., 1., 1.], [1., 1., 1.]]).transpose()
a = polynomial(waypoints1, 0.,1.)
b = polynomial(waypoints2, 1., 3.)
ppc = piecewise_polynomial_curve(a)
ppc.add_curve(b)
ppc.min()
ppc.max()
ppc(0.4)
self.assertTrue ((ppc.derivate(0.4, 0) == ppc(0.4)).all())
ppc.derivate(0.4, 2)
ppc.is_continuous(0)
ppc.is_continuous(1)
pc = piecewise_polynomial_curve(a)
pc.add_curve(b)
pc.min()
pc.max()
pc(0.4)
self.assertTrue ((pc(pc.min()) == matrix([1., 1., 1.]).transpose()).all())
self.assertTrue ((pc.derivate(0.4, 0) == pc(0.4)).all())
pc.derivate(0.4, 2)
pc.is_continuous(0)
pc.is_continuous(1)
return
def test_piecewise_bezier3_curve(self):
......@@ -123,15 +126,16 @@ class TestCurves(unittest.TestCase):
waypoints = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
a = bezier3(waypoints, 0., 1.)
b = bezier3(waypoints, 1., 2.)
ppc = piecewise_bezier3_curve(a)
ppc.add_curve(b)
ppc.min()
ppc.max()
ppc(0.4)
self.assertTrue ((ppc.derivate(0.4, 0) == ppc(0.4)).all())
ppc.derivate(0.4, 2)
ppc.is_continuous(0)
ppc.is_continuous(1)
pc = piecewise_bezier3_curve(a)
pc.add_curve(b)
pc.min()
pc.max()
pc(0.4)
self.assertTrue ((pc(pc.min()) == matrix([1., 2., 3.]).transpose()).all())
self.assertTrue ((pc.derivate(0.4, 0) == pc(0.4)).all())
pc.derivate(0.4, 2)
pc.is_continuous(0)
pc.is_continuous(1)
return
def test_piecewise_bezier6_curve(self):
......@@ -140,35 +144,38 @@ class TestCurves(unittest.TestCase):
waypoints = matrix([[1., 2., 3., 7., 5., 5.], [4., 5., 6., 4., 5., 6.]]).transpose()
a = bezier6(waypoints, 0., 1.)
b = bezier6(waypoints, 1., 2.)
ppc = piecewise_bezier6_curve(a)
ppc.add_curve(b)
ppc.min()
ppc.max()
ppc(0.4)
self.assertTrue ((ppc.derivate(0.4, 0) == ppc(0.4)).all())
ppc.derivate(0.4, 2)
ppc.is_continuous(0)
ppc.is_continuous(1)
pc = piecewise_bezier6_curve(a)
pc.add_curve(b)
pc.min()
pc.max()
pc(0.4)
self.assertTrue ((pc(pc.min()) == matrix([1., 2., 3., 7., 5., 5.]).transpose()).all())
self.assertTrue ((pc.derivate(0.4, 0) == pc(0.4)).all())
pc.derivate(0.4, 2)
pc.is_continuous(0)
pc.is_continuous(1)
return
def test_piecewise_cubic_hermite_curve(self):
# To test :
# - Functions : constructor, min, max, derivate, add_curve, is_continuous
points = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
tangents = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
tangents = matrix([[2., 2., 2.], [4., 4., 4.]]).transpose()
time_points0 = matrix([0., 1.]).transpose()
time_points1 = matrix([1., 2.]).transpose()
a = cubic_hermite_spline(points, tangents, time_points0)
b = cubic_hermite_spline(points, tangents, time_points1)
ppc = piecewise_cubic_hermite_curve(a)
ppc.add_curve(b)
ppc.min()
ppc.max()
ppc(0.4)
self.assertTrue ((ppc.derivate(0.4, 0) == ppc(0.4)).all())
ppc.derivate(0.4, 2)
ppc.is_continuous(0)
ppc.is_continuous(1)
pc = piecewise_cubic_hermite_curve(a)
pc.add_curve(b)
pc.min()
pc.max()
pc(0.4)
self.assertTrue ((pc(0.) == matrix([1., 2., 3.]).transpose()).all())
self.assertTrue ((pc.derivate(0.,1) == matrix([2., 2., 2.]).transpose()).all())
self.assertTrue ((pc.derivate(0.4, 0) == pc(0.4)).all())
pc.derivate(0.4, 2)
pc.is_continuous(0)
pc.is_continuous(1)
return
def test_exact_cubic(self):
......@@ -206,12 +213,14 @@ class TestCurves(unittest.TestCase):
def test_cubic_hermite_spline(self):
points = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
tangents = matrix([[1., 2., 3.], [4., 5., 6.]]).transpose()
tangents = matrix([[2., 2., 2.], [4., 4., 4.]]).transpose()
time_points = matrix([0., 1.]).transpose()
a = cubic_hermite_spline(points, tangents, time_points)
a.min()
a.max()
a(0.4)
self.assertTrue ((a(0.) == matrix([1., 2., 3.]).transpose()).all())
self.assertTrue ((a.derivate(0.,1) == matrix([2., 2., 2.]).transpose()).all())
self.assertTrue ((a.derivate(0.4, 0) == a(0.4)).all())
a.derivate(0.4, 2)
return
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment