mirror of
https://github.com/boostorg/math.git
synced 2026-01-19 04:22:09 +00:00
Merge branch 'develop' into complex_newton
This commit is contained in:
@@ -144,4 +144,5 @@ test-suite examples :
|
||||
[ run barycentric_interpolation_example_2.cpp : : : [ requires cxx11_smart_ptr cxx11_function_template_default_args ] ]
|
||||
[ run cubic_b_spline_example.cpp : : : [ requires cxx11_smart_ptr cxx11_hdr_random cxx11_defaulted_functions ] ]
|
||||
[ compile naive_monte_carlo_example.cpp : [ requires cxx11_auto_declarations cxx11_lambdas cxx11_unified_initialization_syntax cxx11_hdr_thread cxx11_hdr_atomic cxx11_decltype cxx11_hdr_future cxx11_hdr_chrono cxx11_hdr_random cxx11_allocator ] ] # requires user input, can't run it, take a long time too!
|
||||
[ run catmull_rom_example.cpp : : : [ requires cxx17_if_constexpr cxx11_auto_declarations ] ] # Actually the C++17 features used is std::size, not if constexpr; looks like there isn't yet a test for it.
|
||||
;
|
||||
|
||||
44
example/catmull_rom_example.cpp
Normal file
44
example/catmull_rom_example.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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>
|
||||
|
||||
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 = M_PI;
|
||||
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;
|
||||
}
|
||||
@@ -45,7 +45,7 @@ for this purpose, and here we use `float` precision where `max_digits10` = 9
|
||||
to avoid displaying a distracting number of decimal digits.
|
||||
|
||||
[note Older compilers can use this formula to calculate `max_digits10`
|
||||
from `std::numeric_limits<FPT>::digits10`:[br]
|
||||
from `std::numeric_limits<FPT>::digits10`:
|
||||
__spaces `int max_digits10 = 2 + std::numeric_limits<FPT>::digits10 * 3010/10000;`
|
||||
] [/note]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user