33#include <boost/version.hpp>
37#if BOOST_VERSION < 107000
38# include <boost/math/tools/numerical_differentiation.hpp>
40# include <boost/math/differentiation/finite_difference.hpp>
46template<
class ResultType,
class F,
typename Valtype>
47inline ResultType finite_difference_derivative6(
const F f, Valtype t )
55 using rtype =
typename Valtype::real_type;
56 constexpr rtype eps = (std::numeric_limits<rtype>::epsilon)();
59 Valtype h{ std::pow( eps / rtype{168}, rtype{1} / rtype{7} ) };
61#if BOOST_VERSION < 107000
62 h = Valtype{ boost::math::tools::detail::make_xph_representable(t.Units(), h.Units()) };
64 h = Valtype{ boost::math::differentiation::detail::make_xph_representable(t.Units(), h.Units()) };
67 const auto y1 = f(t + h) - f(t - h);
68 const auto y2 = f(t - 2 * h) - f(t + 2 * h);
69 const auto y3 = f(t + 3 * h) - f(t - 3 * h);
71 return (y3 + 9
_1 * y2 + 45
_1 * y1) / (60 * h);
74template<
class ResultType,
class F,
typename Valtype>
75inline ResultType finite_difference_derivative8(
const F f, Valtype t )
83 using rtype =
typename Valtype::real_type;
85 const rtype eps = (std::numeric_limits<rtype>::epsilon)();
92 Valtype h{ std::pow( rtype{551.25f} * eps, rtype{1} / rtype{9} ) };
94#if BOOST_VERSION < 107000
95 h = Valtype{ boost::math::tools::detail::make_xph_representable(t.Units(), h.Units()) };
97 h = Valtype{ boost::math::differentiation::detail::make_xph_representable(t.Units(), h.Units()) };
100 const auto y1 = f(t + h) - f(t - h);
101 const auto y2 = f(t - 2 * h) - f(t + 2 * h);
102 const auto y3 = f(t + 3 * h) - f(t - 3 * h);
103 const auto y4 = f(t - 4 * h) - f(t + 4 * h);
105 const auto tmp1 = 3 * y4 / 8 + 4 * y3;
106 const auto tmp2 = 21 * y2 + 84 * y1;
108 return (tmp1 + tmp2) / (105 * h);
114template<
class ContainerType,
typename Valtype,
typename IteratorToPositionConverterType >
117 typename ContainerType::iterator start,
118 typename ContainerType::iterator end,
119 Valtype maxDeviation,
120 IteratorToPositionConverterType P ){
126 Valtype maxDistance = Valtype{0};
127 typename ContainerType::iterator iterMax;
128 for(
typename ContainerType::iterator iter = start + 1; iter < end; ++iter ){
131 const Valtype distance = O.
Length();
132 if( maxDistance < distance ){
133 maxDistance = distance;
138 if( maxDistance < maxDeviation )
139 data.erase( start+1, end );
constexpr Real _1(One one) noexcept
Dimensionated Values conversion functions.
Definition DimensionedValues.h:1186
auto Normalize(const Frame< Valtype, ValtypeT > &f) noexcept -> std::pair< Vector< ValtypeT >, Frame< Valtype, decltype(ValtypeT{}/ValtypeT{})> >
Outer normalizing.
Definition Frame.h:1144
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
void DouglasPeucker(ContainerType &data, typename ContainerType::iterator start, typename ContainerType::iterator end, Valtype maxDeviation, IteratorToPositionConverterType P)
Definition Numerics.h:115
Implements a Vector bundle.
Definition VectorBundle.h:42
Position< Valtype > P
Base space postion.
Definition VectorBundle.h:43
Vector< ValtypeT > T
Tangent vector or x-axis.
Definition VectorBundle.h:44
Implements a 3D - vector in cartesian coordinates.
Definition Vector.h:48
constexpr Valtype Length() const noexcept
Calculates the length of the vector.
Definition Vector.h:449