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
std::vector<double> Map::getXY(double s, double d) {
	int prev_wp = -1;
	while (s > map_waypoints_s_[prev_wp + 1] && (prev_wp < (int) (map_waypoints_s_.size() - 1))) {
		prev_wp++;
	}
	int wp2 = (prev_wp + 1) % map_waypoints_x_.size();
	double heading = atan2((map_waypoints_y_[wp2] - map_waypoints_y_[prev_wp]), (map_waypoints_x_[wp2] - map_waypoints_x_[prev_wp]));
	double seg_s = (s - map_waypoints_s_[prev_wp]);
	double seg_x = map_waypoints_x_[prev_wp] + seg_s * std::cos(heading);
	double seg_y = map_waypoints_y_[prev_wp] + seg_s * std::sin(heading);
	double perp_heading = heading - Map::pi() / 2;
	double x = seg_x + d * std::cos(perp_heading);
	double y = seg_y + d * std::sin(perp_heading);
	return
	{
		x, y
	};
}
std :: vector < double > Map :: getXY ( double s , double d ) { int prev_wp = -1 ; while ( s > map_waypoints_s_ [ prev_wp + 1 ] && ( prev_wp < ( int ) ( map_waypoints_s_ . size ( ) - 1 ) ) ) { prev_wp ++ ; } int wp2 = ( prev_wp + 1 ) % map_waypoints_x_ . size ( ) ; double heading = atan2 ( ( map_waypoints_y_ [ wp2 ] - map_waypoints_y_ [ prev_wp ] ) , ( map_waypoints_x_ [ wp2 ] - map_waypoints_x_ [ prev_wp ] ) ) ; double seg_s = ( s - map_waypoints_s_ [ prev_wp ] ) ; double seg_x = map_waypoints_x_ [ prev_wp ] + seg_s * std :: cos ( heading ) ; double seg_y = map_waypoints_y_ [ prev_wp ] + seg_s * std :: sin ( heading ) ; double perp_heading = heading - Map :: pi ( ) / 2 ; double x = seg_x + d * std :: cos ( perp_heading ) ; double y = seg_y + d * std :: 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
// the x,y,s along the segment