Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find next postion knowing lat/lon/heading/speed

Tags:

c#

algorithm

gps

knowing a decimal latitude, decimal longitude, speed (km/h), heading how to find the next position of a car after 60 seconds? is there any algorithm to do that?

like image 216
Elloumi Ahmed Avatar asked Jan 16 '23 12:01

Elloumi Ahmed


2 Answers

This might help:

distance_traveled = speed * time

Then, calculate x and y components of speed using heading as angle (trigonometry):

speed_x=distance_traveled * Math.Cos(heading/180*Math.PI)
speed_y=distance_traveled * Math.Sin(heading/180*Math.PI)

Next, see how to map lat/long into some form of x/y coordinates, add speed_x and speed_y, and convert to lat/long again.

This last one is a tricky one, look here: http://www.movable-type.co.uk/scripts/latlong.html

In fact, you'll find everything within that article!

like image 103
Daniel Mošmondor Avatar answered Jan 24 '23 17:01

Daniel Mošmondor



I've found more accurate formula
This code work for me :
1. First we have to count the distance ( speed * time ).
2. In my program, i convert the distance to KM because I use earth radius in KM too.
const double radiusEarthKilometres = 6371.01f;

            kmDistance = kmSpeed * (timer1.Interval / 1000f) / 3600f;

            var distRatio = kmDistance / radiusEarthKilometres;
            var distRatioSine = Math.Sin(distRatio);
            var distRatioCosine = Math.Cos(distRatio);

            var startLatRad = deg2rad(lat0);
            var startLonRad = deg2rad(lon0);

            var startLatCos = Math.Cos(startLatRad);
            var startLatSin = Math.Sin(startLatRad);

            var endLatRads = Math.Asin((startLatSin * distRatioCosine) + (startLatCos * distRatioSine * Math.Cos(angleRadHeading)));

            var endLonRads = startLonRad
                + Math.Atan2(Math.Sin(angleRadHeading) * distRatioSine * startLatCos,
                    distRatioCosine - startLatSin * Math.Sin(endLatRads));

            newLat = rad2deg(endLatRads);
            newLong = rad2deg(endLonRads);
like image 34
faruk Avatar answered Jan 24 '23 17:01

faruk