function map = update_friction_map(map, pose, vehicle_width_m, footprint_length_m, compaction_factor, mu_max)
%UPDATE_FRICTION_MAP Updates friction after a vehicle passage.
%
% pose = [x, y, psi]
% The updated area is a local rectangular footprint around the vehicle.

    x0 = pose(1);
    y0 = pose(2);
    psi = pose(3);

    dx_global = map.X - x0;
    dy_global = map.Y - y0;

    % Transform global grid coordinates into vehicle local frame.
    x_local =  cos(psi) * dx_global + sin(psi) * dy_global;
    y_local = -sin(psi) * dx_global + cos(psi) * dy_global;

    footprint_mask = abs(x_local) <= footprint_length_m/2 & ...
                     abs(y_local) <= vehicle_width_m/2 & ...
                     map.traversable;

    map.mu(footprint_mask) = min(mu_max, compaction_factor * map.mu(footprint_mask));
    map.visited_count(footprint_mask) = map.visited_count(footprint_mask) + 1;
end
