# calculate the distance between the waypoint in APM 2.22 coding

hi,

after I learned coding in apm 2.22.i find that formula to calculate the distance between waypoint  is:

if(loc1->lat == 0 || loc1->lng == 0)

return -1;

if(loc2->lat == 0 || loc2->lng == 0)

return -1;

float dlat = (float)(loc2->lat - loc1->lat);

float dlong= ((float)(loc2->lng - loc1->lng)) * scaleLongDown;

wp_distance= (sqrt [ (latitude2-latitude1)^2 + (longitude2-longitude1)^2 ) ] ) * 0.01113195;

my question is:

function "scaleLongDown" is used for what, and how its value?

Where the value " 0.01113195" obtained from ? and what it use for?

what units used for " wp_distance" obtained ? (kilometer or meter or degree or what?)

thanks.

Views: 73

1

2

3

4

5

6

7

8

9

10

## Contests

Season Two of the Trust Time Trial (T3) Contest has now begun. The fourth round is an accuracy round for multicopters, which requires contestants to fly a cube. The deadline is April 14th.

A list of all T3 contests is here

24 members

1298 members

47 members

87 members

183 members