Skip to content

matlab/matlab-agentic-toolkit / skills-catalog/automotive/roadrunner-build-rrhd-map

roadrunner-build-rrhd-map

Verified

Build, convert, and import RoadRunner HD Maps (.rrhd) in MATLAB. Author lanes, lane boundaries, markings, junctions, signs, barriers, and speed limits with roadrunnerHDMap; convert Lanelet2 (.osm, Autoware) maps to RRHD; resolve RoadRunner road asset paths for markings, crosswalks, signs, signals, and barriers; and import or build .rrhd or OpenDRIVE (.xodr) files into a RoadRunner scene. Use when creating road networks for driving simulation, converting Lanelet2 or other HD map sources to RRHD, looking up road asset paths, or loading and verifying a map in RoadRunner or RoadRunner Scene Builder. Not for building scenes from recorded sensor data, running simulations, or recreating OpenSCENARIO (.xosc) scenarios.

FileKindSize
SKILL.mdskill md15.5 KB
manifest.yamlconfig557 B
references/assets/assetCatalog.mdmarkdown7.4 KB
references/assets/barriers.mdmarkdown3.6 KB
references/assets/laneMarkings.mdmarkdown5.8 KB
references/assets/laneTypes.mdmarkdown2.2 KB
references/assets/signs.mdmarkdown5.0 KB
references/assets/staticObjects.mdmarkdown5.1 KB
references/authoring/alignmentRules.mdmarkdown10.3 KB
references/authoring/apiReference.mdmarkdown9.0 KB
references/authoring/authoringWorkflow.mdmarkdown20.4 KB
references/authoring/deduplicateBoundaries.mdmarkdown4.9 KB
references/authoring/junctionPolygon.mdmarkdown6.8 KB
references/authoring/leftGapFilter.mdmarkdown6.5 KB
references/authoring/orthogonalSplit.mdmarkdown7.7 KB
references/authoring/resolveHeights.mdmarkdown2.4 KB
references/authoring/snapEndpoints.mdmarkdown4.0 KB
references/authoring/splitClosedGeometry.mdmarkdown3.8 KB
references/authoring/synthesizeCenterLine.mdmarkdown4.6 KB
references/authoring/validateMap.mdmarkdown1.1 KB
references/import/buildOptions.mdmarkdown4.0 KB
references/import/importScene.mdmarkdown12.9 KB
references/lanelet2/buildRRHD.mdmarkdown14.2 KB
references/lanelet2/conversionPipeline.mdmarkdown13.3 KB
references/lanelet2/coordinates.mdmarkdown4.9 KB
references/lanelet2/discoverRelations.mdmarkdown2.4 KB
references/lanelet2/enforcementGate.mdmarkdown3.3 KB
references/lanelet2/extractGeometry.mdmarkdown3.4 KB
references/lanelet2/extractJunctions.mdmarkdown5.0 KB
references/lanelet2/extractLanelets.mdmarkdown2.6 KB
references/lanelet2/extractNonLaneElements.mdmarkdown14.4 KB
references/lanelet2/extractSemantics.mdmarkdown4.4 KB
references/lanelet2/extractTopology.mdmarkdown5.4 KB
references/lanelet2/placedObjects.mdmarkdown4.4 KB
references/lanelet2/readOSM.mdmarkdown4.0 KB
references/lanelet2/splitClosedRoads.mdmarkdown3.0 KB
scripts/detectAlignment.mother3.3 KB
scripts/detectClosedLoop.mother5.8 KB
scripts/detectJunctions.mother12.4 KB
scripts/discoverWayTypes.mother4.8 KB
scripts/parseOSM.mother4.0 KB
scripts/resolveHeightConflicts.mother6.8 KB
scripts/resolveSignAsset.mother7.2 KB
scripts/snapConnectedEndpoints.mother4.0 KB
scripts/validateRRHD.mother6.3 KB

references/authoring/junctionPolygon.md

View on GitHub
# Junction Polygon Construction

Computes a junction polygon by tracing the outer boundary geometry of junction lanes. Reusable for both Lanelet2 conversion and from-scratch RRHD authoring.

## When to Use

- Building junction polygons from a set of junction lane boundaries
- Converting Lanelet2 maps with `turn_direction` tags
- Authoring RRHD from scratch where junction areas need explicit polygons

## Algorithm: Trace Outer Boundary Geometry

For authored junctions, the polygon should **follow the actual boundary polylines** — straight where boundaries are straight, curved where they curve — without spline smoothing. For junctions inferred from Lanelet2 `turn_direction` clusters, use `boundary(pts, 0.7)` (see the alternative below) — outer-boundary chaining is often impractical there.

### Step 1: Identify Outer Boundaries

Count how many times each boundary is referenced within the junction cluster. **Outer boundaries** are referenced exactly ONCE. Internal shared boundaries (referenced by 2+ junction lanes) are lane dividers inside the junction and must be excluded.

```matlab
bndWayCount = containers.Map('KeyType','char','ValueType','double');
for j = 1:numel(junctionLaneIndices)
    leftBndID = getLeftBoundaryID(junctionLaneIndices(j));
    rightBndID = getRightBoundaryID(junctionLaneIndices(j));
    if bndWayCount.isKey(leftBndID), bndWayCount(leftBndID) = bndWayCount(leftBndID)+1;
    else, bndWayCount(leftBndID) = 1; end
    if bndWayCount.isKey(rightBndID), bndWayCount(rightBndID) = bndWayCount(rightBndID)+1;
    else, bndWayCount(rightBndID) = 1; end
end

% Collect outer boundary polylines (count == 1)
outerSegs = {};
bndKeys = bndWayCount.keys;
for b = 1:numel(bndKeys)
    if bndWayCount(bndKeys{b}) == 1
        outerSegs{end+1} = getBoundaryGeometry(bndKeys{b});  % Nx2 polyline
    end
end
```

