-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestbench.c
508 lines (450 loc) · 34.4 KB
/
testbench.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
/*
* Программа проверки модуля geodesy.c
*
* Таблица покрытия тестами
*
* ФУНКЦИЯ ПОКРЫТИЕ ТЕСТОВЫХ ТОЧЕК ТЕСТ
*
* geodetic2ecef ДА (для WGS-84) 100 (random) test_geodetic2ecef
* ecef2geodetic ДА (для WGS-84) 100 (random) test_ecef2geodetic
* ecef2enu ДА (для WGS-84, ТС МСК) 100 (random) test_ecef2enu
* enu2ecef ДА (для WGS-84, ТС МСК) 100 (random) test_enu2ecef
* geodetic2enu ДА (для WGS-84, ТС МСК) 100 (random) test_geodetic2enu
* enu2geodetic ДА (для WGS-84, ТС МСК) 100 (random) test_enu2geodetic
* geodetic2gk ДА 5 (города РФ) test_geodetic2gk
* gk2geodetic ДА 5 (города РФ) test_gk2geodetic
* ecef2ecef ДА (wgs84_to_pz9011) 1 (МСК) test_ecef2ecef
* ecef2ecef ДА (pz9011_to_wgs84) 1 (МСК) test_ecef2ecef
* ecef2ecef ДА (pz9011_to_pz90) 1 (МСК) test_ecef2ecef
* ecef2ecef ДА (pz90_to_pz9011) 1 (МСК) test_ecef2ecef
* ecef2ecef ДА (sk42_to_pz9011) 1 (МСК) test_ecef2ecef
* ecef2ecef ДА (pz9011_to_sk42) 1 (МСК) test_ecef2ecef
*
*/
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "geodesy.h"
#define DEG2RAD(deg) ((M_PI / 180.0) * (deg))
#define RAD2DEG(rad) ((180.0 / M_PI) * (rad))
#define MSKLAT DEG2RAD(55.7522200)
#define MSKLON DEG2RAD(37.6155600)
#define MSKALT 144
#ifdef __WIN__
uint32_t mtime()
{
return GetTickCount();
}
#else
#include <unistd.h>
#include <sys/time.h>
uint32_t mtime()
{
struct timeval tv;
if (gettimeofday(&tv, NULL) != 0 ) return 0;
return (uint32_t)tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
#endif
static __inline double sqr(double x)
{
return x * x;
}
typedef struct
{
double x, y, z;
double lat, lon, h;
double e, n, u;
} point_t;
typedef struct
{
double x, y;
double lat, lon;
} gk_geodetic_point_t;
static const gk_geodetic_point_t gk_geodetic_points[5] =
{
{6656894.141, 5654376.3340, 59.9953, 29.7667}, /* Кронштадт */
{4779853.345, 22736031.509, 43.1167, 131.900}, /* Владивосток */
{7653845.786, 6503337.9480, 68.9667, 33.0833}, /* Мурманск */
{7181830.195, 30524632.846, 64.7333, 177.517}, /* Анадырь */
{6182347.540, 7413219.3620, 55.7558, 37.6178} /* Москва */
};
/*
Код matlab для построения таблицы wgs84_points
function testbench()
fprintf(1, 'WGS-84\n');
rand('seed', 0); % Фиксируем seed (может не работать в новых matlab!)
for i = 1 : 100
oneline(referenceEllipsoid('wgs84'));
end
end
function oneline(ell)
xyz = (rand(3, 1) - 0.5) * 6370e3 * 2;
[lat, lon, h] = ecef2geodetic(ell, xyz(1), xyz(2), xyz(3));
MSKLAT = 55.7522200;
MSKLON = 37.6155600;
MSKALT = 144;
[e, n, u] = ecef2enu(xyz(1), xyz(2), xyz(3), MSKLAT, MSKLON, MSKALT, ell);
fprintf(1, ' { %+20.10f, %+20.10f, %+20.10f, ', xyz(1), xyz(2), xyz(3));
fprintf(1, '%+15.10f, %+15.10f, %+20.10f, ', lat, lon, h);
fprintf(1, '%+20.10f, %+20.10f, %+20.10f },\n', e, n, u);
end
*/
static const point_t wgs84_points[100] =
{
{ -3580459.9661801290, -5770651.5894274469, +2278736.4929023837, +18.6523716664, -121.8179574123, +787327.4922615094, -2385700.4886033875, +6558200.6025275700, -8058351.0391694177 },
{ +2284236.2103584395, +5537987.4942861442, -1484183.5327791902, -14.0081196239, +67.5854761166, -205197.3469217345, +2992565.2229918446, -5105105.0762185641, -4669973.1281206338 },
{ +247364.5801457409, +4216498.5094715366, -5929551.3118801415, -54.6957465596, +86.6425411275, +916153.7751313038, +3189007.7862661425, -5606405.2663109088, -9706497.9523588903 },
{ -5688898.7695327485, +378380.4630899716, +2180443.1531440676, +21.0630930084, +176.1947434992, -271210.7830074988, +3772002.2079034639, +4781068.2011805102, -6967356.5934800152 },
{ -6271925.1076699821, -1485284.6093826387, -5518429.8940135306, -40.7122881571, -166.6769508240, +2115982.3610282717, +2651604.6685455707, +1770380.9474046659, -14231397.1373728011 },
{ -1051228.6854075403, +2379484.3554727202, +1133562.4299960034, +23.8647599559, +113.8352875323, -3537082.4998835418, +2526474.7256117472, +145645.4237526511, -5077944.8302168092 },
{ +5483760.9428324560, +4410166.1850792198, +343072.6264478039, +2.8080520004, +38.8070381422, +667401.7528486690, +146328.0971175199, -5602735.0538403206, -2120639.2701659775 },
{ -5198367.2917486941, +1960927.5796874091, -1070168.1937184965, -10.9835290167, +159.3325265129, -719318.5337560838, +4726174.6827374836, +1832078.7314480306, -8892081.6728031896 },
{ +2563168.1732242787, +5227487.3804382449, +3340403.0255928645, +30.0029533194, +63.8801283499, +339461.2390667191, +2576361.6589640840, -2415940.3420755430, -664225.2022316181 },
{ -3026348.8607184724, -5765302.0953644542, +3007683.2096174746, +24.9233461310, -117.6960857708, +798059.8822188620, -2719670.4503422487, +6602912.8809409952, -7206942.8368906258 },
{ -2188295.9591030590, +1689815.3548873095, +3266669.5910211052, +50.0385117709, +142.3244633603, -2086002.8746707272, +2674192.1459626094, +2438587.1593949362, -4058479.6584875141 },
{ +6255816.2917037569, -1715585.3349555214, -3222724.5974506834, -26.5539488674, -15.3356773028, +869343.7391295126, -5177258.1185670849, -5024363.7427103575, -6828157.4506434100 },
{ +6147690.6463679355, +2836693.5058807451, +3227753.3376951478, +25.6158272332, +24.7697453511, +1126457.5771865211, -1505293.5787991353, -3620176.4483257774, +19362.8196941491 },
{ +1930346.6423602528, -5443981.8512340914, +1677026.3086105818, +16.2996997410, -70.4763286090, -361851.0966606271, -5490515.1848719614, +2446400.2111847601, -5986882.7232031934 },
{ +4901168.8180506090, -2895675.0234242878, -810118.6920051086, -8.1591146379, -30.5751526547, -627694.2868143246, -5285212.3360841097, -2184228.4078786811, -5843106.2476814175 },
{ +3395143.4701425689, -283697.3138403597, -3340753.7149315486, -44.6944810574, -4.7765242701, -1596020.5850866167, -2296984.2344735879, -3940111.1936313109, -7709123.9267534819 },
{ -2867686.8545346363, -1792964.1636381692, -4248698.2667067545, -51.6989652717, -147.9851369601, -934565.6500789355, +330072.4333717246, +411162.3597768946, -11769947.1359110884 },
{ -171768.5404241867, +5066141.0906892922, +5213311.2149421638, +45.9722074873, +91.9418811396, +904322.1630296754, +4117852.2138408376, +510264.3450608181, -390675.3222889661 },
{ -5598410.4670437109, +5155280.3963633627, +57621.6790394953, +0.4362470873, +137.3596667418, +1232543.3055334836, +7500668.4168330934, +1117058.4481748808, -7040929.3369395537 },
{ +207559.6168067112, -2305520.3295943891, +6199820.5071081501, +69.6466364417, -84.8556876247, +258517.9391040122, -1952943.9409377440, +4536299.8482865738, -1938239.4416676005 },
{ -76737.0333181399, -2979318.9779805574, -5214062.9192274353, -60.4234453295, -91.4754164629, -356276.1435774127, -2313152.5738692712, -1361020.7871819269, -11731268.7552690059 },
{ +5704516.5444884989, -5430436.7817940358, +9008.3876340692, +0.0658908944, -43.5899857043, +1497854.0005528834, -7783389.3080143593, -970395.3460369578, -5678561.3335631285 },
{ -1476029.0342038632, -2839977.8643296924, +5272034.2108523631, +58.9139335593, -117.4623696932, -194954.9481206248, -1348704.8514724323, +5386195.3201211374, -3639261.4354949030 },
{ +378981.7956690597, -452960.1901224629, +5618084.6117660794, +84.0437498179, -50.0815208025, -707942.7582368758, -590116.0439550357, +3161997.2453831397, -1706347.7329884546 },
{ -5731930.0474980520, +3331691.7002395219, +3442405.9256503386, +27.5740109629, +149.8326493977, +1096716.3684177157, +6137655.2514151344, +4029405.8954281793, -4928940.9220861960 },
{ +4176392.4052409786, -4772845.1148620090, -6167845.4857775224, -44.3403928940, -48.8130350773, +2479003.8241557488, -6329788.9049766790, -3777753.3551169168, -11239757.3232754599 },
{ +2400920.5371844214, +4691468.4585674983, +1650383.1439467061, +17.5155353473, +62.8983079002, -853711.6549844518, +2250797.7688230737, -2990363.3231888311, -2317662.2807345982 },
{ +3009500.3123020283, +2871748.8601998184, +6363093.3783543725, +56.9731291236, +43.6582554505, +1239032.6362057766, +437901.4184752922, +181441.8922414401, +1224151.5217007319 },
{ +4950410.0019486668, -3399097.2487577694, -2467459.8718236480, -22.4708494697, -34.4746388600, +117174.1585479984, -5714039.9842115203, -2895185.1330141770, -7364055.2279762290 },
{ -1898065.7400507787, +169106.9665640160, +1160787.0414158269, +31.8395247437, +174.9087115877, -4140980.0679357937, +1292457.6584314506, +1830661.2849212964, -6192200.5475009903 },
{ +4407805.0758027500, -1120090.9831887535, +4350845.5466203596, +43.9260006269, -14.2579503905, -73988.3369148765, -3577600.1099218763, +147429.5317214886, -1187025.2694084155 },
{ -2938897.9516033540, -1077872.5975695401, +475252.6487341393, +8.7490119569, -159.8589418779, -3211453.7954207701, +939977.9913045475, +2755515.6527509121, -7651189.7908095811 },
{ -408732.7253160687, -2710914.3871632004, -4098105.0519124162, -56.4473062338, -98.5740763680, -1432755.5029469021, -1897905.8863967827, -651024.6122338939, -10864608.6456518676 },
{ -4411607.4919801243, +912882.2900554547, +3852648.9620295586, +40.7408038621, +168.3089381300, -441298.0846706638, +3415785.9925871706, +4616124.4094891967, -4832095.2437759405 },
{ -5948895.1692166254, +438890.9761835312, -19363.2833889517, -0.1873289337, +175.7805401253, -413042.1421487201, +3978625.5145215830, +3682787.4567097621, -8880859.7222317029 },
{ +5801296.0818928173, +3163248.3725963389, +695398.2266622584, +6.0463320894, +28.6021245816, +266250.3177967798, -1035196.1669090176, -4983262.4820045810, -2116159.2644276577 },
{ +4977995.5125823598, +1590579.9717179409, +4357584.6634281725, +39.9999297333, +17.7198340524, +434988.9020539429, -1778434.4302214324, -1589743.6823317795, +3828.0620429929 },
{ -4334561.7627001191, -3659545.7008991139, +2735404.9885950075, +25.8959065251, -139.8265605867, -76218.0379629200, -253169.2237812793, +6243852.9959908109, -7291878.7997029945 },
{ -4708356.6837098245, -5210783.1110250130, -2871746.9973870311, -22.3537516143, -132.1003198660, +1212282.5562638147, -1253791.8918670136, +4115699.9734584326, -12626289.0321699698 },
{ -6331785.0838237377, -1091903.8255521578, -6027596.0551191103, -43.3098561240, -170.2156883171, +2441865.7124226177, +2999747.1485033780, +1324558.3188459333, -14543840.4681721888 },
{ +2673101.6131132380, +5578811.5941960411, -3313536.3471245095, -28.3208346243, +64.3984718195, +644348.4486575015, +2787554.9626000570, -6409833.0982338991, -5994763.7567288997 },
{ -4065386.1216341080, -2324546.3044543499, +4930261.0357386339, +46.6530200610, -150.2395190107, +433008.4424285684, +640021.5980513748, +6629259.5777997142, -4899026.1288462169 },
{ +1937227.6592288290, -4454731.3410624545, +2310350.7633322617, +25.6133224725, -66.4972380554, -995026.6875864919, -4711106.0973546188, +2299205.0751591017, -5120500.0990455570 },
{ -1454720.6746715684, -1430379.2050482607, -3299.2461199400, -0.0946370778, -135.4833906777, -4337987.9786646757, -245133.8196833739, +1692242.2960293246, -7506225.0430666506 },
{ -4490429.5378366625, +1110757.5792170861, +4402633.9015702866, +43.7759110360, +166.1061486243, +18048.3652800359, +3620637.5893619996, +4877417.8378553186, -4344640.0701579871 },
{ +1147983.6918217987, +5801908.4489680398, +715301.8058488620, +6.9453024897, +78.8078411058, -420338.8978382060, +3895146.7578502460, -3256456.5664439439, -3267723.1249893974 },
{ -4482549.0981771369, +6157306.9368523108, -1162312.3232053181, -8.7246633978, +126.0547984855, +1326677.9550421787, +7613320.1164466441, -805683.0292422888, -7207715.3009770066 },
{ -4563216.1117872298, +826809.1920282737, -3157909.5808080905, -34.4564819085, +169.7299970100, -760724.5815387052, +3440141.3167841234, +813468.6912750965, -10724254.5373859331 },
{ -146324.6415817760, -458251.0649078765, +5874352.0933223665, +85.3521777522, -107.7088586655, -462878.5830689063, -273680.8745895687, +3652846.5576413292, -1730505.6451638336 },
{ -4764367.5309859067, -3825093.2801305749, -2302759.1545752995, -20.7753116761, -141.2406090363, +153947.3685944118, -121967.0400923425, +3773462.3138758121, -11704949.4764181059 },
{ +1646889.0529483969, -4755687.0962892137, +1926972.6671916302, +21.1036410317, -70.8990883358, -986322.3292013267, -4772289.1878510192, +2425399.3035429744, -5670210.2805605959 },
{ +1549617.4897344862, +3861149.9675135822, -3212495.9992163326, -37.8990842974, +68.1326446960, -1113699.7711284598, +2112684.2235430786, -4750723.4284511320, -7002082.8622585051 },
{ -300258.8289092566, -1410137.4778804078, -3780590.7360141119, -69.3256685268, -102.0204021774, -2313274.3401164864, -933737.5490233111, -1199644.6866140133, -10106982.1374573838 },
{ -6008500.1891844440, +5117320.3770477893, -936422.9578182205, -6.8026921062, +139.5796224658, +1569860.6435537282, +7720901.8660345320, +845307.1156804794, -8058469.3727503540 },
{ -4560652.0508372467, +5700981.5783942966, -1142611.9270606954, -8.9458578608, +128.6589919029, +1011983.9113385240, +7299524.8290593689, -513225.7885386553, -7382993.0507568102 },
{ -4698658.1091064299, +4913160.2482326152, -5195707.9544503745, -37.5278402864, +133.7215709699, +2186160.7150523365, +6759706.1326172901, -2306354.7647037446, -11065462.3007882927 },
{ -4303590.4474433465, -5464650.1803280087, -1715580.7728439479, -13.9347374466, -128.2215867449, +787346.4506750153, -1701939.3125542076, +4629410.4259415055, -11577351.4773016721 },
{ -3146049.1882339348, -4648706.6477437997, +3607371.3699529739, +32.8945044401, -124.0884894405, +300557.3939263681, -1762128.1643119552, +6455421.4748054026, -6381050.2849923298 },
{ -569385.2003567786, -1917062.3963731632, -607695.8437532631, -17.2339398137, -106.5419047745, -4286172.8334217891, -1171020.8456496762, +1017952.0868282383, -7778329.0800671224 },
{ +3935954.0389040280, +5499531.8599834722, +1931970.7422153894, +16.0355568994, +54.4091210253, +656910.1273209974, +1953960.5960403229, -4244693.7598183425, -1123037.3453647560 },
{ -3627735.5859604366, +2288006.7629450965, +5209664.8182345862, +50.7142330226, +147.7604384737, +382673.0709208855, +4026610.6772610028, +4172760.7040437488, -2888583.8997736443 },
{ -3183399.9313197094, +4597354.3096367987, -366117.9343220395, -3.7746305165, +124.7003444072, -774140.8150174869, +5584695.2509913649, -421217.4376915824, -6506264.2150399620 },
{ +75877.8494810120, +1279016.2273631508, +4045733.2924733553, +72.5923132444, +86.6048976544, -2114915.1759695038, +966826.5139950992, +1601750.9770078408, -2546267.0371286105 },
{ +3259446.5996927805, -480998.9634486841, +5750421.3179649878, +60.3482394582, -8.3945940615, +265401.6023963103, -2370447.6062277243, +1364551.9504778355, -322517.3228459770 },
{ +1691091.0375607617, -772931.7162665220, +4136644.7085638745, +65.9978239883, -24.5632905933, -1825013.0109980498, -1644432.5404099622, +1630577.2408617320, -2455911.6876013987 },
{ +2407616.8330282047, +2576112.7050435692, +6206233.6672731824, +60.5442575342, +46.9363864688, +775995.0485364962, +571086.7344441875, +636423.5988155676, +724629.0035777071 },
{ +5789245.8603900140, +4475175.5749644600, -2684111.5723243505, -20.2459093064, +37.7045716108, +1418445.1114984928, +11367.7217717736, -7539176.5709436536, -4464433.4968098793 },
{ +476803.9446448926, +183897.6467092971, -5052251.7568349149, -84.2721409766, +21.0910375715, -1278935.5404993119, -145352.4777037173, -3228345.2099033096, -10264206.3419251721 },
{ -1095277.1244129522, +977369.9915070880, +4797447.2596251620, +73.1225043485, +138.2558884647, -1341562.2057431759, +1442711.8249965962, +2943832.4940892975, -2550589.6723382608 },
{ -763907.4798924417, +2926985.4477313287, +4704420.0204286808, +57.4570572369, +104.6272162857, -769917.3591089863, +2784793.9753689854, +1690864.2676735697, -1810085.4786059959 },
{ +2747283.3448542678, +3831176.9656656198, +2631261.9420798789, +29.3611609127, +54.3562227470, -974049.9722866584, +1357934.1940877729, -2231098.7090288382, -1647958.0575742277 },
{ +3079460.5365160205, -6126762.7752464088, +4918036.4336017687, +35.7863191764, -63.3147809686, +2067589.6692486797, -6732735.7916519875, +3862421.5445601530, -3030098.8775781579 },
{ +318339.5449297224, -467268.3661604617, -5539430.0588823063, -84.2162740990, -55.7342659636, -788761.2708309134, -564436.2696541436, -3070223.4665752063, -10961226.5208948348 },
{ +2719000.3650770523, -140864.1499797185, +2136231.2908779043, +38.4630287543, -2.9656899666, -2909256.8587996485, -1771151.7569711639, -487152.0426308857, -3434137.5089722807 },
{ +2319305.7849394646, -3827672.5224115294, +5307915.8294284325, +50.0369578743, -58.7870247785, +577311.3617893150, -4447603.1327069085, +3419606.2720570513, -2256962.0554208355 },
{ +4661345.2036638483, +4968837.9783084793, +559901.4306114534, +4.7274542486, +46.8288389911, +458013.2248063721, +1090835.3074621547, -5224076.4759983495, -2116126.8505297774 },
{ -4596655.7133135647, -632573.6610789661, +6234478.2458173474, +53.4925811801, -172.1643970784, +1407265.9169994611, +2304539.4630506593, +6857449.2853700686, -3476594.7348954845 },
{ -3624122.5478398246, -687661.5439437614, -2347569.0628018091, -32.7276814723, -169.2560981415, -1999497.8727233298, +1667307.3930743202, +1418705.0911029615, -10155995.0312156342 },
{ +186761.4900026288, +4860362.4741874458, -767896.3315942776, -9.0486965766, +87.7994679775, -1453421.2620056374, +3736017.5514022792, -2986733.3607644807, -5245666.7406629240 },
{ -413645.1050190464, +3906719.9448853359, -1717886.3121605879, -23.8298608729, +96.0439820088, -2086942.3547301115, +3347078.8506328296, -2647086.3723126496, -6626162.9291745052 },
{ -3675248.4830027670, +6358746.1724918084, -4413078.9301745025, -31.1269249094, +120.0271908942, +2195884.8808108075, +7280140.7018670300, -3265362.0078729726, -9465760.1149000116 },
{ +1662420.5571284606, +1482303.6580496954, -6362419.1587755540, -70.8192688186, +41.7219143424, +381934.8406348079, +159492.6568569948, -5397074.4485123390, -10372679.7337166145 },
{ -6358801.5407457948, +3482504.6854151892, +2896247.7730988748, +21.8843311254, +151.2919413493, +1431892.4479368646, +6639735.3001499362, +4056415.2320391666, -5608048.6260190634 },
{ -2303677.5272123874, -1048199.8585994351, +2324976.5192880183, +42.9268086818, -155.5339171190, -2931554.7430170788, +575769.1448223242, +3365590.4510524534, -5828821.9594100937 },
{ +2300359.6737284027, -3754963.6467383071, +4285989.2692677621, +44.4241222600, -58.5075994066, -222698.7770090941, -4378444.7392125949, +2820215.3366908692, -3085169.1873049103 },
{ +2661648.5832872102, +4187739.3081308058, -5165448.2455437295, -46.3216891202, +57.5607256122, +795646.0766489534, +1692643.8120388153, -6742700.7997855879, -8008506.4468703149 },
{ -5328662.8534638612, +3363421.8328788052, +1650745.1940703886, +14.7722971091, +147.7401111591, +137243.9885128392, +5916651.1603325717, +2741048.1561205513, -6219278.4498199383 },
{ -3645523.2589857294, -3649413.7731564296, -5337285.4401112003, -46.1419431596, -134.9694431878, +1055520.5540142311, -665705.2335234415, +1244481.9307192126, -13654214.0993926227 },
{ -1416391.9489394834, +5760514.1740993196, +5701724.0872661229, +44.0144283850, +103.8138254597, +1860112.1546450276, +5427550.4637227319, +1249750.2081099208, -303269.9766449352 },
{ -1403265.3182713618, -2940204.1867795419, +2448232.7962379120, +37.2134077903, -115.5136489753, -2295108.9413899658, -1472508.6023286111, +3799959.5466819103, -5975438.4419698622 },
{ -2751393.6294062962, +3527270.5683751353, +3616442.6809113673, +39.1613765561, +127.9554688836, -617224.4872619212, +4473376.8297804771, +2077081.4827367649, -3389218.8860340384 },
{ -987861.9226523963, -2775334.0188252432, -3898854.3958630669, -53.1666935855, -109.5928530299, -1477832.1917389855, -1595456.7431016313, -127188.5391150722, -10980201.1380831245 },
{ -6225831.2705605440, -3926164.3110570330, +6156424.0644436441, +40.0356334598, -147.7634477808, +3226371.5829929505, +689991.6345714079, +9541990.2880413961, -5398708.0863170968 },
{ -3260748.8956724983, +4073310.4323145510, -4631564.0893306416, -41.7688051750, +128.6778199668, +608109.9066988351, +5216798.3007861590, -2506652.1598887681, -10246618.4231875166 },
{ -1297649.3800932774, +1286868.7722910515, -4116544.1042960361, -66.2618163063, +135.2389922256, -1856267.5443156632, +1811393.2028480461, -2096362.9099369585, -9902901.5803095065 },
{ +4183239.0965210465, -4360504.7707867362, +6216317.3873193180, +45.9529424789, -46.1886028094, +2302137.0206380934, -6007343.2058811998, +2979196.3931227420, -858176.5007406448 },
{ -3093671.3242268520, -3393946.2807047861, -5075139.8053416703, -48.0369922152, -132.3499951533, +478111.0114129102, -800171.8390334225, +901778.2133015916, -13103762.0801428650 },
{ -3574708.3774510343, +1716300.1804641916, +2497133.0616656374, +32.4365625759, +154.3532606112, -1685893.0595110217, +3541382.5176729974, +2899943.8763510520, -5303533.1307046916 },
{ +3755367.4143764037, +2500133.4242197373, +3222460.8611280383, +35.7469283119, +33.6536656489, -826724.0008848673, -311711.7282655874, -1886907.4657055354, -1167082.3518859744 },
{ +2159692.9789379672, +1699897.0104148139, -5650945.9582348103, -64.2160855934, +38.2063272459, -76949.0246165339, +28338.2074509033, -5432062.6084389053, -9488148.6813281700 },
};
/* Предельно допустимая ошибка, метры */
#define MAX_DIST_ERROR 1e-2
/* Предельно допустимая угловая ошибка */
#define MAX_ANGLE_ERROR (360.0 * MAX_DIST_ERROR / 4e7) /* дуга 1 мм на экваторе (9e-9 градусов) */
void test_ecef2geodetic(const ellipsoid_t *ell, const char *name, const point_t *points)
{
int i;
double lat, lon, h;
double max[3];
printf("Тестируем ecef2geodetic, эллипсоид %s...\n", name);
max[0] = 0; max[1] = 0; max[2] = 0;
for (i = 0; i < 100; i++)
{
ecef2geodetic(points[i].x, points[i].y, points[i].z, &lat, &lon, &h, ell);
lat = fabs(RAD2DEG(lat) - points[i].lat);
lon = fabs(RAD2DEG(lon) - points[i].lon);
h = fabs(h - points[i].h);
if (lat > max[0]) max[0] = lat;
if (lon > max[1]) max[1] = lon;
if (h > max[2]) max[2] = h;
}
printf("Максимальная ошибка Ш: %.12f градусов [%s]\n", max[0], max[0] < MAX_ANGLE_ERROR ? "OK" : "ERROR");
printf("Максимальная ошибка Д: %.12f градусов [%s]\n", max[1], max[1] < MAX_ANGLE_ERROR ? "OK" : "ERROR");
printf("Максимальная ошибка В: %.12f метров [%s]\n", max[2], max[2] < MAX_DIST_ERROR ? "OK" : "ERROR");
}
void test_geodetic2ecef(const ellipsoid_t *ell, const char *name, const point_t *points)
{
int i;
double x, y, z;
double max[3];
printf("Тестируем geodetic2ecef, эллипсоид %s...\n", name);
max[0] = 0; max[1] = 0; max[2] = 0;
for (i = 0; i < 100; i++)
{
geodetic2ecef(DEG2RAD(points[i].lat), DEG2RAD(points[i].lon), points[i].h, &x, &y, &z, ell);
x = fabs(x - points[i].x);
y = fabs(y - points[i].y);
z = fabs(z - points[i].z);
if (x > max[0]) max[0] = x;
if (y > max[1]) max[1] = y;
if (z > max[2]) max[2] = z;
}
printf("Максимальная ошибка X: %.12f метров [%s]\n", max[0], max[0] < MAX_DIST_ERROR ? "OK" : "ERROR");
printf("Максимальная ошибка Y: %.12f метров [%s]\n", max[1], max[1] < MAX_DIST_ERROR ? "OK" : "ERROR");
printf("Максимальная ошибка Z: %.12f метров [%s]\n", max[2], max[2] < MAX_DIST_ERROR ? "OK" : "ERROR");
}
void test_ecef2enu(const ellipsoid_t *ell, const char *name, const point_t *points)
{
int i;
double e, n, u;
double max[3];
printf("Тестируем ecef2enu, эллипсоид %s...\n", name);
max[0] = 0; max[1] = 0; max[2] = 0;
for (i = 0; i < 100; i++)
{
ecef2enu(points[i].x, points[i].y, points[i].z, MSKLAT, MSKLON, MSKALT, &e, &n, &u, ell);
e = fabs(e - points[i].e);
n = fabs(n - points[i].n);
u = fabs(u - points[i].u);
if (e > max[0]) max[0] = e;
if (n > max[1]) max[1] = n;
if (u > max[2]) max[2] = u;
}
printf("Максимальная ошибка E: %.12f метров [%s]\n", max[0], max[0] < MAX_DIST_ERROR ? "OK" : "ERROR");
printf("Максимальная ошибка N: %.12f метров [%s]\n", max[1], max[1] < MAX_DIST_ERROR ? "OK" : "ERROR");
printf("Максимальная ошибка U: %.12f метров [%s]\n", max[2], max[2] < MAX_DIST_ERROR ? "OK" : "ERROR");
}
void test_enu2ecef(const ellipsoid_t *ell, const char *name, const point_t *points)
{
int i;
double x, y, z;
double max[3];
printf("Тестируем enu2ecef, эллипсоид %s...\n", name);
max[0] = 0; max[1] = 0; max[2] = 0;
for (i = 0; i < 100; i++)
{
enu2ecef(points[i].e, points[i].n, points[i].u, MSKLAT, MSKLON, MSKALT, &x, &y, &z, ell);
x = fabs(x - points[i].x);
y = fabs(y - points[i].y);
z = fabs(z - points[i].z);
if (x > max[0]) max[0] = x;
if (y > max[1]) max[1] = y;
if (z > max[2]) max[2] = z;
}
printf("Максимальная ошибка X: %.12f метров [%s]\n", max[0], max[0] < MAX_DIST_ERROR ? "OK" : "ERROR");
printf("Максимальная ошибка Y: %.12f метров [%s]\n", max[1], max[1] < MAX_DIST_ERROR ? "OK" : "ERROR");
printf("Максимальная ошибка Z: %.12f метров [%s]\n", max[2], max[2] < MAX_DIST_ERROR ? "OK" : "ERROR");
}
void test_geodetic2enu(const ellipsoid_t *ell, const char *name, const point_t *points)
{
int i;
double e, n, u;
double max[3];
printf("Тестируем geodetic2enu, эллипсоид %s...\n", name);
max[0] = 0; max[1] = 0; max[2] = 0;
for (i = 0; i < 100; i++)
{
geodetic2enu(DEG2RAD(points[i].lat), DEG2RAD(points[i].lon), points[i].h, MSKLAT, MSKLON, MSKALT, &e, &n, &u, ell);
e = fabs(e - points[i].e);
n = fabs(n - points[i].n);
u = fabs(u - points[i].u);
if (e > max[0]) max[0] = e;
if (n > max[1]) max[1] = n;
if (u > max[2]) max[2] = u;
}
printf("Максимальная ошибка E: %.12f метров [%s]\n", max[0], max[0] < MAX_DIST_ERROR ? "OK" : "ERROR");
printf("Максимальная ошибка N: %.12f метров [%s]\n", max[1], max[1] < MAX_DIST_ERROR ? "OK" : "ERROR");
printf("Максимальная ошибка U: %.12f метров [%s]\n", max[2], max[2] < MAX_DIST_ERROR ? "OK" : "ERROR");
}
void test_enu2geodetic(const ellipsoid_t *ell, const char *name, const point_t *points)
{
int i;
double lat, lon, h;
double max[3];
printf("Тестируем enu2geodetic, эллипсоид %s...\n", name);
max[0] = 0; max[1] = 0; max[2] = 0;
for (i = 0; i < 100; i++)
{
enu2geodetic(points[i].e, points[i].n, points[i].u, MSKLAT, MSKLON, MSKALT, &lat, &lon, &h, ell);
lat = fabs(RAD2DEG(lat) - points[i].lat);
lon = fabs(RAD2DEG(lon) - points[i].lon);
h = fabs(h - points[i].h);
if (lat > max[0]) max[0] = lat;
if (lon > max[1]) max[1] = lon;
if (h > max[2]) max[2] = h;
}
printf("Максимальная ошибка Ш: %.12f градусов [%s]\n", max[0], max[0] < MAX_ANGLE_ERROR ? "OK" : "ERROR");
printf("Максимальная ошибка Д: %.12f градусов [%s]\n", max[1], max[1] < MAX_ANGLE_ERROR ? "OK" : "ERROR");
printf("Максимальная ошибка В: %.12f метров [%s]\n", max[2], max[2] < MAX_DIST_ERROR ? "OK" : "ERROR");
}
void test_performance()
{
int i;
double x, y, z;
double lat, lon, h;
uint32_t t;
printf("Тестируем производительность...\n");
t = mtime();
for (i = 0; i < 1000000; i++)
geodetic2ecef(MSKLAT, MSKLON, MSKALT, &x, &y, &z, &wgs84);
t = mtime() - t;
fprintf(stderr, "1 млн вызовов geodetic2ecef за %u мс\n", (unsigned)t);
t = mtime();
for (i = 0; i < 1000000; i++)
ecef2geodetic(x, y, z, &lat, &lon, &h, &wgs84);
t = mtime() - t;
fprintf(stderr, "1 млн вызовов ecef2geodetic за %u мс\n", (unsigned)t);
t = mtime();
for (i = 0; i < 1000000; i++)
enu2geodetic(123456, 654321, 12345, MSKLAT, MSKLON, MSKALT, &lat, &lon, &h, &wgs84);
t = mtime() - t;
fprintf(stderr, "1 млн вызовов enu2geodetic за %u мс\n", (unsigned)t);
t = mtime();
for (i = 0; i < 1000000; i++)
geodetic2enu(lat, lon, h, MSKLAT, MSKLON, MSKALT, &x, &y, &z, &wgs84);
t = mtime() - t;
fprintf(stderr, "1 млн вызовов geodetic2enu за %u мс\n", (unsigned)t);
}
void test_geodetic2gk()
{
int i;
double x, y;
double max[2];
printf("Тестируем geodetic2gk...\n");
max[0] = 0; max[1] = 0;
for (i = 0; i < 5; i++)
{
int z = geodetic2gk_zone(DEG2RAD(gk_geodetic_points[i].lon));
geodetic2gk(DEG2RAD(gk_geodetic_points[i].lat), DEG2RAD(gk_geodetic_points[i].lon), z, &x, &y);
x = fabs(x - gk_geodetic_points[i].x);
y = fabs(y - gk_geodetic_points[i].y);
if (x > max[0]) max[0] = x;
if (y > max[1]) max[1] = y;
}
printf("Максимальная ошибка X: %.12f метров [%s]\n", max[0], max[0] < MAX_DIST_ERROR ? "OK" : "ERROR");
printf("Максимальная ошибка Y: %.12f метров [%s]\n", max[1], max[1] < MAX_DIST_ERROR ? "OK" : "ERROR");
}
void test_gk2geodetic()
{
int i;
double lat, lon;
double max[2];
printf("Тестируем gk2geodetic...\n");
max[0] = 0; max[1] = 0;
for (i = 0; i < 5; i++)
{
gk2geodetic(gk_geodetic_points[i].x, gk_geodetic_points[i].y, &lat, &lon);
lat = fabs(RAD2DEG(lat) - gk_geodetic_points[i].lat);
lon = fabs(RAD2DEG(lon) - gk_geodetic_points[i].lon);
if (lat > max[0]) max[0] = lat;
if (lon > max[1]) max[1] = lon;
}
printf("Максимальная ошибка Ш: %.12f градусов [%s]\n", max[0], max[0] < MAX_ANGLE_ERROR ? "OK" : "ERROR");
printf("Максимальная ошибка Д: %.12f градусов [%s]\n", max[1], max[1] < MAX_ANGLE_ERROR ? "OK" : "ERROR");
}
double get_ecef2ecef_error(const double point[3], const double test[3], const ecefconv_t *conv)
{
double dst[3];
ecef2ecef(point[0], point[1], point[2], dst + 0, dst + 1, dst + 2, conv);
dst[0] -= test[0];
dst[1] -= test[1];
dst[2] -= test[2];
return sqrt(dst[0] * dst[0] + dst[1] * dst[1] + dst[2] * dst[2]);
}
void test_ecef2ecef()
{
static const struct
{
double wgs84[3];
double pz9011[3];
double pz90[3];
double sk42[3];
} tp[1] =
/* Точки подготовлены программой "PHOTOMOD GeoCalculator (ГОСТ 32453-2017)" */
{
{
{ 2849872.803, 2195930.716, 5249085.005 },
{ 2849872.632, 2195930.804, 5249085.058 },
{ 2849876.244, 2195929.353, 5249085.960 },
{ 2849849.364, 2196061.234, 5249170.796 }
}
};
for (int i = 0; i < 1; i++)
{
double err;
printf("Тестируем ecef2ecef (точка %i из %i)...\n", i + 1, 1);
err = get_ecef2ecef_error(tp[i].wgs84, tp[i].pz9011, &wgs84_to_pz9011);
printf("Ошибка wgs84->pz9011: %.12f метров [%s]\n", err, err < MAX_DIST_ERROR ? "OK" : "ERROR");
err = get_ecef2ecef_error(tp[i].pz9011, tp[i].wgs84, &pz9011_to_wgs84);
printf("Ошибка pz9011->wgs84: %.12f метров [%s]\n", err, err < MAX_DIST_ERROR ? "OK" : "ERROR");
err = get_ecef2ecef_error(tp[i].pz9011, tp[i].pz90, &pz9011_to_pz90);
printf("Ошибка pz9011->pz90: %.12f метров [%s]\n", err, err < MAX_DIST_ERROR ? "OK" : "ERROR");
err = get_ecef2ecef_error(tp[i].pz90, tp[i].pz9011, &pz90_to_pz9011);
printf("Ошибка pz90->pz9011: %.12f метров [%s]\n", err, err < MAX_DIST_ERROR ? "OK" : "ERROR");
err = get_ecef2ecef_error(tp[i].pz9011, tp[i].sk42, &pz9011_to_sk42);
printf("Ошибка pz9011->sk42: %.12f метров [%s]\n", err, err < MAX_DIST_ERROR ? "OK" : "ERROR");
err = get_ecef2ecef_error(tp[i].sk42, tp[i].pz9011, &sk42_to_pz9011);
printf("Ошибка sk42->pz9011: %.12f метров [%s]\n", err, err < MAX_DIST_ERROR ? "OK" : "ERROR");
}
}
int main(int argc, const char **argv)
{
(void)argc;
(void)argv;
test_ecef2geodetic(&wgs84, "WGS-84", wgs84_points);
test_geodetic2ecef(&wgs84, "WGS-84", wgs84_points);
test_ecef2enu(&wgs84, "WGS-84", wgs84_points);
test_enu2ecef(&wgs84, "WGS-84", wgs84_points);
test_geodetic2enu(&wgs84, "WGS-84", wgs84_points);
test_enu2geodetic(&wgs84, "WGS-84", wgs84_points);
test_geodetic2gk();
test_gk2geodetic();
test_ecef2ecef();
test_performance();
return 0;
}