GteATanEstimate.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
11 #include <cmath>
12 
13 // Minimax polynomial approximations to atan(x). The polynomial p(x) of
14 // degree D has only odd-power terms, is required to have linear term x,
15 // and p(1) = atan(1) = pi/4. It minimizes the quantity
16 // maximum{|atan(x) - p(x)| : x in [-1,1]} over all polynomials of
17 // degree D subject to the constraints mentioned.
18 
19 namespace gte
20 {
21 
22 template <typename Real>
24 {
25 public:
26  // The input constraint is x in [-1,1]. For example,
27  // float x; // in [-1,1]
28  // float result = ATanEstimate<float>::Degree<3>(x);
29  template <int D>
30  inline static Real Degree(Real x);
31 
32  // The input x can be any real number. Range reduction is used via
33  // the identities atan(x) = pi/2 - atan(1/x) for x > 0, and
34  // atan(x) = -pi/2 - atan(1/x) for x < 0. For example,
35  // float x; // x any real number
36  // float result = ATanEstimate<float>::DegreeRR<3>(x);
37  template <int D>
38  inline static Real DegreeRR(Real x);
39 
40 private:
41  // Metaprogramming and private implementation to allow specialization of
42  // a template member function.
43  template <int D> struct degree {};
44  inline static Real Evaluate(degree<3>, Real x);
45  inline static Real Evaluate(degree<5>, Real x);
46  inline static Real Evaluate(degree<7>, Real x);
47  inline static Real Evaluate(degree<9>, Real x);
48  inline static Real Evaluate(degree<11>, Real x);
49  inline static Real Evaluate(degree<13>, Real x);
50 };
51 
52 
53 template <typename Real>
54 template <int D>
55 inline Real ATanEstimate<Real>::Degree(Real x)
56 {
57  return Evaluate(degree<D>(), x);
58 }
59 
60 template <typename Real>
61 template <int D>
63 {
64  if (std::abs(x) <= (Real)1)
65  {
66  return Degree<D>(x);
67  }
68  else if (x > (Real)1)
69  {
70  return (Real)GTE_C_HALF_PI - Degree<D>((Real)1 / x);
71  }
72  else
73  {
74  return (Real)-GTE_C_HALF_PI - Degree<D>((Real)1 / x);
75  }
76 }
77 
78 template <typename Real>
80 {
81  Real xsqr = x * x;
82  Real poly;
83  poly = (Real)GTE_C_ATAN_DEG3_C1;
84  poly = (Real)GTE_C_ATAN_DEG3_C0 + poly * xsqr;
85  poly = poly * x;
86  return poly;
87 }
88 
89 template <typename Real>
91 {
92  Real xsqr = x * x;
93  Real poly;
94  poly = (Real)GTE_C_ATAN_DEG5_C2;
95  poly = (Real)GTE_C_ATAN_DEG5_C1 + poly * xsqr;
96  poly = (Real)GTE_C_ATAN_DEG5_C0 + poly * xsqr;
97  poly = poly * x;
98  return poly;
99 }
100 
101 template <typename Real>
103 {
104  Real xsqr = x * x;
105  Real poly;
106  poly = (Real)GTE_C_ATAN_DEG7_C3;
107  poly = (Real)GTE_C_ATAN_DEG7_C2 + poly * xsqr;
108  poly = (Real)GTE_C_ATAN_DEG7_C1 + poly * xsqr;
109  poly = (Real)GTE_C_ATAN_DEG7_C0 + poly * xsqr;
110  poly = poly * x;
111  return poly;
112 }
113 
114 template <typename Real>
116 {
117  Real xsqr = x * x;
118  Real poly;
119  poly = (Real)GTE_C_ATAN_DEG9_C4;
120  poly = (Real)GTE_C_ATAN_DEG9_C3 + poly * xsqr;
121  poly = (Real)GTE_C_ATAN_DEG9_C2 + poly * xsqr;
122  poly = (Real)GTE_C_ATAN_DEG9_C1 + poly * xsqr;
123  poly = (Real)GTE_C_ATAN_DEG9_C0 + poly * xsqr;
124  poly = poly * x;
125  return poly;
126 }
127 
128 template <typename Real>
130 {
131  Real xsqr = x * x;
132  Real poly;
133  poly = (Real)GTE_C_ATAN_DEG11_C5;
134  poly = (Real)GTE_C_ATAN_DEG11_C4 + poly * xsqr;
135  poly = (Real)GTE_C_ATAN_DEG11_C3 + poly * xsqr;
136  poly = (Real)GTE_C_ATAN_DEG11_C2 + poly * xsqr;
137  poly = (Real)GTE_C_ATAN_DEG11_C1 + poly * xsqr;
138  poly = (Real)GTE_C_ATAN_DEG11_C0 + poly * xsqr;
139  poly = poly * x;
140  return poly;
141 }
142 
143 template <typename Real>
145 {
146  Real xsqr = x * x;
147  Real poly;
148  poly = (Real)GTE_C_ATAN_DEG13_C6;
149  poly = (Real)GTE_C_ATAN_DEG13_C5 + poly * xsqr;
150  poly = (Real)GTE_C_ATAN_DEG13_C4 + poly * xsqr;
151  poly = (Real)GTE_C_ATAN_DEG13_C3 + poly * xsqr;
152  poly = (Real)GTE_C_ATAN_DEG13_C2 + poly * xsqr;
153  poly = (Real)GTE_C_ATAN_DEG13_C1 + poly * xsqr;
154  poly = (Real)GTE_C_ATAN_DEG13_C0 + poly * xsqr;
155  poly = poly * x;
156  return poly;
157 }
158 
159 
160 }
#define GTE_C_ATAN_DEG11_C3
Definition: GteConstants.h:358
#define GTE_C_ATAN_DEG7_C1
Definition: GteConstants.h:343
#define GTE_C_ATAN_DEG13_C0
Definition: GteConstants.h:363
#define GTE_C_ATAN_DEG13_C6
Definition: GteConstants.h:369
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
Definition: GteBSNumber.h:966
#define GTE_C_ATAN_DEG13_C5
Definition: GteConstants.h:368
#define GTE_C_ATAN_DEG11_C0
Definition: GteConstants.h:355
#define GTE_C_ATAN_DEG11_C2
Definition: GteConstants.h:357
static Real Evaluate(degree< 3 >, Real x)
#define GTE_C_ATAN_DEG13_C4
Definition: GteConstants.h:367
#define GTE_C_ATAN_DEG5_C2
Definition: GteConstants.h:339
GLint GLenum GLint x
Definition: glcorearb.h:404
#define GTE_C_ATAN_DEG11_C4
Definition: GteConstants.h:359
#define GTE_C_ATAN_DEG11_C1
Definition: GteConstants.h:356
#define GTE_C_ATAN_DEG3_C1
Definition: GteConstants.h:334
#define GTE_C_ATAN_DEG9_C3
Definition: GteConstants.h:351
#define GTE_C_ATAN_DEG9_C2
Definition: GteConstants.h:350
static Real Degree(Real x)
#define GTE_C_ATAN_DEG9_C4
Definition: GteConstants.h:352
#define GTE_C_ATAN_DEG13_C2
Definition: GteConstants.h:365
#define GTE_C_ATAN_DEG13_C1
Definition: GteConstants.h:364
#define GTE_C_ATAN_DEG3_C0
Definition: GteConstants.h:333
#define GTE_C_ATAN_DEG7_C0
Definition: GteConstants.h:342
#define GTE_C_HALF_PI
Definition: GteConstants.h:18
#define GTE_C_ATAN_DEG13_C3
Definition: GteConstants.h:366
static Real DegreeRR(Real x)
#define GTE_C_ATAN_DEG9_C1
Definition: GteConstants.h:349
#define GTE_C_ATAN_DEG9_C0
Definition: GteConstants.h:348
#define GTE_C_ATAN_DEG5_C0
Definition: GteConstants.h:337
#define GTE_C_ATAN_DEG7_C2
Definition: GteConstants.h:344
#define GTE_C_ATAN_DEG11_C5
Definition: GteConstants.h:360
#define GTE_C_ATAN_DEG7_C3
Definition: GteConstants.h:345
#define GTE_C_ATAN_DEG5_C1
Definition: GteConstants.h:338


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59