yucad3d

Road alignment (clothoid)

A horizontal alignment with true clothoid spiral-arc-spiral curves; query any chainage with CadRPlanGetPoint. (hc_Code_RPlan in the VeCAD help.)

// Clothoid road alignment: straight -> left spiral-arc-spiral -> right curve.
static void feat_roadplan() {
    samp_clear();
    int rp = CadAddRPlan(g_hDwg);
    if (!rp) { set_status(L"CadAddRPlan failed"); return; }
    CadRPlanSetStart(rp, 0, 0, 0.0, 0.0);                // origin, chainage 0, heading +X
    CadRPlanAddCurve(rp, 120, 0.8,  1, 100, 30, 30);     // left,  defl 0.8 rad, R100, A-spirals 30
    CadRPlanAddCurve(rp, 320, 0.6, -1, 150, 40, 40);     // right, defl 0.6 rad, R150
    CadRPlanSetEnd(rp, 460);
    CadRPlanUpdate(rp);
    double x, y, z, dir;
    if (CadRPlanGetPoint(rp, 200, &x, &y, &z, &dir)) {   // marker at chainage 200
        int m = CadAddCircle(g_hDwg, x, y, 0, 3);
        CadEntityPutColor(m, CAD_COLOR_RED);
    }
    CadUpdate(g_hDwg); samp_zoom_ext();
    wchar_t s[160]; swprintf(s, 160,
        L"CadAddRPlan: clothoid S-alignment, %d curve recs; red marker = chainage 200",
        CadRPlanGetNumRecs(rp));
    set_status(s);
}
    5:                                            // Road alignment (clothoid)
      begin
        CadPurge(FhDwg, CAD_CLEAR_ENTITIES);
        rp := CadAddRPlan(FhDwg);
        if rp = 0 then begin StatusBar.SimpleText := 'CadAddRPlan failed'; Exit; end;
        CadRPlanSetStart(rp, 0, 0, 0.0, 0.0);
        CadRPlanAddCurve(rp, 120, 0.8, 1, 100, 30, 30);
        CadRPlanAddCurve(rp, 320, 0.6, -1, 150, 40, 40);
        CadRPlanSetEnd(rp, 460);
        CadRPlanUpdate(rp);
        if CadRPlanGetPoint(rp, 200, @x, @y, @z, @dir) <> 0 then
        begin
          m := CadAddCircle(FhDwg, x, y, 0, 3);
          CadEntityPutColor(m, CAD_COLOR_RED);
        end;
        CadUpdate(FhDwg); CadExecute(FhDwg, FCadHwnd, CAD_CMD_ZOOM_EXT);
        StatusBar.SimpleText := Format('CadAddRPlan: clothoid S-alignment, %d curve recs; red marker = chainage 200',
                                       [CadRPlanGetNumRecs(rp)]);
      end;
    private void FeatRoadPlan()
    {
        SampleClear();
        var rp = YuCadApi.CadAddRPlan(_hDwg);
        if (rp == 0) { SetStatus("CadAddRPlan failed"); return; }
        YuCadApi.CadRPlanSetStart(rp, 0, 0, 0.0, 0.0);
        YuCadApi.CadRPlanAddCurve(rp, 120, 0.8, 1, 100, 30, 30);
        YuCadApi.CadRPlanAddCurve(rp, 320, 0.6, -1, 150, 40, 40);
        YuCadApi.CadRPlanSetEnd(rp, 460);
        YuCadApi.CadRPlanUpdate(rp);
        if (YuCadApi.CadRPlanGetPoint(rp, 200, out var x, out var y, out _, out _) != 0)
        {
            var m = YuCadApi.CadAddCircle(_hDwg, x, y, 0, 3);
            YuCadApi.CadEntityPutColor(m, YuCadApi.CAD_COLOR_RED);
        }
        YuCadApi.CadUpdate(_hDwg); SampleZoomExt();
        SetStatus($"CadAddRPlan: clothoid S-alignment, {YuCadApi.CadRPlanGetNumRecs(rp)} curve recs; red marker = chainage 200");
    }
This code is extracted verbatim from the shipped demo hosts (examples/cpp, examples/delphi, examples/csharp) — run the matching menu item there to see it live.