%% Create and Display Road Boundaries
% Create a driving scenario containing a figure-8 road specified in the world coordinates of the scenario. Convert the world coordinates of the scenario to the coordinate system of the ego vehicle.
% Create an empty driving scenario.

scenario = drivingScenario;

%
% Add a figure-8 road to the scenario. Display the scenario.

roadCenters = [0  0  1
             20 -20  1
             20  20  1
            -20 -20  1
            -20  20  1
              0   0  1];

roadWidth = 3;
bankAngle = [0 15 15 -15 -15 0];
road(scenario,roadCenters,roadWidth,bankAngle);
plot(scenario)

%
% Add an ego vehicle to the scenario. Position the vehicle at world coordinates (20, –20) and orient it at a –15 degree yaw angle.

ego = actor(scenario,'ClassID',1,'Position',[20 -20 0],'Yaw',-15);

%
% Obtain the road boundaries in ego vehicle coordinates by using the roadBoundaries function. Specify the ego vehicle as the input argument.

rbEgo1 = roadBoundaries(ego);

%
% Display the result on a bird's-eye plot.

bep = birdsEyePlot;
lbp = laneBoundaryPlotter(bep,'DisplayName','Road');
plotLaneBoundary(lbp,rbEgo1)

%
% Obtain the road boundaries in world coordinates by using the roadBoundaries function. Specify the scenario as the input argument.

rbScenario = roadBoundaries(scenario);

% Obtain the road boundaries in ego vehicle coordinates by using the driving.scenario.roadBoundariesToEgo function.

rbEgo2 = driving.scenario.roadBoundariesToEgo(rbScenario,ego);

%
% Display the road boundaries on a bird's-eye plot.

bep = birdsEyePlot;
lbp = laneBoundaryPlotter(bep,'DisplayName','Road boundaries');
plotLaneBoundary(lbp,{rbEgo2})

% Copyright 2012 The MathWorks, Inc.