Marble

MarbleMath.h
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2007 Torsten Rahn <[email protected]>
9 // Copyright 2007 Inge Wallin <[email protected]>
10 //
11 
12 #ifndef MARBLE_MARBLEMATH_H
13 #define MARBLE_MARBLEMATH_H
14 
15 #include <QtGlobal>
16 
17 #include <cmath>
18 
19 
20 namespace
21 {
22  const qreal a1 = 1.0/6.0;
23  const qreal a2 = 1.0/24.0;
24  const qreal a3 = 61.0/5040;
25  const qreal a4 = 277.0/72576.0;
26  const qreal a5 = 50521.0/39916800.0;
27  const qreal a6 = 41581.0/95800320.0;
28  const qreal a7 = 199360981.0/1307674368000.0;
29  const qreal a8 = 228135437.0/4184557977600.0;
30  const qreal a9 = 2404879675441.0/121645100408832000.0;
31  const qreal a10 = 14814847529501.0/2043637686868377600.0;
32  const qreal a11 = 69348874393137901.0/25852016738884976640000.0;
33  const qreal a12 = 238685140977801337.0/238634000666630553600000.0;
34  const qreal a13 = 4087072509293123892361.0/10888869450418352160768000000.0;
35  const qreal a14 = 454540704683713199807.0/3209350995912777478963200000.0;
36  const qreal a15 = 441543893249023104553682821.0/8222838654177922817725562880000000.0;
37  const qreal a16 = 2088463430347521052196056349.0/102156677868375135241390522368000000.0;
38 }
39 
40 namespace Marble
41 {
42 
51 inline qreal distanceSphere( qreal lon1, qreal lat1, qreal lon2, qreal lat2 ) {
52 
53  qreal h1 = sin( 0.5 * ( lat2 - lat1 ) );
54  qreal h2 = sin( 0.5 * ( lon2 - lon1 ) );
55  qreal d = h1 * h1 + cos( lat1 ) * cos( lat2 ) * h2 * h2;
56 
57  return 2.0 * atan2( sqrt( d ), sqrt( 1.0 - d ) );
58 }
59 
60 
67 inline qreal distanceSphereApprox( qreal lon1, qreal lat1, qreal lon2, qreal lat2 ) {
68  return acos( sin( lat1 ) * sin( lat2 ) + cos( lat1 ) * cos( lat2 ) * cos( lon1 - lon2 ) );
69 }
70 
71 
78 inline qreal gdInv( qreal x ) {
79  const qreal x2 = x * x;
80  return x
81  + x * x2 * ( a1
82  + x2 * ( a2 + x2 * ( a3 + x2 * ( a4 + x2 * ( a5
83  + x2 * ( a6 + x2 * ( a7 + x2 * ( a8 + x2 * ( a9
84  + x2 * ( a10 + x2 * ( a11 + x2 * ( a12 + x2 * ( a13
85  + x2 * ( a14 + x2 * ( a15 + x2 * ( a16 ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) );
86 }
87 
88 }
89 
96 inline qreal gd( qreal x ) {
97 
98  /*
99  const qreal x2 = x * x;
100  return x
101  - x * x2 * ( a1
102  - x2 * ( a2 - x2 * ( a3 - x2 * ( a4 - x2 * ( a5
103  - x2 * ( a6 - x2 * ( a7 - x2 * ( a8 - x2 * ( a9
104  - x2 * ( a10 - x2 * ( a11 - x2 * ( a12 - x2 * ( a13
105  - x2 * ( a14 - x2 * ( a15 - x2 * ( a16 ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) );
106  */
107 
108  return atan ( sinh ( x ) );
109 }
110 
111 #endif
qreal gdInv(qreal x)
This method is a fast Mac Laurin power series approximation of the.
Definition: MarbleMath.h:78
Binds a QML item to a specific geodetic location in screen coordinates.
qreal distanceSphere(qreal lon1, qreal lat1, qreal lon2, qreal lat2)
This method calculates the shortest distance between two points on a sphere.
Definition: MarbleMath.h:51
qreal distanceSphereApprox(qreal lon1, qreal lat1, qreal lon2, qreal lat2)
This method roughly calculates the shortest distance between two points on a sphere.
Definition: MarbleMath.h:67
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Sep 23 2020 23:20:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.