GteACosEstimate.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 // Approximations to acos(x) of the form f(x) = sqrt(1-x)*p(x)
14 // where the polynomial p(x) of degree D minimizes the quantity
15 // maximum{|acos(x)/sqrt(1-x) - p(x)| : x in [0,1]} over all
16 // polynomials of degree D.
17 
18 namespace gte
19 {
20 
21 template <typename Real>
23 {
24 public:
25  // The input constraint is x in [0,1]. For example,
26  // float x; // in [0,1]
27  // float result = ACosEstimate<float>::Degree<3>(x);
28  template <int D>
29  inline static Real Degree(Real x);
30 
31 private:
32  // Metaprogramming and private implementation to allow specialization of
33  // a template member function.
34  template <int D> struct degree {};
35  inline static Real Evaluate(degree<1>, Real x);
36  inline static Real Evaluate(degree<2>, Real x);
37  inline static Real Evaluate(degree<3>, Real x);
38  inline static Real Evaluate(degree<4>, Real x);
39  inline static Real Evaluate(degree<5>, Real x);
40  inline static Real Evaluate(degree<6>, Real x);
41  inline static Real Evaluate(degree<7>, Real x);
42  inline static Real Evaluate(degree<8>, Real x);
43 };
44 
45 
46 template <typename Real>
47 template <int D>
48 inline Real ACosEstimate<Real>::Degree(Real x)
49 {
50  return Evaluate(degree<D>(), x);
51 }
52 
53 template <typename Real>
55 {
56  Real poly;
57  poly = (Real)GTE_C_ACOS_DEG1_C1;
58  poly = (Real)GTE_C_ACOS_DEG1_C0 + poly * x;
59  poly = poly * sqrt((Real)1 - x);
60  return poly;
61 }
62 
63 template <typename Real>
65 {
66  Real poly;
67  poly = (Real)GTE_C_ACOS_DEG2_C2;
68  poly = (Real)GTE_C_ACOS_DEG2_C1 + poly * x;
69  poly = (Real)GTE_C_ACOS_DEG2_C0 + poly * x;
70  poly = poly * sqrt((Real)1 - x);
71  return poly;
72 }
73 
74 template <typename Real>
76 {
77  Real poly;
78  poly = (Real)GTE_C_ACOS_DEG3_C3;
79  poly = (Real)GTE_C_ACOS_DEG3_C2 + poly * x;
80  poly = (Real)GTE_C_ACOS_DEG3_C1 + poly * x;
81  poly = (Real)GTE_C_ACOS_DEG3_C0 + poly * x;
82  poly = poly * sqrt((Real)1 - x);
83  return poly;
84 }
85 
86 template <typename Real>
88 {
89  Real poly;
90  poly = (Real)GTE_C_ACOS_DEG4_C4;
91  poly = (Real)GTE_C_ACOS_DEG4_C3 + poly * x;
92  poly = (Real)GTE_C_ACOS_DEG4_C2 + poly * x;
93  poly = (Real)GTE_C_ACOS_DEG4_C1 + poly * x;
94  poly = (Real)GTE_C_ACOS_DEG4_C0 + poly * x;
95  poly = poly * sqrt((Real)1 - x);
96  return poly;
97 }
98 
99 template <typename Real>
101 {
102  Real poly;
103  poly = (Real)GTE_C_ACOS_DEG5_C5;
104  poly = (Real)GTE_C_ACOS_DEG5_C4 + poly * x;
105  poly = (Real)GTE_C_ACOS_DEG5_C3 + poly * x;
106  poly = (Real)GTE_C_ACOS_DEG5_C2 + poly * x;
107  poly = (Real)GTE_C_ACOS_DEG5_C1 + poly * x;
108  poly = (Real)GTE_C_ACOS_DEG5_C0 + poly * x;
109  poly = poly * sqrt((Real)1 - x);
110  return poly;
111 }
112 
113 template <typename Real>
115 {
116  Real poly;
117  poly = (Real)GTE_C_ACOS_DEG6_C6;
118  poly = (Real)GTE_C_ACOS_DEG6_C5 + poly * x;
119  poly = (Real)GTE_C_ACOS_DEG6_C4 + poly * x;
120  poly = (Real)GTE_C_ACOS_DEG6_C3 + poly * x;
121  poly = (Real)GTE_C_ACOS_DEG6_C2 + poly * x;
122  poly = (Real)GTE_C_ACOS_DEG6_C1 + poly * x;
123  poly = (Real)GTE_C_ACOS_DEG6_C0 + poly * x;
124  poly = poly * sqrt((Real)1 - x);
125  return poly;
126 }
127 
128 template <typename Real>
130 {
131  Real poly;
132  poly = (Real)GTE_C_ACOS_DEG7_C7;
133  poly = (Real)GTE_C_ACOS_DEG7_C6 + poly * x;
134  poly = (Real)GTE_C_ACOS_DEG7_C5 + poly * x;
135  poly = (Real)GTE_C_ACOS_DEG7_C4 + poly * x;
136  poly = (Real)GTE_C_ACOS_DEG7_C3 + poly * x;
137  poly = (Real)GTE_C_ACOS_DEG7_C2 + poly * x;
138  poly = (Real)GTE_C_ACOS_DEG7_C1 + poly * x;
139  poly = (Real)GTE_C_ACOS_DEG7_C0 + poly * x;
140  poly = poly * sqrt((Real)1 - x);
141  return poly;
142 }
143 
144 template <typename Real>
146 {
147  Real poly;
148  poly = (Real)GTE_C_ACOS_DEG8_C8;
149  poly = (Real)GTE_C_ACOS_DEG8_C7 + poly * x;
150  poly = (Real)GTE_C_ACOS_DEG8_C6 + poly * x;
151  poly = (Real)GTE_C_ACOS_DEG8_C5 + poly * x;
152  poly = (Real)GTE_C_ACOS_DEG8_C4 + poly * x;
153  poly = (Real)GTE_C_ACOS_DEG8_C3 + poly * x;
154  poly = (Real)GTE_C_ACOS_DEG8_C2 + poly * x;
155  poly = (Real)GTE_C_ACOS_DEG8_C1 + poly * x;
156  poly = (Real)GTE_C_ACOS_DEG8_C0 + poly * x;
157  poly = poly * sqrt((Real)1 - x);
158  return poly;
159 }
160 
161 
162 }
#define GTE_C_ACOS_DEG3_C2
Definition: GteConstants.h:282
#define GTE_C_ACOS_DEG3_C0
Definition: GteConstants.h:280
#define GTE_C_ACOS_DEG7_C4
Definition: GteConstants.h:314
#define GTE_C_ACOS_DEG2_C0
Definition: GteConstants.h:275
#define GTE_C_ACOS_DEG8_C7
Definition: GteConstants.h:327
#define GTE_C_ACOS_DEG4_C4
Definition: GteConstants.h:290
#define GTE_C_ACOS_DEG4_C0
Definition: GteConstants.h:286
#define GTE_C_ACOS_DEG6_C1
Definition: GteConstants.h:302
#define GTE_C_ACOS_DEG8_C4
Definition: GteConstants.h:324
#define GTE_C_ACOS_DEG6_C0
Definition: GteConstants.h:301
#define GTE_C_ACOS_DEG8_C6
Definition: GteConstants.h:326
static Real Evaluate(degree< 1 >, Real x)
#define GTE_C_ACOS_DEG6_C4
Definition: GteConstants.h:305
#define GTE_C_ACOS_DEG4_C2
Definition: GteConstants.h:288
#define GTE_C_ACOS_DEG5_C3
Definition: GteConstants.h:296
#define GTE_C_ACOS_DEG5_C2
Definition: GteConstants.h:295
#define GTE_C_ACOS_DEG8_C3
Definition: GteConstants.h:323
static Real Degree(Real x)
#define GTE_C_ACOS_DEG3_C3
Definition: GteConstants.h:283
#define GTE_C_ACOS_DEG4_C1
Definition: GteConstants.h:287
GLint GLenum GLint x
Definition: glcorearb.h:404
#define GTE_C_ACOS_DEG6_C5
Definition: GteConstants.h:306
#define GTE_C_ACOS_DEG8_C2
Definition: GteConstants.h:322
#define GTE_C_ACOS_DEG5_C1
Definition: GteConstants.h:294
#define GTE_C_ACOS_DEG5_C5
Definition: GteConstants.h:298
#define GTE_C_ACOS_DEG1_C0
Definition: GteConstants.h:271
#define GTE_C_ACOS_DEG6_C2
Definition: GteConstants.h:303
#define GTE_C_ACOS_DEG8_C5
Definition: GteConstants.h:325
#define GTE_C_ACOS_DEG6_C6
Definition: GteConstants.h:307
#define GTE_C_ACOS_DEG5_C4
Definition: GteConstants.h:297
#define GTE_C_ACOS_DEG7_C5
Definition: GteConstants.h:315
#define GTE_C_ACOS_DEG2_C1
Definition: GteConstants.h:276
#define GTE_C_ACOS_DEG7_C3
Definition: GteConstants.h:313
#define GTE_C_ACOS_DEG4_C3
Definition: GteConstants.h:289
#define GTE_C_ACOS_DEG8_C8
Definition: GteConstants.h:328
#define GTE_C_ACOS_DEG7_C0
Definition: GteConstants.h:310
#define GTE_C_ACOS_DEG5_C0
Definition: GteConstants.h:293
#define GTE_C_ACOS_DEG1_C1
Definition: GteConstants.h:272
#define GTE_C_ACOS_DEG2_C2
Definition: GteConstants.h:277
#define GTE_C_ACOS_DEG7_C6
Definition: GteConstants.h:316
#define GTE_C_ACOS_DEG3_C1
Definition: GteConstants.h:281
#define GTE_C_ACOS_DEG7_C1
Definition: GteConstants.h:311
#define GTE_C_ACOS_DEG6_C3
Definition: GteConstants.h:304
#define GTE_C_ACOS_DEG7_C7
Definition: GteConstants.h:317
#define GTE_C_ACOS_DEG8_C1
Definition: GteConstants.h:321
#define GTE_C_ACOS_DEG8_C0
Definition: GteConstants.h:320
#define GTE_C_ACOS_DEG7_C2
Definition: GteConstants.h:312


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