Yes, I just realized too. Sorry for the confusion.
So it seems it is possible to implement it in Pd! Even with only 32bit
floats.

Attached all three working implementations and I added also the
equirectangular approximation which should be faster and still accurate
for short distances.

Thank you everyone very much!




On 2015년 06월 08일 18:22, Cyrille Henry wrote:
> ahah!!
> using -118.4 better than 118.4 also gives me the expected result. (2287.26)
> 
> all confusion came that i i was using the wrong set of value...
> 
> 
> cheer
> c
> 
> 
> Le 08/06/2015 11:10, Lorenzo Sutton a écrit :
>> Hi,
>>
>> On 07/06/2015 04:48, Max wrote:
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA1
>>>
>>> Merci Cyrille,
>>>
>>> in the formula the intermediate steps are quite small fractions and it
>>> seems their precision is important.
>>> In the test case the Pd implementation is 8917.74 km off the proper
>>> result (2887.26). However I need a precision of about 1m.
>>>
>>> So I assume the haversine formula is not implementable in Pd at all?
>>> (unless double precision will be there that is)
>>
>> I had a go at immplementing it in Pd Vanilla, with a few [expr], and
>> the result seems the one expected... no?
>>
>> Lorenzo
>>
>>
>> _______________________________________________
>> Pd-list@lists.iem.at mailing list
>> UNSUBSCRIBE and account-management ->
>> http://lists.puredata.info/listinfo/pd-list
>>
> 
> _______________________________________________
> Pd-list@lists.iem.at mailing list
> UNSUBSCRIBE and account-management ->
> http://lists.puredata.info/listinfo/pd-list

