%% Find Current Lanes of Two Cars
% Obtain the current lane boundaries of cars during a driving scenario
% simulation.

%%
% Create a driving scenario containing a straight, three-lane road.
scenario = drivingScenario;
roadCenters = [0 0; 80 0];
road(scenario,roadCenters,'Lanes',lanespec([1 2],'Width',3));

%%
% Add an ego vehicle moving at 20 meters per second and a target vehicle
% moving at 10 meters per second.
ego = vehicle(scenario,'ClassID',1,'Position',[5 0 0], ...
    'Length',3,'Width',2,'Height',1.6);
trajectory(ego,[1 0 0; 20 0 0; 30 0 0;50 0 0],20);

target = vehicle(scenario,'ClassID',1,'Position',[5 0 0], ...
    'Length',3,'Width',2,'Height',1.6);
trajectory(target,[5 -3 0; 20 -3 0; 30 -3 0;50 -3 0],10);
%%
% Plot the scenario.
plot(scenario)

%%
% Run the simulation loop.
while advance(scenario)
    [cl1,numlanes] = currentLane(ego);
    [cl2,numlanes] = currentLane(target);
end
%%
% Display the current lane of each vehicle.
disp(cl1)
disp(cl2)


%% 
% Copyright 2012 The MathWorks, Inc.