summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/math/example/catmull_rom_example.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/math/example/catmull_rom_example.cpp
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/math/example/catmull_rom_example.cpp')
-rw-r--r--src/boost/libs/math/example/catmull_rom_example.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/boost/libs/math/example/catmull_rom_example.cpp b/src/boost/libs/math/example/catmull_rom_example.cpp
new file mode 100644
index 000000000..69a497070
--- /dev/null
+++ b/src/boost/libs/math/example/catmull_rom_example.cpp
@@ -0,0 +1,45 @@
+// Copyright Nick Thompson, 2017
+
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt).
+
+#include <iostream>
+#include <vector>
+#include <array>
+#include <cmath>
+#include <boost/math/interpolators/catmull_rom.hpp>
+#include <boost/math/constants/constants.hpp>
+
+using std::sin;
+using std::cos;
+using boost::math::catmull_rom;
+
+int main()
+{
+ std::cout << "This shows how to use Boost's Catmull-Rom spline to create an Archimedean spiral.\n";
+
+ // The Archimedean spiral is given by r = a*theta. We have set a = 1.
+ std::vector<std::array<double, 2>> spiral_points(500);
+ double theta_max = boost::math::constants::pi<double>();
+ for (size_t i = 0; i < spiral_points.size(); ++i)
+ {
+ double theta = ((double) i/ (double) spiral_points.size())*theta_max;
+ spiral_points[i] = {theta*cos(theta), theta*sin(theta)};
+ }
+
+ auto archimedean = catmull_rom<std::array<double,2>>(std::move(spiral_points));
+ double max_s = archimedean.max_parameter();
+ std::cout << "Max s = " << max_s << std::endl;
+ for (double s = 0; s < max_s; s += 0.01)
+ {
+ auto p = archimedean(s);
+ double x = p[0];
+ double y = p[1];
+ double r = sqrt(x*x + y*y);
+ double theta = atan2(y/r, x/r);
+ std::cout << "r = " << r << ", theta = " << theta << ", r - theta = " << r - theta << std::endl;
+ }
+
+ return 0;
+}