How to get individual Road boundaries

1 次查看(过去 30 天)
HARI
HARI 2022-3-14
回答: Gayatri 2024-1-30
Hello,
Please see the attached image.
using "RoadBoundaries" function i get overall boundaries.
Are there some ways to get boundaries of roads with different roadcentres seperately?for ex: the curved road and the straight road boundaries seperately.
Thanks!

回答(1 个)

Gayatri
Gayatri 2024-1-30
Hi,
The `roadBoundaries` function does not take individual road objects as input. Instead, it extracts the boundaries from the entire scenario. To get the boundaries for individual road segments, you'll need to extract them from the scenario after all roads have been added.
Please refer the below sample code:
1. Create the driving scenario and add the road segments.
scenario = drivingScenario(); % Create a driving scenario
laneSpecification = lanespec(2); % Define the two lanes for the roads
% Define a straight road segment
straightRoadCenters = [0 0; 100 0];
straightRoad = road(scenario, straightRoadCenters, 'Lanes', laneSpecification);
% Define a curved road segment
theta = linspace(0, pi/2, 30);
radius = 50;
curvedRoadCenters = radius * [cos(theta)' sin(theta)'];
curvedRoad = road(scenario, curvedRoadCenters, 'Lanes', laneSpecification);
Please refer the below documentation for ‘drivingScenario’ and ‘road’ functions:
2. Use the `roadBoundaries` function to extract all road boundaries from the scenario and display them.
roadBoundariesInfo = roadBoundaries(scenario); % Extract the road boundaries for the entire scenario
% Display the road boundaries
figure;
for i = 1:length(roadBoundariesInfo)
boundary = roadBoundariesInfo{i};
plot(boundary(:,1), boundary(:,2));
end
The boundaries are stored in `roadBoundariesInfo' which is a cell array where each cell contains the boundary points for a particular road segment.
Note: If you need to distinguish between the boundaries of the straight and curved roads, you will need to implement additional logic based on the known geometry of the roads you've defined.
I hope this helps!

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by