function f = in_collision(world_state, id, P)
% return true if hero and any other entity are physically colliding
% based on approximating vehicle shape with two disks

hero_state = world_state.car_states(id);
hero = P.cars(id);

hero_frame = vehicle_frame(hero_state, P);

center_offset = (hero.length - hero.width)/2;

hero_centers = hero_frame*...
    [center_offset, -center_offset;
     0, 0;
     1, 1];

hero_front = hero_centers(1:2, 1);
hero_back = hero_centers(1:2, 2);

f = 0;

other_states = world_state.car_states([world_state.car_states.id] ~= id);

for i=1:length(other_states)
  car_state = other_states(i);
  car_frame = vehicle_frame(car_state, P);
  car = P.cars(car_state.id);
  
  center_offset = (car.length - car.width)/2;
  car_centers = car_frame*...
      [center_offset, -center_offset;
       0, 0;
       1, 1];
  car_front = car_centers(1:2,1);
  car_back = car_centers(1:2,2);
  
  safety_buffer = 1;
  
  r_min = min(hero.width, car.width) + safety_buffer;
  
  f = f || ...
      norm(hero_front - car_front) < r_min || ...
      norm(hero_front - car_back) < r_min || ...
      norm(hero_back - car_front) < r_min || ...
      norm(hero_back - car_back) < r_min;
end

