Logo Search packages:      
Sourcecode: navit version File versions

struct coord route_get_coord_dist ( struct route this_,
int  dist 
) [read]

Returns a coordinate at a given distance.

This function returns the coordinate, where the user will be if he follows the current route for a certain distance.

Parameters:
this_ The route we're driving upon
dist The distance in meters
Returns:
The coordinate where the user will be in that distance

Definition at line 1826 of file route.c.

References route_path_segment::c, route_path_segment::data, route_segment_data::len, route_path_segment::ncoords, route_path_segment::next, route_projection(), coord::x, and coord::y.

{
      int d,l,i,len;
      int dx,dy;
      double frac;
      struct route_path_segment *cur;
      struct coord ret;
      enum projection pro=route_projection(this_);

      d = dist;

      if (!this_->path2 || pro == projection_none) {
            return this_->pos->c;
      }
      
      ret = this_->pos->c;
      cur = this_->path2->path;
      while (cur) {
            if (cur->data->len < d) {
                  d -= cur->data->len;
            } else {
                  for (i=0; i < (cur->ncoords-1); i++) {
                        l = d;
                        len = (int)transform_polyline_length(pro, (cur->c + i), 2);
                        d -= len;
                        if (d <= 0) { 
                              // We interpolate a bit here...
                              frac = (double)l / len;
                              
                              dx = (cur->c + i + 1)->x - (cur->c + i)->x;
                              dy = (cur->c + i + 1)->y - (cur->c + i)->y;
                              
                              ret.x = (cur->c + i)->x + (frac * dx);
                              ret.y = (cur->c + i)->y + (frac * dy);
                              return ret;
                        }
                  }
                  return cur->c[(cur->ncoords-1)];
            }
            cur = cur->next;
      }

      return this_->dst->c;
}


Generated by  Doxygen 1.6.0   Back to index