0

The purpose is to calculate the distance travelled. For this I calculate an euclidean distance with velocity, acceleration and time. I get this data from GPS. Here's my calculation:

    private float getDistanceTraveled(float vend, float vstart, long timeDifference){
        float distance = 0;

        if(vend == 0 && vstart == 0)
            return distance;

        if(vend - vstart == 0)
            distance = vend * timeDifference;
        else
            distance = (vend * vend - vstart * vstart) 
                    / ((2 * (vend - vstart) / timeDifference);

        return distance;
    }

What is the usual way to convert this distance to a shortest distance over earth surface?

I did it with simple circle calculations, where my given distance is the chord c and the radius r is the earth radius.

double distance = 2 * r * Math.asin(c / (2 * r));

I'm not 100% sure, if this is the correct way to calculate the euclidean distance and convert it. Have I take something else into account?

I'm familiar with the Haversine Formula, but I can't use the coordinates in this approach.

Steve Benett
  • 12,843
  • 7
  • 59
  • 79
  • How do you calculate the euclidean distance? – Hari Menon Oct 15 '13 at 10:24
  • Do you want to calculate the length of the arc, given the length of the chord and radius of the circle? Then your formula seems to be correct. – Abhishek Bansal Oct 15 '13 at 10:29
  • @AbhishekBansal Nice to hear, but can I use this formula for my purpose or I have to take something else into account? – Steve Benett Oct 15 '13 at 10:33
  • Vincenty's formulae may be what your after. See this question: http://stackoverflow.com/questions/27928 which has answers on both Haversine and Vincenty. – Jackson Oct 15 '13 at 10:45
  • @Jackson I can't use the coordinates to calculate the distance. But thanks for the Vincenty suggestion. I didn't know it before. – Steve Benett Oct 15 '13 at 10:55
  • What do the velocities vend and vstart signify? Are these the velocities of a vehicle on the surface of the earth as noted by the GPS? – Abhishek Bansal Oct 15 '13 at 11:06
  • @AbhishekBansal Yes, the velocity of a vehicle or a person taking a walk. – Steve Benett Oct 15 '13 at 11:26
  • @AbhishekBansal Isn't this already done at the time I'm getting the data? – Steve Benett Oct 15 '13 at 11:39
  • Actually I'm not sure whether the distance you are calculating represents the chord of the circle. – Abhishek Bansal Oct 15 '13 at 12:09
  • @AbhishekBansal OK, where's the problem? – Steve Benett Oct 15 '13 at 12:10
  • Please note that floating point has some inherent design characteristics that make things like comparing to 0 problematic; among other things, there are both positive and negative zero values. Usually, comparisons are done against some small value, known as epsilon, which represents the deviation from the 'correct' value; this is mostly to account for the fact that the values represented in doubles/floats aren't _exactly_ what people would expect (eg, `.1` can't be exactly represented). – Clockwork-Muse Oct 15 '13 at 12:32
  • The other question is for what you need the distance calculation. For most application the distance between two GPS fixes is better suited, at least if you have some filtering of the positions to avoid jitter. – AlexWien Oct 15 '13 at 20:31

2 Answers2

1

What you are measuring is the number of meters the person/vehicle travelled.
Thats fine.
You have the correct meters, there is no need to convert it to greater circle distance, nor makes this sense.
This makes only sense for distances over 10-100 km from one coordinate to the neaxt measure:
(There may be special situations where you want this, e.g when an aeroplane flights straight (by beans of 3d-straight for 100km, then falls down on earth, and then you want to know what the greater circle distance is.)

So you have the correct meters, if you need more (e.g coordinates for position prediction in a specific direction) , then this would be another question.

AlexWien
  • 28,470
  • 6
  • 53
  • 83
  • Why is this? Because the distances are small and the error factor doesn't matter? I'm very unsure at this point. Because I have read a lot about this topic, but everyone is telling another story.. – Steve Benett Oct 15 '13 at 15:11
  • Because the vehicle/person is already traveling on the earth surface, so it is implicit a greater circle distance. Further it would not matter. Further it depens where you get the speed info from. From GPS? then it is already speed over ground. And it still would not matter. You calculate the speed yourself? from distance betwwen GPS fixes, then it depend son the formula used, whether it is greater circle or line-of-sight-distance. Better you describe what you want to solve. – AlexWien Oct 15 '13 at 15:24
  • Well, I get the speed from GPS and I calclulate the distance with the formula in my question. All I want to achieve is to calculate the distance travelled. – Steve Benett Oct 15 '13 at 16:08
  • For short distances, as used between two GPS measures for a vehicle, the earth curvature has no effect. Much more effect has fact whether the road is perfectly plain or not. – AlexWien Oct 15 '13 at 17:35
0

Use this formula to proove that you dont need the distance to greater circle conversion.

b = 2 * r * arcsin(s / 2r)

where r is the earth radius in meter and s is your straight-line-of-sight distance in meter

b is then the chord length, the length on a circle with earth radius. Compare b with s, and you will se that it probably does not make sense to distinguish between that values for your application.

see also http://de.wikipedia.org/wiki/Kreissegment
only the german link provides the formula at "Bogenlänge"

AlexWien
  • 28,470
  • 6
  • 53
  • 83
  • I use this formula already. I will do some tests. The question was if I can use this formula to convert the distance to a great circle distance or if I have to take more into account. – Steve Benett Oct 15 '13 at 16:10
  • No the formula is not sufficient, the radius is dependent on the direction. – AlexWien Oct 15 '13 at 17:31
  • OK, is there a formula which I can use for this? As you said my calculation with the GPS data should do the job. But I would like to know how I can do the convertion. – Steve Benett Oct 15 '13 at 18:09
  • You would need latitude, longitude, and course, then search for "aviation formula" and "calculate position by distance and bearing from current position": – AlexWien Oct 15 '13 at 19:25