#define MICROPY_FLOAT_IMPL
on
(MICROPY_FLOAT_IMPL_DOUBLE)
and compiled micropython for port esp32.
Everything works.
Code: Select all
>>> 1/3
0.333333333333333
Code: Select all
>>> 1/3
0.333333333333333
Code: Select all
def dist_waypoints(self, lat1, lon1, lat2, lon2):
"""
Calculate distance betweeen two coordinates.
"""
try:
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
result = 6371 * (acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon1 - lon2)))
meters = int(result * 1000.0);
return meters
except Exception as e:
self.exception_save(e)
sys.exit()
return 0
def bearing_dest(self, lat1, lon1, lat2, lon2):
"""
Calculate bearing destination betweeen two coordinates.
"""
try:
theta1 = radians(lat1)
theta2 = radians(lat2)
delta1 = radians(lat2-lat1)
delta2 = radians(lon2-lon1)
y = sin(delta2) * cos(theta2)
x = cos(theta1)*sin(theta2) - sin(theta1)*cos(theta2)*cos(delta2)
brng = atan2(y,x)
bearing = degrees(brng)
bearing = (bearing + 360) % 360
return bearing
except Exception as e:
self.exception_save(e)
return 0
Can I have an example please? because I don't quite understand. Thanks.pythoncoder wrote: ↑Mon May 25, 2020 6:20 amI don't know your application. Is worldwide coverage needed? If not, you could express lat and long relative to a local datum for calculations, converting to absolute values only for final display.