#N canvas 512 304 329 363 10;
#X obj 109 112 inlet deg;
#X obj 109 231 outlet rad;
#X obj 172 177 / 45;
#X obj 172 111 loadbang;
#X obj 109 202 * 0.0174533;
#X text 93 282 rad=deg*pi/180;
#X obj 172 154 atan;
#X msg 172 133 1;
#X text 225 36 part of zexy;
#X text 63 66 convert DEGree to RADiant;
#X connect 0 0 4 0;
#X connect 2 0 4 1;
#X connect 3 0 7 0;
#X connect 4 0 1 0;
#X connect 6 0 2 0;
#X connect 7 0 6 0;
#N canvas 788 1029 1262 734 10;
#X obj 30 25 inlet;
#X obj 28 673 outlet;
#X obj 924 19 inlet;
#X obj 971 19 inlet;
#X obj 978 647 v loca.earth-rad;
#X obj 556 688 outlet;
#X obj 514 78 unpack f f;
#X msg 978 617 bang;
#X floatatom 978 676 15 0 0 0 - - -, f 15;
#X text 836 249 lat1 lon1 lat2 lon2;
#X obj 826 109 unpack f f;
#X obj 826 176 deg2rad;
#X obj 938 140 f \$1;
#X obj 997 144 f \$2;
#X obj 826 87 t l b b;
#X obj 826 636 outlet;
#X obj 826 289 expr acos(sin($f1)*sin($f3)+cos($f1)*cos($f3)*cos($f4-$f2))
;
#X obj 826 367 * 6.3728e+06;
#X text 352 17 3 implementation attempts for the haversine formula
;
#X obj 896 173 deg2rad;
#X obj 951 172 deg2rad;
#X obj 1006 173 deg2rad;
#X text 118 334 http://www.movable-type.co.uk/scripts/latlong.html
;
#X obj 28 427 atan2;
#X obj 28 406 sqrt;
#X obj 62 405 sqrt;
#X obj 28 447 * 2;
#X obj 62 384 -;
#X msg 62 362 1 \$1;
#X obj 28 339 t f f;
#X obj 28 210 sin;
#X obj 83 207 sin;
#X obj 138 206 cos;
#X obj 193 206 cos;
#X obj 28 179 / 2;
#X obj 83 182 / 2;
#X obj 28 74 unpack f f;
#X obj 28 125 - \$1;
#X obj 83 128 - \$2;
#X obj 28 98 t f f;
#X obj 28 301 expr $f1 + ($f2 * $f3 * $f4);
#X obj 28 542 * 6372.8;
#X obj 28 148 deg2rad;
#X obj 83 149 deg2rad;
#X obj 138 148 deg2rad;
#X obj 193 149 deg2rad;
#X obj 29 232 t f f;
#X obj 28 257 *;
#X obj 79 232 t f f;
#X obj 78 257 *;
#X obj 193 120 f \$1;
#X obj 83 98 t f b;
#X obj 641 213 f \$1;
#X obj 505 524 sqrt;
#X obj 556 647 * 6372.8;
#X obj 569 243 deg2rad;
#X obj 498 244 deg2rad;
#X obj 641 245 deg2rad;
#X text 577 266 ph1;
#X text 510 270 th1;
#X obj 568 214 - \$2;
#X obj 696 219 f \$1;
#X obj 696 251 deg2rad;
#X obj 572 103 t f b b, f 8;
#X text 644 273 th2;
#X text 711 276 ph2;
#X obj 502 375 sin;
#X obj 530 373 sin;
#X obj 504 408 -;
#X text 534 410 dz;
#X obj 609 357 cos;
#X obj 582 358 cos;
#X obj 587 383 *;
#X obj 647 360 cos;
#X obj 586 412 -;
#X text 620 412 dx;
#X obj 729 384 sin;
#X obj 696 385 cos;
#X obj 701 415 *;
#X text 734 419 dy;
#X obj 498 310 t f f f;
#X obj 503 431 t f f;
#X obj 502 456 *;
#X obj 585 434 t f f;
#X obj 584 459 *;
#X obj 703 437 t f f;
#X obj 702 462 *;
#X obj 502 486 +;
#X obj 504 508 +;
#X obj 505 544 / 2;
#X obj 505 571 expr asin($f1);
#X obj 510 599 * 2;
#X obj 577 285 t f f;
#X obj 641 294 t f f;
#X connect 0 0 6 0;
#X connect 0 0 14 0;
#X connect 0 0 36 0;
#X connect 2 0 12 1;
#X connect 3 0 13 1;
#X connect 4 0 8 0;
#X connect 6 0 56 0;
#X connect 6 1 63 0;
#X connect 7 0 4 0;
#X connect 10 0 11 0;
#X connect 10 1 19 0;
#X connect 11 0 16 0;
#X connect 12 0 20 0;
#X connect 13 0 21 0;
#X connect 14 0 10 0;
#X connect 14 1 12 0;
#X connect 14 2 13 0;
#X connect 16 0 17 0;
#X connect 17 0 15 0;
#X connect 19 0 16 1;
#X connect 20 0 16 2;
#X connect 21 0 16 3;
#X connect 23 0 26 0;
#X connect 24 0 23 0;
#X connect 25 0 23 1;
#X connect 26 0 41 0;
#X connect 27 0 25 0;
#X connect 28 0 27 0;
#X connect 29 0 24 0;
#X connect 29 1 28 0;
#X connect 30 0 46 0;
#X connect 31 0 48 0;
#X connect 32 0 40 2;
#X connect 33 0 40 3;
#X connect 34 0 30 0;
#X connect 35 0 31 0;
#X connect 36 0 39 0;
#X connect 36 1 51 0;
#X connect 37 0 42 0;
#X connect 38 0 43 0;
#X connect 39 0 37 0;
#X connect 39 1 44 0;
#X connect 40 0 29 0;
#X connect 41 0 1 0;
#X connect 42 0 34 0;
#X connect 43 0 35 0;
#X connect 44 0 32 0;
#X connect 45 0 33 0;
#X connect 46 0 47 0;
#X connect 46 1 47 1;
#X connect 47 0 40 0;
#X connect 48 0 49 0;
#X connect 48 1 49 1;
#X connect 49 0 40 1;
#X connect 50 0 45 0;
#X connect 51 0 38 0;
#X connect 51 1 50 0;
#X connect 52 0 57 0;
#X connect 53 0 89 0;
#X connect 54 0 5 0;
#X connect 55 0 92 0;
#X connect 56 0 80 0;
#X connect 57 0 93 0;
#X connect 60 0 55 0;
#X connect 61 0 62 0;
#X connect 63 0 60 0;
#X connect 63 1 52 0;
#X connect 63 2 61 0;
#X connect 66 0 68 0;
#X connect 67 0 68 1;
#X connect 68 0 81 0;
#X connect 70 0 72 1;
#X connect 71 0 72 0;
#X connect 72 0 74 0;
#X connect 73 0 74 1;
#X connect 74 0 83 0;
#X connect 76 0 78 1;
#X connect 77 0 78 0;
#X connect 78 0 85 0;
#X connect 80 0 66 0;
#X connect 80 1 71 0;
#X connect 80 2 77 0;
#X connect 81 0 82 0;
#X connect 81 1 82 1;
#X connect 82 0 87 0;
#X connect 83 0 84 0;
#X connect 83 1 84 1;
#X connect 84 0 87 1;
#X connect 85 0 86 0;
#X connect 85 1 86 1;
#X connect 86 0 88 1;
#X connect 87 0 88 0;
#X connect 88 0 53 0;
#X connect 89 0 90 0;
#X connect 90 0 91 0;
#X connect 91 0 54 0;
#X connect 92 0 70 0;
#X connect 92 1 76 0;
#X connect 93 0 67 0;
#X connect 93 1 73 0;
#N canvas 813 950 989 549 10;
#X text 248 209 calculates distance of two points;
#X text 66 383 http://rosettacode.org/wiki/Haversine_formula;
#X text 66 328 In this test-case \, let's calculate the distance between
Nashville International Airport at 36.12 \, -86.67 and Loas Angeles
International Airport at 33.94 \, 118.40.;
#X msg 66 162 36.12 -86.67;
#X floatatom 66 253 15 0 0 0 - - -, f 15;
#X text 66 419 The result of the test-case should be about 2887.26
km;
#X floatatom 169 254 15 0 0 0 - - -, f 15;
#X floatatom 265 254 15 0 0 0 - - -, f 15;
#X text 126 276 three implementation fails;
#X msg 469 144 36.12 -86.67;
#X floatatom 482 262 15 0 0 0 - - -, f 15;
#X obj 482 229 / 1000;
#X msg 488 168 33.9412 118.403;
#X obj 66 209 loca.haversine 33.94 -118.4;
#X obj 483 200 loca.distance 33.94 -118.4;
#X connect 3 0 13 0;
#X connect 9 0 14 0;
#X connect 11 0 10 0;
#X connect 12 0 14 0;
#X connect 13 0 4 0;
#X connect 13 1 6 0;
#X connect 13 2 7 0;
#X connect 14 0 11 0;
#N canvas 915 951 767 605 10;
#X text 69 19 Equirectangular approximation formula;
#X obj 95 74 inlet;
#X obj 95 554 outlet;
#X obj 95 101 unpack f f;
#X text 415 73 var x = (long2-long1) * Math.cos((lat1+lat2)/2) \; var
y = (lat2-lat1) \; var d = Math.sqrt(x*x + y*y) * R \;;
#X obj 143 163 f \$1;
#X obj 207 160 f \$2;
#X obj 95 199 deg2rad;
#X obj 259 199 deg2rad;
#X obj 144 199 deg2rad;
#X obj 207 200 deg2rad;
#X obj 207 313 -;
#X obj 95 345 *;
#X obj 95 305 cos;
#X obj 95 125 t f b;
#X obj 95 257 +;
#X obj 95 281 / 2;
#X obj 144 226 t f f;
#X obj 95 225 t f f;
#X obj 140 344 -;
#X obj 140 281 pack f f;
#X msg 140 312 \$2 \$1;
#X obj 207 133 t b f;
#X obj 95 451 sqrt;
#X obj 95 423 +;
#X obj 194 74 inlet;
#X obj 267 74 inlet;
#X obj 95 484 * 6.3728e+06;
#X obj 95 368 t f f;
#X obj 95 392 *;
#X obj 140 369 t f f;
#X obj 140 392 *;
#X text 166 537 distance in m;
#X connect 1 0 3 0;
#X connect 3 0 14 0;
#X connect 3 1 22 0;
#X connect 5 0 9 0;
#X connect 6 0 10 0;
#X connect 7 0 18 0;
#X connect 8 0 11 1;
#X connect 9 0 17 0;
#X connect 10 0 11 0;
#X connect 11 0 12 1;
#X connect 12 0 28 0;
#X connect 13 0 12 0;
#X connect 14 0 7 0;
#X connect 14 1 5 0;
#X connect 15 0 16 0;
#X connect 16 0 13 0;
#X connect 17 0 15 1;
#X connect 17 1 20 1;
#X connect 18 0 15 0;
#X connect 18 1 20 0;
#X connect 19 0 30 0;
#X connect 20 0 21 0;
#X connect 21 0 19 0;
#X connect 22 0 6 0;
#X connect 22 1 8 0;
#X connect 23 0 27 0;
#X connect 24 0 23 0;
#X connect 25 0 5 1;
#X connect 26 0 6 1;
#X connect 27 0 2 0;
#X connect 28 0 29 0;
#X connect 28 1 29 1;
#X connect 29 0 24 0;
#X connect 30 0 31 0;
#X connect 30 1 31 1;
#X connect 31 0 24 1;
#N canvas 917 216 760 744 10;
#X text 31 24 Equirectangular approximation formula;
#X text 79 374 distance in m;
#X text 34 132 http://rosettacode.org/wiki/Haversine_formula;
#X text 34 77 In this test-case \, let's calculate the distance between
Nashville International Airport at 36.12 \, -86.67 and Loas Angeles
International Airport at 33.94 \, 118.40.;
#X text 34 168 The result of the test-case should be about 2887.26
km;
#X msg 45 275 36.12 -86.67;
#X obj 67 346 loca.distance 33.94 118.4;
#X floatatom 66 440 15 0 0 0 - - -, f 15;
#X obj 66 407 / 1000;
#X msg 75 305 33.9412 118.403;
#X text 82 462 distance in km;
#X text 43 211 This method sucks for long distances \, but works accurately
for short ones.;
#X text 136 273 long distance;
#X text 186 305 short distance;
#X text 273 503 35.8345 \, 128.758;
#X text 275 524 35.834 \, 128.758;
#X text 394 359 distance in m;
#X floatatom 381 425 15 0 0 0 - - -, f 15;
#X obj 382 331 loca.distance 35.834 128.758;
#X msg 382 283 35.8345 128.758;
#X text 377 450 according to google maps the distance it is 59 m;
#X connect 5 0 6 0;
#X connect 6 0 8 0;
#X connect 8 0 7 0;
#X connect 9 0 6 0;
#X connect 18 0 17 0;
#X connect 19 0 18 0;
_______________________________________________
Pd-list@lists.iem.at mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list

Reply via email to