%% Plot Outlines of Targets on Bird's-Eye Plot
% Create a driving scenario. Create a 25 m road segment, add a pedestrian and a vehicle, and specify their trajectories to follow. The pedestrian crosses the road at 1 m/s. The vehicle drives along the road at 10 m/s.

scenario = drivingScenario;

road(scenario,[0 0 0; 25 0 0]);

p = actor(scenario,'ClassID',4,'Length',0.2,'Width',0.4,'Height',1.7);
v = vehicle(scenario,'ClassID',1);

trajectory(p,[15 -3 0; 15 3 0],1);
trajectory(v,[v.RearOverhang 0 0; 25-v.Length+v.RearOverhang 0 0], 10);

%
% Use a chase plot to display the scenario from the perspective of the vehicle.

chasePlot(v,'Centerline','on')

%
% Create a bird's-eye plot, outline plotter, and lane boundary plotter.

bep = birdsEyePlot('XLim',[-25 25],'YLim',[-10 10]);
olPlotter = outlinePlotter(bep);
lbPlotter = laneBoundaryPlotter(bep);
legend('off')

%
% Run the simulation loop. Update the plotter with outlines for the targets.

while advance(scenario)
   % Obtain the road boundaries and rectangular outlines.
   rb = roadBoundaries(v);
   [position,yaw,length,width,originOffset,color] = targetOutlines(v);

   % Update the bird's-eye plotters with the road and actors.
   plotLaneBoundary(lbPlotter,rb);
   plotOutline(olPlotter,position,yaw,length,width, ...
               'OriginOffset',originOffset,'Color',color);

   % Allow time for plot to update.
   pause(0.01)
end

% Copyright 2012 The MathWorks, Inc.