[PD] haversine formula in Pd

Lorenzo Sutton lorenzofsutton at gmail.com
Mon Jun 8 11:10:08 CEST 2015


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
-------------- next part --------------
#N canvas 314 73 858 610 10;
#X floatatom 168 116 5 0 0 0 - - -, f 5;
#X floatatom 270 115 5 0 0 0 - - -, f 5;
#X floatatom 493 119 8 0 0 0 - - -, f 8;
#X floatatom 576 119 8 0 0 0 - - -, f 8;
#X msg -93 179 6372.8;
#X text 179 91 lat1;
#X obj 168 146 -;
#N canvas 0 50 450 300 dec2rad 0;
#X obj 127 32 inlet dec;
#X obj 155 61 r \$0-pi;
#X obj 127 118 *;
#X obj 155 86 / 180;
#X obj 127 144 outlet;
#X connect 0 0 2 0;
#X connect 1 0 3 0;
#X connect 2 0 4 0;
#X connect 3 0 2 1;
#X restore 168 171 pd dec2rad;
#X obj 670 170 atan;
#X floatatom 670 222 10 0 0 0 - - -, f 10;
#X msg 670 143 1;
#X obj 670 197 * 4;
#X obj 670 115 loadbang;
#X obj 670 245 s \$0-pi;
#X text 284 93 lat2;
#X obj 493 150 -;
#N canvas 0 50 450 300 dec2rad 0;
#X obj 127 32 inlet dec;
#X obj 155 61 r \$0-pi;
#X obj 127 118 *;
#X obj 155 86 / 180;
#X obj 127 144 outlet;
#X connect 0 0 2 0;
#X connect 1 0 3 0;
#X connect 2 0 4 0;
#X connect 3 0 2 1;
#X restore 493 175 pd dec2rad;
#X text 499 95 lon2;
#X text 582 102 lon1;
#X text 227 194 dLat;
#N canvas 0 50 450 300 dec2rad 0;
#X obj 127 32 inlet dec;
#X obj 155 61 r \$0-pi;
#X obj 127 118 *;
#X obj 155 86 / 180;
#X obj 127 144 outlet;
#X connect 0 0 2 0;
#X connect 1 0 3 0;
#X connect 2 0 4 0;
#X connect 3 0 2 1;
#X restore 53 171 pd dec2rad;
#N canvas 0 50 450 300 dec2rad 0;
#X obj 127 32 inlet dec;
#X obj 155 61 r \$0-pi;
#X obj 127 118 *;
#X obj 155 86 / 180;
#X obj 127 144 outlet;
#X connect 0 0 2 0;
#X connect 1 0 3 0;
#X connect 2 0 4 0;
#X connect 3 0 2 1;
#X restore 270 170 pd dec2rad;
#X floatatom 493 201 5 0 0 0 - - -, f 5;
#X text 540 198 dLon;
#X obj 168 267 * 0.5;
#X obj 168 289 sin;
#X obj 168 323 expr pow($f1 \, 2);
#X obj 493 263 * 0.5;
#X obj 493 286 sin;
#X obj 493 323 expr pow($f1 \, 2);
#X obj 286 389 +;
#X obj 318 323 expr cos($f1)*cos($f2);
#X obj 475 352 *;
#X obj 286 452 expr 2*asin(sqrt($f1));
#X obj -92 510 *;
#X floatatom -92 532 10 0 0 0 - - -, f 10;
#X obj 132 92 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X obj 241 91 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X obj 463 89 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X obj 554 95 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X floatatom 316 197 5 0 0 0 - - -, f 5;
#X msg 168 69 36.12;
#X msg 576 71 -86.67;
#X msg 270 68 33.94;
#X msg 493 71 -118.4;
#X obj -93 25 t b b b b b;
#X text -66 161 R;
#X text 458 452 <-- c;
#X floatatom 168 194 8 0 0 0 - - -, f 8;
#X floatatom 38 200 5 0 0 0 - - -, f 5;
#X text -3 154 lat1 = radians(lat1);
#X text 277 149 lat2 = radians(lat2);
#X text 356 422 <-- a;
#X floatatom 286 423 8 0 0 0 - - -, f 8;
#X obj -93 86 del 1;
#X text 519 452 c = 2*asin(sqrt(a));
#X obj -93 -19 bng 15 250 50 0 empty empty empty 17 7 0 10 -257985
-1 -1;
#X obj -93 1 t b b;
#X text -72 -22 <- test;
#X text 152 305 a = sin(dLat/2)**2 + cos(lat1)*cos(lat2) * sin(dLon/2)**2
, f 81;
#X connect 0 0 6 0;
#X connect 0 0 20 0;
#X connect 1 0 6 1;
#X connect 1 0 21 0;
#X connect 2 0 15 0;
#X connect 3 0 15 1;
#X connect 4 0 34 0;
#X connect 6 0 7 0;
#X connect 7 0 48 0;
#X connect 8 0 11 0;
#X connect 9 0 13 0;
#X connect 10 0 8 0;
#X connect 11 0 9 0;
#X connect 12 0 10 0;
#X connect 15 0 16 0;
#X connect 16 0 22 0;
#X connect 20 0 31 0;
#X connect 20 0 49 0;
#X connect 21 0 31 1;
#X connect 21 0 40 0;
#X connect 22 0 27 0;
#X connect 24 0 25 0;
#X connect 25 0 26 0;
#X connect 26 0 30 0;
#X connect 27 0 28 0;
#X connect 28 0 29 0;
#X connect 29 0 32 1;
#X connect 30 0 53 0;
#X connect 31 0 32 0;
#X connect 32 0 30 1;
#X connect 33 0 34 1;
#X connect 34 0 35 0;
#X connect 36 0 0 0;
#X connect 37 0 1 0;
#X connect 38 0 2 0;
#X connect 39 0 3 0;
#X connect 41 0 0 0;
#X connect 42 0 3 0;
#X connect 43 0 1 0;
#X connect 44 0 2 0;
#X connect 45 0 54 0;
#X connect 45 1 41 0;
#X connect 45 2 43 0;
#X connect 45 3 44 0;
#X connect 45 4 42 0;
#X connect 48 0 24 0;
#X connect 53 0 33 0;
#X connect 54 0 4 0;
#X connect 56 0 57 0;
#X connect 57 0 45 0;
#X connect 57 1 45 0;


More information about the Pd-list mailing list