TNB Library
TnbEarthCoordinates.h
[詳解]
1#pragma once
11#include "TnbValueUnit.h"
12
13
14
15//TNB Library
16namespace TNB
17{
18
19
20
35{
36public:
37
39 CEarthCoordinates(void) : m_latitude(0.0), m_longitude(0.0)
40 {
41 }
42
49 CEarthCoordinates(const CValueDegree& latitude, const CValueDegree& longitude)
50 : m_latitude(latitude), m_longitude(longitude)
51 {
52 }
53
59 CEarthCoordinates(double latitude, double longitude)
60 : m_latitude(CValueDegree(latitude)), m_longitude(CValueDegree(longitude))
61 {
62 }
63
69 {
70 m_latitude = other.m_latitude;
71 m_longitude = other.m_longitude;
72 }
73
80 {
81 m_latitude = other.m_latitude;
82 m_longitude = other.m_longitude;
83 return *this;
84 }
85
93 {
94 const CValueDegree& lat1 = m_latitude;
95 const CValueDegree& lat2 = other.m_latitude;
96 const CValueDegree& lon1 = m_longitude;
97 const CValueDegree& lon2 = other.m_longitude;
98 CRealNumber y = cos(lat2) * sin(lon2 - lon1);
99 CRealNumber x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon2 - lon1);
100 return CValueDegree(atan2(y, x), CValueDegree::RAD);
101 }
102
110 {
111 return CValueDistance(m_CalcDirectDistance(other), CValueDistance::M);
112 }
113
121 {
122 const double er = 6378136.0; // 赤道半径(m)
123 CRealNumber r = m_CalcDirectDistance(other);
124 CRealNumber wr = asin(r / 2 / er); // 半射程角(rad)
125 return CValueDistance(er * 2 * wr, CValueDistance::M);
126 }
127
136 {
137 CValueDegree one(1.0, CValueDegree::DEG); //1°
138 CEarthCoordinates rr = *this;
139 CValueDistance cx = sin(de) * di; //移動距離(東西方向)
140 CValueDistance cy = cos(de) * di; //移動距離(南北方向)
141 //経度(たて)
142 CEarthCoordinates ecy(m_latitude + one, m_longitude);
143 CValueDistance dy = CalcDirectDistance(ecy); //経度一度の長さ
144 CRealNumber ry = cy / dy; //移動経度
145 rr.m_latitude += CValueDegree(ry, CValueDegree::DEG);
146 //緯度(横)
147 CEarthCoordinates ecx(rr.m_latitude, m_longitude + one);
148 CValueDistance dx = CalcDirectDistance(ecx); //緯度一度の長さ
149 CRealNumber rx = cx / dx; //移動緯度
150 rr.m_longitude += CValueDegree(rx, CValueDegree::DEG);
151 return rr;
152 }
153
158 const CValueDegree& GetLatitude(void) const
159 {
160 return m_latitude;
161 }
162
167 const CValueDegree& GetLongitude(void) const
168 {
169 return m_longitude;
170 }
171
178 {
179 double r = m_latitude.GetValue(CValueDegree::DEGS).ToDouble();
180 return CStr::Fmt(_T("%s %s"), (r >= 0) ? _T("北緯") : _T("南緯"), SecondToString(r));
181 }
182
189 {
190 double r = m_longitude.GetValue(CValueDegree::DEGS).ToDouble();
191 return CStr::Fmt(_T("%s %s"), (r >= 0) ? _T("東経") : _T("西経"), SecondToString(r));
192 }
193
198 CStr ToString(void) const
199 {
200 return CStr::Fmt(_T("%s / %s"), LatitudeToString(), LongitudeToString());
201 }
202
209 static CStr SecondToString(double deg)
210 {
211 int dd;
212 int mm;
213 double ss;
214 Resolution(dd, mm, ss, deg);
215 return CStr::Fmt(_T("%d度%d分%.3f秒"), dd, mm, ss);
216 }
217
226 static void Resolution(int& _dd, int& _mm, double& _ss, double deg)
227 {
228 int r = 1;
229 if ( deg < 0 )
230 {
231 deg = -deg;
232 r = -1;
233 }
234 _dd = static_cast<int>(deg / 60.0 / 60.0);
235 _mm = int(deg / 60.0) % 60;
236 _ss = deg - ((_dd * 60) + _mm) * 60;
237 _dd *= r;
238 }
239
240private:
241
247 CRealNumber m_CalcDirectDistance(const CEarthCoordinates& other) const
248 {
249 const double er = 6378136.0; // 赤道半径(m)
250 const double ecc = 0.006694470; // 地球の離心率の自乗
251 const CValueDegree& lat1 = m_latitude;
252 const CValueDegree& lat2 = other.m_latitude;
253 const CValueDegree& lon1 = m_longitude;
254 const CValueDegree& lon2 = other.m_longitude;
255 CRealNumber n1 = er / (sqrt(1.0 - ecc * sin(lat1) * sin(lat1)));//緯度補正した地球の半径(m)
256 CRealNumber x1 = n1 * cos(lat1) * cos(lon1); //2地点の直交座標値(m)
257 CRealNumber y1 = n1 * cos(lat1) * sin(lon1);
258 CRealNumber z1 = (n1 * (1.0 - ecc)) * sin(lat1);
259 CRealNumber n2 = er / (sqrt(1.0 - ecc * sin(lat2) * sin(lat2)));//緯度補正した地球の半径(m)
260 CRealNumber x2 = n2 * cos(lat2) * cos(lon2); //2地点の直交座標値(m)
261 CRealNumber y2 = n2 * cos(lat2) * sin(lon2);
262 CRealNumber z2 = (n2 * (1.0 - ecc)) * sin(lat2);
263 return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));
264 }
265
266 CValueDegree m_latitude;
267 CValueDegree m_longitude;
268 friend class CEarthCoordinatesTest;
269};
270
271
272
273}; // TNB
274
275
276/*
277 memo
278
279 2007年の磁北極は 北緯 84.1度 西経123.7度
280 マリンスタジアム
281 緯度 35度38分46.95秒(35.646375), 経度 140度1分52.928秒(140.031369)
282 東京タワー
283 緯度 35度39分31.075秒(35.658632), 経度 139度44分43.48秒(139.745411)
284 東京ドーム
285 緯度 35度42分20.045秒(35.705568), 経度 139度45分6.858秒(139.751905)
286 札幌ドーム
287 緯度 43度0分54.612秒(43.01517), 経度 141度24分35.154秒(141.409765)
288 ハワイ
289 緯度 19度32分20.703秒(19.539084), 経度 -155度40分34.57秒(-155.67627)
290 ストップホルム
291 緯度 59度19分58.037秒(59.332788), 経度 18度3分52.157秒(18.064488)
292
293
294*/
単位付値管理関係のヘッダ
地球座標(緯度,経度)管理クラス
CValueDistance CalcEarthSurfaceDistance(const CEarthCoordinates &other) const
[計算] 地表面距離.
const CValueDegree & GetLatitude(void) const
[取得] 緯度
CEarthCoordinates(const CEarthCoordinates &other)
コピーコンストラクタ.
const CValueDegree & GetLongitude(void) const
[取得] 経度
CStr LatitudeToString(void) const
[変換] 緯度文字列化
CEarthCoordinates(void)
コンストラクタ
static CStr SecondToString(double deg)
[変換] 角度(秒)文字列化
CEarthCoordinates Move(const CValueDegree &de, const CValueDistance &di) const
[計算] 座標移動.
static void Resolution(int &_dd, int &_mm, double &_ss, double deg)
[変換] 角度分解.
CValueDistance CalcDirectDistance(const CEarthCoordinates &other) const
[計算] 直距離.
CEarthCoordinates(double latitude, double longitude)
代入コンストラクタ.
CStr LongitudeToString(void) const
[変換] 経度文字列化
CEarthCoordinates & operator=(const CEarthCoordinates &other)
コピーオペレータ.
CStr ToString(void) const
[変換] 文字列化
CEarthCoordinates(const CValueDegree &latitude, const CValueDegree &longitude)
代入コンストラクタ.
CValueDegree CalcAzimuthal(const CEarthCoordinates &other) const
[計算] 方位角計算.
実数管理クラス
Definition: TnbRealNumber.h:78
double ToDouble(void) const
[取得] double型取得.
static CStrT Fmt(const TCHAR *lpszFormat,...)
[作成] 書式付き文字列作成
Definition: TnbStr.h:1206
@ RAD
ラジアン
@ DEG
角度(度)
@ DEGS
角度(秒)
CRealNumber GetValue(void) const
[取得] 値取得.
Definition: TnbValueUnit.h:454
CValueUnitT< CUnitDistance > CValueDistance
距離管理クラス
Definition: TnbValueUnit.h:979
CRealNumber sin(const CValueDegree &d)
[計算] sin (値 = sin(角度))
CValueDistance sqrt(const CValueArea &a)
[計算] 平方根 (距離 = √面積)
CRealNumber cos(const CValueDegree &d)
[計算] cos (値 = cos(角度))
CValueUnitT< CUnitDegree > CValueDegree
角度管理クラス
TNB Library
Definition: TnbDoxyTitle.txt:2