## [Gumstix-users] Math on the robostix

 [Gumstix-users] Math on the robostix From: Jon Keller - 2007-05-13 04:17:58 I've asked this same question around some of the avr lists but am having troubles getting an answer so I thought I may as well try this list as well, sorry if its a little off topic. I'm trying to calculate the distance between two gps coordinates on the robostix and am running into some weird issues. I'm using the code below for the calc. When I run this same code within perl and C on my standard workstation I get the correct values, which for the coordinates below are "NMiles: 2.5005995199488 SMiles: 2.87763854023694 SKm: 4.63111031889908" However when running the same code over the robostix I get the following results. "NMiles: 2.9072017670 SMiles: 3.3455481529 SKm: 5.3841376305" Obviously theres quite a big difference in the results, could anyone shed some light on why? Another very strange problem I've noticed is that if I make the two coords closer together, the results on the robostix stop decreasing when they hit a certain value, for instances the nautical miles result stops at 1.678 no matter how close the coords get to each other. Any help is greatly appreciated, Cheers. -Jon double lon1 = 174.681821; double lon2 = 174.629821; double lat2 = deg2rad(-36.728889); double lat1 = deg2rad(-36.728889); double dlon = lon2 - lon1; if (dlon > 180) { dlon -= 360; } if (dlon < -180) { dlon += 360; } double rdlon = deg2rad(dlon); double cosdist = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(rdlon); double rdist = acos(cosdist); double nautical_miles = rad2deg(rdist) * 60; double statue_miles = fabs((rad2deg(rdist) * 60.) * 1.15077945); double statue_km = fabs((rad2deg(rdist) * 60.) * 1.8520000031807997); print_double("Distance - NMiles: %.2lf SMiles: %.2lf SKm: %.2lf\n", nautical_miles, statue_miles, statue_km);