src/map.cpp
// Transform from Frenet s,d coordinates to Cartesian x,y
Transform from Frenet s,d coordinates to Cartesian x,y
Transform from Frenet s d coordinates to Cartesian x y
vector<double> Map::getXY2(double s, double d) {
  vector<double> &maps_s = map_waypoints_s_;
  vector<double> &maps_x = map_waypoints_x_;
  vector<double> &maps_y = map_waypoints_y_;
  int prev_wp = -1;
  while (s > maps_s[prev_wp + 1] && (prev_wp < (int)(maps_s.size() - 1))) {
    prev_wp++;
  }
  int wp2 = (prev_wp + 1) % maps_x.size();
  double heading =
      atan2((maps_y[wp2] - maps_y[prev_wp]), (maps_x[wp2] - maps_x[prev_wp]));
  double seg_s = (s - maps_s[prev_wp]);
  double seg_x = maps_x[prev_wp] + seg_s * cos(heading);
  double seg_y = maps_y[prev_wp] + seg_s * sin(heading);
  double perp_heading = heading - M_PI / 2;
  double x = seg_x + d * cos(perp_heading);
  double y = seg_y + d * sin(perp_heading);
  return {x, y};
}
vector < double > Map :: getXY2 ( double s , double d ) { vector < double > & maps_s = map_waypoints_s_ ; vector < double > & maps_x = map_waypoints_x_ ; vector < double > & maps_y = map_waypoints_y_ ; int prev_wp = -1 ; while ( s > maps_s [ prev_wp + 1 ] && ( prev_wp < ( int ) ( maps_s . size ( ) - 1 ) ) ) { prev_wp ++ ; } int wp2 = ( prev_wp + 1 ) % maps_x . size ( ) ; double heading = atan2 ( ( maps_y [ wp2 ] - maps_y [ prev_wp ] ) , ( maps_x [ wp2 ] - maps_x [ prev_wp ] ) ) ; double seg_s = ( s - maps_s [ prev_wp ] ) ; double seg_x = maps_x [ prev_wp ] + seg_s * cos ( heading ) ; double seg_y = maps_y [ prev_wp ] + seg_s * sin ( heading ) ; double perp_heading = heading - M_PI / 2 ; double x = seg_x + d * cos ( perp_heading ) ; double y = seg_y + d * sin ( perp_heading ) ; return { x , y } ; }
Transform from Frenet s,d coordinates to Cartesian x,y
Transform from Frenet s d coordinates to Cartesian x y