]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/example/catmull_rom_example.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / math / example / catmull_rom_example.cpp
1 // Copyright Nick Thompson, 2017
2
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or
5 // copy at http://www.boost.org/LICENSE_1_0.txt).
6
7 #include <iostream>
8 #include <vector>
9 #include <array>
10 #include <cmath>
11 #include <boost/math/interpolators/catmull_rom.hpp>
12 #include <boost/math/constants/constants.hpp>
13
14 using std::sin;
15 using std::cos;
16 using boost::math::catmull_rom;
17
18 int main()
19 {
20 std::cout << "This shows how to use Boost's Catmull-Rom spline to create an Archimedean spiral.\n";
21
22 // The Archimedean spiral is given by r = a*theta. We have set a = 1.
23 std::vector<std::array<double, 2>> spiral_points(500);
24 double theta_max = boost::math::constants::pi<double>();
25 for (size_t i = 0; i < spiral_points.size(); ++i)
26 {
27 double theta = ((double) i/ (double) spiral_points.size())*theta_max;
28 spiral_points[i] = {theta*cos(theta), theta*sin(theta)};
29 }
30
31 auto archimedean = catmull_rom<std::array<double,2>>(std::move(spiral_points));
32 double max_s = archimedean.max_parameter();
33 std::cout << "Max s = " << max_s << std::endl;
34 for (double s = 0; s < max_s; s += 0.01)
35 {
36 auto p = archimedean(s);
37 double x = p[0];
38 double y = p[1];
39 double r = sqrt(x*x + y*y);
40 double theta = atan2(y/r, x/r);
41 std::cout << "r = " << r << ", theta = " << theta << ", r - theta = " << r - theta << std::endl;
42 }
43
44 return 0;
45 }