|
| 1 | +// Copyright Matt Borland, 2023 |
| 2 | +// Use, modification and distribution are subject to the |
| 3 | +// Boost Software License, Version 1.0. |
| 4 | +// (See accompanying file LICENSE_1_0.txt |
| 5 | +// or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | + |
| 7 | +#include <iostream> |
| 8 | +#include <array> |
| 9 | +#include <vector> |
| 10 | +#include <boost/math/interpolators/bezier_polynomial.hpp> |
| 11 | + |
| 12 | +using tControlPoints = std::vector<std::array<double, 3>>; |
| 13 | + |
| 14 | +void interpolateWithPoints(tControlPoints cp) |
| 15 | +{ |
| 16 | + const auto cpSize = cp.size(); |
| 17 | + auto bp = boost::math::interpolators::bezier_polynomial(std::move(cp)); |
| 18 | + |
| 19 | + // Interpolate at t = 0.5: |
| 20 | + std::array<double, 3> point = bp(0.5); |
| 21 | + std::cout << cpSize << " points, t = 0.5:\n"; |
| 22 | + |
| 23 | + for (const auto& c : point) |
| 24 | + { |
| 25 | + std::cout << " " << c << "\n"; |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | + |
| 30 | +int main(void) |
| 31 | +{ |
| 32 | + auto cp3 = tControlPoints{{0,0,0}, {1,0,0}, {0,1,0}}; |
| 33 | + interpolateWithPoints(cp3); |
| 34 | + |
| 35 | + auto cp4 = tControlPoints{{0,0,0}, {1,0,0}, {0,1,0}, {0,0,1}}; |
| 36 | + interpolateWithPoints(cp4); |
| 37 | + |
| 38 | + auto cp3b = tControlPoints{{0,0,0}, {1,0,0}, {0,1,0}}; |
| 39 | + interpolateWithPoints(cp3b); |
| 40 | + |
| 41 | + return 0; |
| 42 | +} |
0 commit comments