High-Speed Curve Stationing, Offset & 3D Intersection Solvers with vlax-curve-* in AutoLISP (dev-cookbook-27)
Use native C++-backed vlax-curve-* and vla-IntersectWith functions in GstarCAD 2027 AutoLISP to compute arc-length stations, first/second derivatives, and curve intersections.
1. Why `vlax-curve-*` Functions Are 40× Faster Than DXF List Math
In civil alignment stationing, bridge deck setting-out, and automated cable-tray routing, AutoLISP developers frequently need to compute points at exact arc-length intervals along complex `LWPOLYLINE` (containing arc bulge segments), `SPLINE` (NURBS), `ELLIPSE`, or `HELIX` entities, as well as tangent/normal vectors (`firstDeriv`) and closest perpendicular projections. Manually parsing DXF group `10` vertices and group `42` bulge tangents ($ an( heta/4)$) in pure LISP is both mathematically fragile and slow.
In GstarCAD 2027, the **`vlax-curve-*`** family calls the underlying C++ `AcDbCurve` virtual geometry evaluator directly in compiled machine code—accepting either a classic `ENAME` (`(car (entsel))`) or a `VLA-OBJECT` without COM marshaling overhead.
2. Production AutoLISP: Automated Station Ticks & Perpendicular Offset Labels
The following Visual LISP routine places perpendicular station tick marks and rotated chainage annotations (`0+000.00m`, `0+020.00m`, ...) at user-specified intervals along *any* curve (`LWPOLYLINE`, `SPLINE`, `ARC`, or `3DPOLY`) using exact differential tangent vectors (`vlax-curve-getFirstDeriv`):
;; StationAlignment.lsp - Place orthogonal chainage ticks & labels along any AcDbCurve
(vl-load-com)
(defun C:GCSTATION ( / ent step totalLen curDist pt param deriv normAngle pTick1 pTick2 msp doc)
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object))
msp (vla-get-ModelSpace doc))
(if (and (setq ent (car (entsel "
Select alignment curve (Polyline/Spline/Arc): ")))
(not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getEndParam (list ent))))
(setq step (getdist "
Specify station interval distance <20.0>: ")))
(progn
(if (null step) (setq step 20.0))
(setq totalLen (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent))
curDist 0.0)
(vla-StartUndoMark doc)
(while (<= curDist totalLen)
;; 1. Evaluate exact 3D coordinate and curve parameter at arc length curDist
(setq pt (vlax-curve-getPointAtDist ent curDist)
param (vlax-curve-getParamAtDist ent curDist)
deriv (vlax-curve-getFirstDeriv ent param))
;; 2. Compute tangent angle and orthogonal normal (+pi/2)
(setq normAngle (+ (atan (cadr deriv) (car deriv)) (* 0.5 pi))
pTick1 (polar pt normAngle 1.5)
pTick2 (polar pt (+ normAngle pi) 1.5))
;; 3. Draw perpendicular tick line & station text
(entmakex (list '(0 . "LINE") '(8 . "C-ALGN-TICK") (cons 10 pTick1) (cons 11 pTick2)))
(entmakex (list '(0 . "TEXT")
'(8 . "C-ALGN-TEXT")
(cons 10 (polar pt normAngle 2.5))
'(40 . 2.0)
(cons 50 (- normAngle (* 0.5 pi)))
(cons 1 (strcat "STA " (rtos curDist 2 2) "m"))))
(setq curDist (+ curDist step))
)
(vla-EndUndoMark doc)
(princ (strcat "
Generated stationing along " (rtos totalLen 2 2) "m alignment."))
)
)
(princ)
)
3. Reference Matrix of Essential `vlax-curve-*` & `vla-IntersectWith` Calls
| Visual LISP Function | Mathematical Return Value | Engineering Use Case |
|---|---|---|
(vlax-curve-getClosestPointTo crv pt) |
3D WCS point on curve closest to `pt` | Snapping offset structures or boreholes perpendicularly onto a road centerline. |
(vlax-curve-getFirstDeriv crv param) |
Tangent vector $(dx/du, dy/du, dz/du)$ | Aligning block insertions (`VALVE`, `MANHOLE`, `LUMINAIRE`) tangent to host pipe/cable. |
(vlax-curve-getArea crv) |
Exact planar enclosed area ($A$) | Instant area calculation on closed splines, ellipses, and arc-bulge polylines. |
(vlax-invoke obj1 'IntersectWith obj2 mode) |
Flat list `(x1 y1 z1 x2 y2 z2 ...)` | Finding all 3D intersection points between two curves (`acExtendNone = 0`, `acExtendBoth = 3`). |
4. Handling Non-Planar 3D Splines & Variable-Width Bulge Polylines
When evaluating `vlax-curve-getPointAtProjection` on 3D utility pipelines (`3DPOLY` or non-planar `SPLINE`) that slope across varying elevations (`Z != 0`), pass the WCS projection normal `'(0.0 0.0 1.0)` so horizontal stationing distances match civil plan-view chainages rather than inclined 3D slope lengths. Conversely, when calculating true cable or pipe cut lengths for material procurement schedules, use `(vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent))`, which integrates the true 3D arc length along all three axes.
Validate This Workflow in GstarCAD 2027
Engineered by Suzhou Gstarsoft Co., Ltd. (SSE: 688657), GstarCAD 2027 delivers 100% native AC1032 DWG binary fidelity, perpetual licensing sovereignty, and zero-day AutoCAD command parity.