• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
geolocation.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  geolocation.cpp - K Desktop Planetarium
3  -------------------
4  begin : Sun Feb 11 2001
5  copyright : (C) 2001-2005 by Jason Harris
6  email : jharris@30doradus.org
7  copyright : (C) 2003-2005 by Pablo de Vicente
8  email : p.devicente@wanadoo.es
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  ***************************************************************************/
19 
20 #include "geolocation.h"
21 #include "timezonerule.h"
22 
23 
24 GeoLocation::GeoLocation( dms lng, dms lat,
25  const QString &name, const QString &province, const QString &country, double tz, TimeZoneRule *tzrule, int iEllips, double hght ) {
26  Longitude = lng;
27  Latitude = lat;
28  Name = name;
29  Province = province;
30  Country = country;
31  TimeZone = tz;
32  TZrule = tzrule;
33  Height = hght;
34  indexEllipsoid = iEllips;
35  setEllipsoid ( indexEllipsoid );
36  geodToCart();
37 }
38 
39 GeoLocation::GeoLocation( double x, double y, double z,
40  const QString &name, const QString &province,
41  const QString &country, double TZ,
42  TimeZoneRule *tzrule, int iEllips ) {
43  PosCartX = x;
44  PosCartY = y;
45  PosCartZ = z;
46  Name = name;
47  Province = province;
48  Country = country;
49  TimeZone = TZ;
50  TZrule = tzrule;
51  indexEllipsoid = iEllips;
52  setEllipsoid ( indexEllipsoid );
53  cartToGeod();
54 }
55 
56 QString GeoLocation::fullName() const {
57  if ( province().isEmpty() ) {
58  return QString("%1, %2").arg(translatedName(), translatedCountry());
59  } else {
60  return QString("%1, %2, %3").arg(translatedName(), translatedProvince(), translatedCountry());
61  }
62 }
63 
64 void GeoLocation::setEllipsoid(int i) {
65  static const double A[] = { 6378140.0, 6378137.0, 6378137.0, 6378137.0, 6378136.0 };
66  static const double F[] = { 0.0033528131779, 0.0033528106812, 0.0033528131779, 0.00335281066474, 0.0033528131779 };
67 
68  Q_ASSERT(i >= 0 && i < sizeof(A)/sizeof(A[0]) && "Index must be in bounds");
69  axis = A[i];
70  flattening = F[i];
71 }
72 
73 void GeoLocation::changeEllipsoid(int index) {
74  setEllipsoid(index);
75  cartToGeod();
76 }
77 
78 QString GeoLocation::translatedName() const {
79  QString context;
80  if( province().isEmpty() ) {
81  context = QString("City in %1").arg(country());
82  } else {
83  context = QString("City in %1 %2").arg(province(), country());
84  }
85  return Name.isEmpty() ? QString() : i18nc(context.toUtf8().data(), Name.toUtf8().data());
86 }
87 
88 QString GeoLocation::translatedProvince() const {
89  return Province.isEmpty() ? QString() : i18nc(QString("Region/state in " + country()).toUtf8().data(), Province.toUtf8().data());
90 }
91 
92 QString GeoLocation::translatedCountry() const {
93  return Country.isEmpty() ? QString() : i18nc("Country name", Country.toUtf8().data());
94 }
95 
96 void GeoLocation::cartToGeod()
97 {
98  static const double RIT = 2.7778e-6;
99  double e2, rpro, lat1, xn, s1, sqrtP2, latd, sinl;
100 
101  e2 = 2*flattening-flattening*flattening;
102 
103  sqrtP2 = sqrt(PosCartX*PosCartX+PosCartY*PosCartY);
104 
105  rpro = PosCartZ/sqrtP2;
106  latd = atan2(rpro, (1-e2));
107  lat1 = 0.;
108 
109  while ( fabs( latd-lat1 ) > RIT ) {
110  lat1 = latd;
111  s1 = sin(lat1);
112  xn = axis/(sqrt(1-e2*s1*s1));
113  latd = atan2( (long double)rpro*(1+e2*xn*s1), PosCartZ );
114  }
115 
116  sinl = sin(latd);
117  xn = axis/( sqrt(1-e2*sinl*sinl) );
118 
119  Height = sqrtP2/cos(latd)-xn;
120  Longitude.setRadians( atan2(PosCartY,PosCartX) );
121  Latitude.setRadians(latd);
122 }
123 
124 void GeoLocation::geodToCart() {
125  double e2, xn;
126  double sinLong, cosLong, sinLat, cosLat;
127 
128  e2 = 2*flattening-flattening*flattening;
129 
130  Longitude.SinCos(sinLong,cosLong);
131  Latitude.SinCos(sinLat,cosLat);
132 
133  xn = axis/( sqrt(1-e2*sinLat*sinLat) );
134  PosCartX = (xn+Height)*cosLat*cosLong;
135  PosCartY = (xn+Height)*cosLat*sinLong;
136  PosCartZ = (xn*(1-e2)+Height)*sinLat;
137 }
138 
139 void GeoLocation::TopocentricVelocity(double vtopo[], dms gst) {
140 
141  double Wearth = 7.29211510e-5; // rads/s
142  dms angularVEarth;
143 
144  dms time= GSTtoLST(gst);
145  // angularVEarth.setRadians(time.Hours()*Wearth*3600.);
146  double se, ce;
147  // angularVEarth.SinCos(se,ce);
148  time.SinCos(se,ce);
149 
150  double d0 = sqrt(PosCartX*PosCartX+PosCartY*PosCartY);
151  // km/s
152  vtopo[0] = - d0 * Wearth * se /1000.;
153  vtopo[1] = d0 * Wearth * ce /1000.;
154  vtopo[2] = 0.;
155 }
156 
157 double GeoLocation::LMST( double jd )
158 {
159  int divresult;
160  double ut, tu, gmst, theta;
161 
162  ut = ( jd + 0.5 ) - floor( jd + 0.5 );
163  jd -= ut;
164  tu = ( jd - 2451545. ) / 36525.;
165 
166  gmst = 24110.54841 + tu * ( 8640184.812866 + tu * ( 0.093104 - tu * 6.2e-6 ) );
167  divresult = (int)( ( gmst + 8.6400e4 * 1.00273790934 * ut ) / 8.6400e4 );
168  gmst = ( gmst + 8.6400e4 * 1.00273790934 * ut ) - (double)divresult * 8.6400e4;
169  theta = 2. * dms::PI * gmst / (24. * 60. * 60.);
170  divresult = (int)( ( theta + Longitude.radians() ) / ( 2. * dms::PI ) );
171  return( ( theta + Longitude.radians() ) - (double)divresult * 2. * dms::PI );
172 }
GeoLocation::translatedName
QString translatedName() const
Definition: geolocation.cpp:78
GeoLocation::TopocentricVelocity
void TopocentricVelocity(double vtopo[], dms gt)
Computes the velocity in km/s of an observer on the surface of the Earth referred to a system whose o...
Definition: geolocation.cpp:139
GeoLocation::lng
const dms * lng() const
Definition: geolocation.h:76
GeoLocation::changeEllipsoid
void changeEllipsoid(int i)
Update Latitude, Longitude and Height according to new ellipsoid.
Definition: geolocation.cpp:73
GeoLocation::tzrule
TimeZoneRule * tzrule()
Definition: geolocation.h:124
TimeZoneRule
This class provides the information needed to determine whether Daylight Savings Time (DST; a...
Definition: timezonerule.h:56
geolocation.h
GeoLocation::LMST
double LMST(double jd)
Local Mean Sidereal Time.
Definition: geolocation.cpp:157
GeoLocation::geodToCart
void geodToCart()
Converts from longitude, latitude and height on a standard geoid of the Earth to cartesian coordinate...
Definition: geolocation.cpp:124
GeoLocation::GeoLocation
GeoLocation(dms lng, dms lat, const QString &name="Nowhere", const QString &province="Nowhere", const QString &country="Nowhere", double TZ=0, TimeZoneRule *TZrule=NULL, int iEllips=4, double hght=-10)
Constructor using dms objects to specify longitude and latitude.
Definition: geolocation.cpp:24
GeoLocation::translatedProvince
QString translatedProvince() const
Definition: geolocation.cpp:88
F
#define F
Definition: satellite.cpp:58
timezonerule.h
GeoLocation::GSTtoLST
dms GSTtoLST(const dms &gst) const
Definition: geolocation.h:230
i18nc
i18nc("string from libindi, used in the config dialog","100x")
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
GeoLocation::province
QString province() const
Definition: geolocation.h:103
GeoLocation::name
QString name() const
Definition: geolocation.h:97
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
GeoLocation::setEllipsoid
void setEllipsoid(int i)
The geoid is an elliposid which fits the shape of the Earth.
Definition: geolocation.cpp:64
PI
#define PI
Definition: satellite.cpp:43
GeoLocation::cartToGeod
void cartToGeod()
Converts from cartesian coordinates in meters to longitude, latitude and height on a standard geoid f...
Definition: geolocation.cpp:96
GeoLocation::TZ
double TZ() const
Definition: geolocation.h:121
GeoLocation::fullName
QString fullName() const
Definition: geolocation.cpp:56
GeoLocation::translatedCountry
QString translatedCountry() const
Definition: geolocation.cpp:92
GeoLocation::country
QString country() const
Definition: geolocation.h:109
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal