# Boost Users :

From: Nick Thompson (nathompson7_at_[hidden])
Date: 2019-09-30 12:08:55

The problem is in this line:

inter_points = interpolator_cr(max_s * (i / num_points));

i/num_points rounds to zero.

I just reproduced your code with the fix:

#include <iostream>
#include <boost/math/interpolators/catmull_rom.hpp>
#include <vector>
#include <array>

int main() {
std::vector<std::array<double, 2>> points_intr(16);
points_intr[0] = { 1.263270, 0.774614 };
points_intr[1] = { 1.876, 2.480 };
points_intr[2] = { 1.651110, 4.550 };
points_intr[3] = { 1.426340, 5.688 };
points_intr[4] = { 1.429, 7.054 };
points_intr[5] = { 2.073220, 8.377020 };
points_intr[6] = { 3.910, 9.140 };
points_intr[7] = { 6.430, 9.537 };
points_intr[8] = { 8.950, 9.859 };
points_intr[9] = { 11.470, 10.317 };
points_intr[10] = { 12.730, 10.6456 };
points_intr[11] = { 13.990, 11.0741 };
points_intr[12] = { 15.335, 11.6928 };
points_intr[13] = { 16.680, 12.5661 };
points_intr[14] = { 18.3538, 14.830 };
points_intr[15] = { 18.700, 16.056 };

boost::math::catmull_rom<std::array<double, 2>> interpolator_cr(std::move(points_intr));

auto max_s = interpolator_cr.max_parameter();
std::array<double, 2> inter_points;
for (int i = 0; i < 100; i++)
{
double arg = max_s*i/double(100);
inter_points = interpolator_cr(arg);
std::cout << "p(" << arg << ") = (" << inter_points[0] << ", " << inter_points[1] << ")\n";
}
}

No need to normalize your data.

Nick

â€â€â€â€â€â€â€ Original Message â€â€â€â€â€â€â€
On Sunday, September 29, 2019 8:46 PM, hgrwilson via Boost-users <boost-users_at_[hidden]> wrote:

> Hi all,
>
> I am trying to interpolate some data with a catmull_rom spline available
> in boost math (interpolation). However, the resulting spline collapses to a
> single point for all /s/, corresponding to the first control point,
> /points_intr[0]/.
>
> Below, the c++ code segment of the interpolation is depicted:
>
> std::vector<std::array<double, 2>> points_intr(16);
>
> points_intr[0] = { 1.263270, 0.774614 };
> points_intr[1] = { 1.876, 2.480 };
> points_intr[2] = { 1.651110, 4.550 };
> points_intr[3] = { 1.426340, 5.688 };
> points_intr[4] = { 1.429, 7.054 };
> points_intr[5] = { 2.073220, 8.377020 };
> points_intr[6] = { 3.910, 9.140 };
> points_intr[7] = { 6.430, 9.537 };
> points_intr[8] = { 8.950, 9.859 };
> points_intr[9] = { 11.470, 10.317 };
> points_intr[10] = { 12.730, 10.6456 };
> points_intr[11] = { 13.990, 11.0741 };
> points_intr[12] = { 15.335, 11.6928 };
> points_intr[13] = { 16.680, 12.5661 };
> points_intr[14] = { 18.3538, 14.830 };
> points_intr[15] = { 18.700, 16.056 };
>
> boost::math::catmull_rom<std::array<double, 2>>
> interpolator_cr(std::move(points_intr));
>
> auto max_s = interpolator_cr.max_parameter();
> std::array<double, 2> inter_points;
>
> for (int i = 0; i < 100; i++)
> {
> inter_points = interpolator_cr(max_s * (i / num_points));
> geometry_msgs::Point p;
> p.x = inter_points[0];
> p.y = inter_points[1];
> p.z = z;
> //p.z = inter_points[2];
> marker.points.push_back(p);
> DEBUG_INFO("spline %d: (x, y) %f, %f, current_s: %f",
> i, p.x, p.y, max_s * (i / 100.0));
> }
>
> I'm using boost 1.71.0
>
>
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>

>
> Boost-users mailing list
> Boost-users_at_[hidden]