function f = vehicle_frame(state, P)
% compute a vehicle frame using its road frame
% and lane ey-offset

road = P.roads(state.road_id);

if abs(state.yaw) > eps
  cyaw = cos(state.yaw);
  syaw = sin(state.yaw);
  
  f = road.frame*[cyaw -syaw state.x;
                  syaw cyaw state.ey;
                  0 0 1];
else
  f = road.frame*[1 0 state.x;
                  0 1 state.ey;
                  0 0 1];  
end