]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/example/catmull_rom_example.cpp
1 // Copyright Nick Thompson, 2017
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).
11 #include <boost/math/interpolators/catmull_rom.hpp>
12 #include <boost/math/constants/constants.hpp>
16 using boost::math::catmull_rom
;
20 std::cout
<< "This shows how to use Boost's Catmull-Rom spline to create an Archimedean spiral.\n";
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
)
27 double theta
= ((double) i
/ (double) spiral_points
.size())*theta_max
;
28 spiral_points
[i
] = {theta
*cos(theta
), theta
*sin(theta
)};
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)
36 auto p
= archimedean(s
);
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
;