From 9a5c94eb383297856e09a2e3540f46ec0472bd45 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 21 Mar 2008 20:39:21 +0200 Subject: [PATCH] Use correct data type, now the simulator works --- src/gps.c | 9 ++++++--- src/latlon.c | 13 +++++++++++-- src/latlon.h | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/gps.c b/src/gps.c index fadb66c..bdd85eb 100644 --- a/src/gps.c +++ b/src/gps.c @@ -427,11 +427,14 @@ gfloat h; g_assert(gps); if (_dest.valid) { - _dest.angle=calculate_course(_dest.lat,_dest.lon, gps->data.lat, gps->data.lon); + gdouble c; + + c=calculate_course_rad(_dest.lat,_dest.lon, gps->data.lat, gps->data.lon); + c-=G_PI; accel=0.005*g_random_double(); - slat=accel*cos(_dest.angle); - slon=accel*sin(_dest.angle); + slat=accel*cos(c); + slon=accel*sin(c); g_debug("Sim: %f %f %f %f", slat, slon, accel, _dest.angle); } else { if (g_random_double()<0.2) { diff --git a/src/latlon.c b/src/latlon.c index e491166..8827dc1 100644 --- a/src/latlon.c +++ b/src/latlon.c @@ -206,7 +206,7 @@ return ((2.f * atan2(sqrt(a), sqrt(1.f - a))) * EARTH_RADIUS); * */ gdouble -calculate_course(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2) +calculate_course_rad(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2) { gdouble c,dlon,x,y; @@ -220,7 +220,16 @@ y=sin(dlon)*cos(lat2); x=cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(dlon); c=atan2(y,x); -/* Fixup for compass */ +return c; +} + +gdouble +calculate_course(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2) +{ +gdouble c; + +c=calculate_course_rad(lat1, lon1, lat2, lon2); + c*=180.f/M_PIl; c=c+360 % 360; return c; diff --git a/src/latlon.h b/src/latlon.h index b31649b..8f5257d 100644 --- a/src/latlon.h +++ b/src/latlon.h @@ -63,6 +63,7 @@ gdouble calculate_distance(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon gdouble calculate_ddistance(gint lat1, gint lon1, gint lat2, gint lon2); gulong calculate_idistance(gint lat1, gint lon1, gint lat2, gint lon2); gulong calculate_idistance_cmp(gint lat1, gint lon1, gint lat2, gint lon2); +gdouble calculate_course_rad(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2); gdouble calculate_course(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2); gboolean distance_point_to_line(gdouble x, gdouble y, gdouble x1, gdouble y1, gdouble x2, gdouble y2, gdouble *d); -- 2.39.5