### Step 2: Chain Segments into Connected Perimeter

Order outer boundary segments by greedy nearest-endpoint chaining. Flip segments when the end point is closer than the start point. This produces a single closed polyline that traces the junction perimeter exactly.

```matlab
nSegs = numel(outerSegs);
used = false(1, nSegs);
used(1) = true;
orderedPts = outerSegs{1};

for iter = 1:nSegs-1
    currentEnd = orderedPts(end,:);
    bestDist = inf; bestIdx = 0; bestFlip = false;

    for s = 1:nSegs
        if used(s), continue; end
        seg = outerSegs{s};
        dStart = norm(currentEnd - seg(1,:));
        dEnd = norm(currentEnd - seg(end,:));
        if dStart < bestDist
            bestDist = dStart; bestIdx = s; bestFlip = false;
        end
        if dEnd < bestDist
            bestDist = dEnd; bestIdx = s; bestFlip = true;
        end
    end

    if bestIdx == 0, break; end
    used(bestIdx) = true;
    seg = outerSegs{bestIdx};
    if bestFlip, seg = flipud(seg); end

    % Append (skip first point if close to current end to avoid duplicate)
    if norm(seg(1,:) - currentEnd) < 0.2
        orderedPts = [orderedPts; seg(2:end,:)];
    else
        orderedPts = [orderedPts; seg];
    end
end

% Close the polygon
if norm(orderedPts(1,:) - orderedPts(end,:)) > 0.1
    orderedPts = [orderedPts; orderedPts(1,:)];
end

meanZ = computeMeanZFromLanes();
polygonPts3D = [orderedPts, ones(size(orderedPts,1),1)*meanZ];
```

### Step 3: Assign to Junction Object

```matlab
jObj = roadrunner.hdmap.Junction;
jObj.ID = junctionID;
pg = roadrunner.hdmap.Polygon;
pg.ExteriorRing = polygonPts3D;  % Nx3
mp = roadrunner.hdmap.MultiPolygon;
mp.Polygons = pg;
jObj.Geometry = mp;
```

## Critical Rules

| Rule | Rationale |
|------|-----------|
| Use ONLY outer boundaries (count == 1) | Internal shared boundaries cause polygon to shrink at straight-through lanes |
| Trace actual polyline geometry | Preserves straight edges as straight, curves as natural curves |
| Greedy nearest-endpoint chaining | Orders segments into a connected perimeter without distortion |
| Prefer outer boundary chaining over `boundary()`/`convhull` | Point-cloud hulls produce artificial shapes that don't follow actual road geometry |
| Do NOT use spline smoothing | Adds artificial curves where edges should be straight |
| Endpoint chaining tolerance = 0.2m | Skip duplicate junction points when connecting adjacent segments |

## Alternative: `boundary()` with Shrink Factor (Lanelet2 Conversion)

For **Lanelet2 conversion** where junctions are inferred from `turn_direction` clustering, `boundary(pts(:,1), pts(:,2), 0.7)` is an acceptable alternative when outer boundary chaining is impractical (e.g., short junction lanes where boundaries don't form a clean perimeter). This produces good curved polygons for most intersections.

**When to use convhull instead:** If `boundary(0.7)` creates concave indentations that visually exclude junction lanes (common for small 2-3 lane junctions with non-turn-direction lanes added), use `convhull` for those specific junctions while keeping `boundary(0.7)` for the rest.

```matlab
% Default: boundary(0.7) for curved polygons
k = boundary(allJuncPts(:,1), allJuncPts(:,2), 0.7);
chain = allJuncPts(k,:);

% Specific junctions needing full coverage: convhull
k = convhull(allJuncPts(:,1), allJuncPts(:,2));
chain = allJuncPts(k,:);
```

## Common Failures

| Symptom | Root Cause | Fix |
|---------|-----------|-----|
| Polygon pinches at straight lanes | Used `boundary()` with high shrink | Reduce shrink or use convhull for that junction |
| Straight edges cutting across curves | Used `convhull` globally | Use `boundary(0.7)` for most, convhull selectively |
| Artificial curves at straight edges | Applied spline smoothing | Use raw boundary geometry — no smoothing |
| Polygon inside/smaller than lanes | Included internal shared boundaries | Use only outer boundaries (count == 1) |
| Giant polygon spanning 200m+ | Cluster threshold too large (30m) | Reduce to 8m for BFS clustering |
| Disconnected polygon | Chaining tolerance too tight | Use 0.2m tolerance for endpoint matching |
| Junction doesn't cover all lanes | Only used turn_direction lanes for polygon | Include non-turn lanes at junction nodes |

## Why Outer-Only Boundaries?

Internal boundaries (shared between two junction lanes) are lane dividers INSIDE the junction. Including them in polygon construction causes:
- Polygon shrinkage where straight-through lanes extend beyond turning lanes
- The polygon cuts inward to follow internal dividers instead of the junction perimeter

By using only boundaries referenced once (the exterior perimeter), the polygon naturally encompasses all junction lanes from the outside.

## Typical Results

| Intersection Type | Lanes | Outer Segments | Polygon Points |
|-------------------|-------|----------------|----------------|
| Small T-intersection | 5-6 | 6 | ~76-87 |
| Standard 4-way | 12 | 12-24 | ~150-285 |
| Oversized (BAD) | 22+ | — | Reduce cluster threshold |

----

Copyright 2026 The MathWorks, Inc.

----
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall