开发者

Calculating co-ordinate of a point on a path given a distance

I'm working on a project that surveys the condition of a road or highway using a calibrated trip computer connected to a rugged-PC. 开发者_运维技巧 An operator keys in defect codes as they travel along a pre-defined route.

I need to show an indicator on the map screen that shows the vehicles current position, taking into account the distance data from the trip computer.

I know the exact lat lon co-ordinates at the starting point of each section of road, and the road is made up of a series of points.

The question is: how can I calculate the lat lon co-ordinates of the vehicle assuming that it has continued on the route and traveled a certain distance (e.g. 1.4km). The co-ordinates would be 'locked onto' the road line, as shown in blue on the diagram below.

Calculating co-ordinate of a point on a path given a distance

Thanks, Alex


Here is some Java-ish pseudocode, giving a solution using linear interpolation between points.

inputs: distance, points

// construct a list of segments from the points
segments = [];
for(point in points) {
  if(not first point) {
    seg = new segment(last_point, point)
    add seg to segments
  }
  last_point = point
}

// calculate current lat and lon
for(segment in segments) {
  if(distance < segment.length) {
    alpha = distance / segment.length
    lat = segment.start.lat * (1.0 - alpha) + segment.end.lat * alpha
    lon = segment.start.lon * (1.0 - alpha) + segment.end.lon * alpha
    return (lat, lon)
  } else {
    distance = distance - segment.length
  }
}

You might also want to consider spline interpolation, which could be more accurate. It will require some more maths, but the above idea can still be applied.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