%% Vary Lane Width Along Curve
% Create an empty driving scenario. Specify the road centers for a curved road.

scenario = drivingScenario;
roadCenters = [-20 22; 0 22; 18.8 15.8; 22 0; 22 -20];

% Define the lane specifications for three two-way road segments. Notice that all the road segments have the same number of lanes. However, the second road segment has a greater lane width (4.6 meters) to widen the road along the curve. The other two road segments have the default lane width of 3.6 meters.

lsArray = [lanespec([1 1]) lanespec([1 1],'Width',4.6) lanespec([1 1])];

% Define normalized lengths for each road segment. Notice that the sum of normalized lengths is 1, and the length of the vector matches the number of lane specification objects.

range = [0.25 0.65 0.1];

% Create a road segment connector object. Since the same specifications apply to both segment connectors for the three road segments, create only one laneSpecConnector object. Since you are neither adding nor dropping lanes, do not define the position property of the road segment connector.

lc = laneSpecConnector('TaperLength',14);

% Create a composite lane specification object and add the road to the driving scenario.

clspec = compositeLaneSpec(lsArray,'Connector',lc,'SegmentRange',range);
road(scenario,roadCenters,'Lanes',clspec);

% Plot the driving scenario.

plot(scenario,'RoadCenters','on')
title('Lane Widening Along a Curve')

% Copyright 2020 The MathWorks, Inc.