Skip to content

matlab/matlab-agentic-toolkit / skills-catalog/automotive/matlab-use-scenario-builder

matlab-use-scenario-builder

Verified

Generate driving scenes, scenarios, road surfaces, and 3D content from scenariobuilder.* sensor data (GPS, camera, lidar, actor tracks) using Scenario Builder for Automated Driving Toolbox. BUILD, EXPORT, or AUGMENT a virtual scenario/scene/map: ego or actor trajectories, trajectory smoothing, OpenCRG road-surface extraction, 3D asset generation, static-object placement, point-cloud georeferencing + elevation, lane-based ego localization, sensor-fusion tracking, scenario-event extraction (cut-ins, hard brakes, near-misses, ADAS disengagements), or export to RoadRunner, drivingScenario, OpenDRIVE, OpenCRG, OpenSCENARIO, or Unreal Engine. Also: log-to-scenario, scenario harvesting, accident/near-miss reconstruction, SOTIF (ISO 21448) and ISO 26262 scenario coverage, USGS-aerial-lidar augmentation, traffic-sign placement, vision-based vehicle classification for actor assets. NOT for raw-data import or multi-sensor sync/crop/offset/timestamp normalization — route those to matlab-import-driving-data.

FileKindSize
SKILL.mdskill md56.6 KB
manifest.yamlconfig704 B
references/actortrackdata-api.mdmarkdown3.3 KB
references/example-roadrunner-scenario.mdmarkdown4.3 KB
references/example-scenario-from-gps-and-tracks.mdmarkdown9.6 KB
references/execution-rules-detail.mdmarkdown16.7 KB
references/gpsdata-api.mdmarkdown2.4 KB
references/osm-flat-scene-gotchas.mdmarkdown8.8 KB
references/per-frame-detections-to-actortrackdata.mdmarkdown7.8 KB
references/python-spkg-install-troubleshooting.mdmarkdown5.8 KB
references/trajectory-api.mdmarkdown13.7 KB
references/visualization-patterns.mdmarkdown12.4 KB
references/workflow-04-roadrunner-export-detail.mdmarkdown32.6 KB
references/workflow-07-height-correction.mdmarkdown3.3 KB
references/workflow-08-lane-localization.mdmarkdown39.1 KB
references/workflow-09-static-objects.mdmarkdown9.3 KB
references/workflow-10-road-surface-opencrg.mdmarkdown4.7 KB
references/workflow-11-point-cloud-georef.mdmarkdown4.5 KB
references/workflow-12-3d-asset-generation.mdmarkdown2.0 KB
references/workflow-13-event-extraction.mdmarkdown5.3 KB
references/workflow-14-sensor-fusion-tracking.mdmarkdown6.9 KB
references/workflow-15-driving-scenario-designer.mdmarkdown7.6 KB
references/workflow-16-aerial-lidar-augmentation.mdmarkdown14.4 KB
references/workflow-17-traffic-signs-from-sensor-data.mdmarkdown12.5 KB
references/workflow-18-vehicle-classification.mdmarkdown12.8 KB
references/workflow-19-ego-lane-inference.mdmarkdown10.0 KB
scripts/buildBestCropGrid.mother5.2 KB
scripts/openFile.mother716 B
scripts/plotActorCircles.mother3.5 KB
scripts/plotBEVAndCamera.mother4.2 KB

references/workflow-07-height-correction.md

View on GitHub
---
name: workflow-07-height-correction
description: Correct trajectory Z values when an existing .rrscene has terrain elevation. Try adjustHeight first; fall back to manual road-geometry interpolation if it fails. Loaded when user uses scenes with 3D terrain (Zenrin, HERE HD, OpenDRIVE, or any elevation-aware map) — including the pre-built-scene + GPS case from workflow-04 Option B.1.
---

# Workflow 7 — Height Correction for Scenes with Elevation

> **Parent skill:** [`SKILL.md`](../SKILL.md) — Loaded when user has a scene with terrain elevation and trajectories are at Z=0 but roads are at hundreds of meters.
>
> **Related references:** [`workflow-04-roadrunner-export-detail.md`](workflow-04-roadrunner-export-detail.md) for the upstream RR scene setup. Apply this height correction *before* the export step.

**Trigger — always run `adjustHeight` for terrain-aware scenes:** If the user supplies a pre-built `.rrscene` from HERE HD, Zenrin, OpenDRIVE, or any map with elevation data (i.e. the workflow-04 Option B.1 path), run `adjustHeight(traj, rrMap)` unconditionally on every trajectory before exporting — including when GPS altitude looks reasonable. Surveyed altitude (geoid) and the scene's terrain (often EGM96 or a local datum) commonly disagree by several meters; `adjustHeight` is a no-op when alignment is already good, so there is no downside to running it. The OSM path (workflow-04 Option A) is the one case where `adjustHeight` is **not** needed (OSM has no terrain — Z is forced to 0).

When using an existing `.rrscene` that has terrain elevation (e.g., from Zenrin, HERE, or any map with 3D data), trajectories created from GPS without altitude will be at Z=0 while roads may be at hundreds of meters elevation. Use this workflow to correct heights.

## Step 1: Try `adjustHeight` first
```matlab
% adjustHeight adjusts Z to match road surface
adjustHeight(egoTrajectory, rrApp, SmoothingFactor=0.1);
```

## Step 2: Check if Z actually changed
```matlab
% If Z is still 0 (or unchanged), adjustHeight failed silently
if max(abs(egoTrajectory.Position(:,3))) < 1
    fprintf("adjustHeight did not modify Z — falling back to manual interpolation.\n");
    % Proceed to Step 3
end
```

## Step 3: Manual Z interpolation from road geometry (fallback)
If `adjustHeight` fails (often with "Trajectory is not aligned with road direction" warning), manually query road surface Z:
```matlab
%% Get road geometry from the scenario map
rrSim = createSimulation(rrApp);
rrhdMap = get(rrSim, "Map");
lbs = rrhdMap.LaneBoundaries;

% Collect all road boundary points [X, Y, Z]
allRoadPts = [];
for i = 1:numel(lbs)
    allRoadPts = [allRoadPts; lbs(i).Geometry];
end

%% Interpolate road Z for each trajectory point
egoPos = egoTrajectory.Position;
roadZ = zeros(size(egoPos, 1), 1);
for k = 1:size(egoPos, 1)
    dists = (allRoadPts(:,1) - egoPos(k,1)).^2 + (allRoadPts(:,2) - egoPos(k,2)).^2;
    [~, minIdx] = min(dists);
    roadZ(k) = allRoadPts(minIdx, 3);
end

%% Rebuild trajectory with corrected Z
correctedPos = [egoPos(:,1:2), roadZ];
egoTrajectory = scenariobuilder.Trajectory(egoTrajectory.Timestamps, correctedPos, ...
    Name="Ego", LocalOrigin=egoTrajectory.LocalOrigin);
smooth(egoTrajectory, SmoothingFactor=0.1);
```

Apply the same Z correction to actor trajectories before exporting them.

----

Copyright 2026 The MathWorks, Inc.

----
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 197kUpdated Claude CodeCodexVerifiedInstall