1 /***************************************************************************
2 geolocation.cpp - K Desktop Planetarium
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 ***************************************************************************/
11 /***************************************************************************
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. *
18 ***************************************************************************/
22 #include "geolocation.h"
23 #include "timezonerule.h"
25 GeoLocation::GeoLocation(){
26 GeoLocation( 0.0, 0.0 );
30 GeoLocation::GeoLocation( const GeoLocation
&g
) {
31 Longitude
= g
.Longitude
;
32 Latitude
= g
.Latitude
;
34 Province
= g
.Province
;
36 TimeZone
= g
.TimeZone
;
39 indexEllipsoid
= g
.indexEllipsoid
;
40 setEllipsoid ( indexEllipsoid
);
44 GeoLocation::GeoLocation( GeoLocation
*g
) {
45 Longitude
= g
->Longitude
;
46 Latitude
= g
->Latitude
;
48 Province
= g
->Province
;
50 TimeZone
= g
->TimeZone
;
53 indexEllipsoid
= g
->indexEllipsoid
;
54 setEllipsoid ( indexEllipsoid
);
58 GeoLocation::GeoLocation( dms lng
, dms lat
,
59 QString name
, QString province
, QString country
, double tz
, TimeZoneRule
*tzrule
, int iEllips
, double hght
) {
68 indexEllipsoid
= iEllips
;
69 setEllipsoid ( indexEllipsoid
);
73 GeoLocation::GeoLocation( double lng
, double lat
,
74 QString name
, QString province
, QString country
, double tz
, TimeZoneRule
*tzrule
, int iEllips
, double hght
) {
83 indexEllipsoid
= iEllips
;
84 setEllipsoid ( indexEllipsoid
);
88 GeoLocation::GeoLocation( double x
, double y
, double z
, QString name
, QString province
, QString country
, double TZ
, TimeZoneRule
*tzrule
, int iEllips
) {
97 indexEllipsoid
= iEllips
;
98 setEllipsoid ( indexEllipsoid
);
102 QString
GeoLocation::fullName() const {
104 if ( province().isEmpty() ) {
105 s
= translatedName() + ", " + translatedCountry();
107 s
= translatedName() + ", " + translatedProvince() + ", " + translatedCountry();
113 void GeoLocation::reset( GeoLocation
*g
) {
114 indexEllipsoid
= g
->ellipsoid();
115 setEllipsoid ( indexEllipsoid
);
116 setLong( g
->lng()->Degrees() );
117 setLat( g
->lat()->Degrees() );
119 Province
= g
->province();
120 Country
= g
->country();
122 TZrule
= g
->tzrule();
123 Height
= g
->height();
127 void GeoLocation::setEllipsoid(int index
) {
128 static const double A
[] = { 6378140.0, 6378137.0, 6378137.0, 6378137.0, 6378136.0 };
129 static const double F
[] = { 0.0033528131779, 0.0033528106812, 0.0033528131779, 0.00335281066474, 0.0033528131779 };
132 flattening
= F
[index
];
135 void GeoLocation::changeEllipsoid(int index
) {
142 void GeoLocation::cartToGeod(void)
144 static const double RIT
= 2.7778e-6;
145 double e2
, rpro
, lat1
, xn
, s1
, sqrtP2
, latd
, sinl
;
147 e2
= 2*flattening
-flattening
*flattening
;
149 sqrtP2
= sqrt(PosCartX
*PosCartX
+PosCartY
*PosCartY
);
151 rpro
= PosCartZ
/sqrtP2
;
152 latd
= atan(rpro
/(1-e2
));
155 while ( fabs( latd
-lat1
) > RIT
) {
158 xn
= axis
/(sqrt(1-e2
*s1
*s1
));
159 latd
= atan( rpro
*(1+e2
*xn
*s1
/PosCartZ
) );
163 xn
= axis
/( sqrt(1-e2
*sinl
*sinl
) );
165 Height
= sqrtP2
/cos(latd
)-xn
;
166 Longitude
.setRadians( atan2(PosCartY
,PosCartX
) );
167 Latitude
.setRadians(latd
);
170 void GeoLocation::geodToCart (void) {
172 double sinLong
, cosLong
, sinLat
, cosLat
;
174 e2
= 2*flattening
-flattening
*flattening
;
176 Longitude
.SinCos(sinLong
,cosLong
);
177 Latitude
.SinCos(sinLat
,cosLat
);
179 xn
= axis
/( sqrt(1-e2
*sinLat
*sinLat
) );
180 PosCartX
= (xn
+Height
)*cosLat
*cosLong
;
181 PosCartY
= (xn
+Height
)*cosLat
*sinLong
;
182 PosCartZ
= (xn
*(1-e2
)+Height
)*sinLat
;
185 void GeoLocation::TopocentricVelocity(double vtopo
[], dms gst
) {
187 double Wearth
= 7.29211510e-5; // rads/s
190 dms time
= GSTtoLST(gst
);
191 // angularVEarth.setRadians(time.Hours()*Wearth*3600.);
193 // angularVEarth.SinCos(se,ce);
196 double d0
= sqrt(PosCartX
*PosCartX
+PosCartY
*PosCartY
);
198 vtopo
[0] = - d0
* Wearth
* se
/1000.;
199 vtopo
[1] = d0
* Wearth
* ce
/1000.;