Offset3D Module
A module containing the core algorithms for offsetting 2D polylines. Normally you would not use this directly; prefer the Polyline2D or Points2D module. Each vertex has its own normal defined by the cross product of the incoming and outgoing segment tangents. These vertex normals define a local plane for each joint; within that plane we build per-segment offset directions.
Types
| Type | Description |
|
For a point where the segments before and after are colinear, this structure holds the index of the point, and the indices of the previous and next points that have valid offset directions. `prevOK` may be bigger than `nextOK` if the colinear point is at the start or end of a closed polyline. |
|
|
Holds the offset directions at a vertex. `prevInPlane` is the unit vector in the local plane pointing perpendicular to the previous segment, `nextInPlane` is the unit vector in the local plane pointing perpendicular to the next segment, `perpDir` is the unit vector perpendicular to the local plane made by the adjacent segments. |
|
|
We can only offset colinear segments if the distances are the same. What shall we do if they differ? Fail? or just skip the point? or add a point at closest distance on the oblique segment, non parallel offsets? or add a point perpendicular from here intersecting the oblique segment, non parallel offsets? |
Functions and values
| Function or value |
Description
|
Full Usage:
getColinearNeighbors dirs
Parameters:
ResizeArray<OffsetDirection voption>
Returns: ResizeArray<ColinearPnt>
|
For all dirs that are ValueNone this will find the index of adjacent points that are OK. Works also for closed polylines where initial and end segments are colinear
|
Full Usage:
getOffsetDirections (uvs, refNormal, isOpen, considerColinearBelow, failAtUTurnAbove)
Parameters:
ResizeArray<UnitVec>
refNormal : UnitVec
isOpen : bool
considerColinearBelow : float<MeasureProduct<cosine, MeasureOne>>
failAtUTurnAbove : float<MeasureProduct<cosine, MeasureOne>>
Returns: ResizeArray<OffsetDirection voption>
|
For points between colinear segments, ValueNone is returned. For a open polyline, the first and last points will be ValueSome, For a closed polyline, the first and last points will be identical, and they may be ValueNone if colinear. Segments are considered colinear if the cosine of the angle between them is less than considerColinearBelow. Special case: If all points are in a line the first and last point will have directions derived from the refNormal. The inner points will be ValueNone. Fails if a U-turn exceeding failAtUTurnAbove is detected.
|
|
|
Full Usage:
offset distInPlane distPerpendicular pts
Parameters:
float
-
The offset distance in the local plane defined by two segments.
A positive distance offsets to the inside of the polyline.
A negative distance offsets to the outside.
No matter how the polyline is oriented.
distPerpendicular : float
-
The offset distance perpendicular to the local plane.
A positive distance offsets in the direction of the computed normal.
For a counterclockwise polyline in xy-plane this is Upwards.
A negative distance offsets in the opposite direction.
pts : ResizeArray<Pnt>
-
The points of the polyline to offset.
Returns: ResizeArray<Pnt>
A new ResizeArray of Points.
|
A constant-distance offset algorithm for closed or open polylines in 3D. Uses default angles: colinear below 2.5 degrees, fails at U-turns above 175 degrees.
|
Full Usage:
offset' refNormal distInPlane distPerpendicular pts
Parameters:
UnitVec
-
The reference normal vector to use for computing the local planes.
For a counterclockwise polyline in xy-plane this is Upwards. If its down the offset direction is flipped.
distInPlane : float
-
The offset distance in the local plane defined by two segments.
A positive distance offsets to the inside of the polyline.
A negative distance offsets to the outside.
No matter how the polyline is oriented.
distPerpendicular : float
-
The offset distance perpendicular to the local plane.
A positive distance offsets in the direction of the computed normal.
For a counterclockwise polyline in xy-plane this is Upwards.
A negative distance offsets in the opposite direction.
pts : ResizeArray<Pnt>
-
The points of the polyline to offset.
Returns: ResizeArray<Pnt>
A new ResizeArray of Points.
|
A constant-distance offset algorithm for closed or open polylines in 3D. Uses default angles: colinear below 2.5 degrees, fails at U-turns above 175 degrees.
|
Full Usage:
offsetConstantWithDirections (pts, dirs, distInPlane, distPerpendicular)
Parameters:
ResizeArray<Pnt>
-
The points of the polyline to offset.
dirs : ResizeArray<OffsetDirection voption>
-
The offset directions at each point of the polyline.
distInPlane : float
-
The distance to offset in the local plane of each vertex.
distPerpendicular : float
-
The distance to offset perpendicular to the local plane of each vertex.
Returns: ResizeArray<Pnt>
The offset points as a ResizeArray of Pnt.
|
Offsets a polyline by a constant distance.
|
Full Usage:
offsetVariable distancesInPlane distancesPerpendicular pts
Parameters:
ResizeArray<float>
-
The offset distances in the local plane defined by two segments.
A positive distance offsets to the inside of the polyline.
A negative distance offsets to the outside.
No matter how the polyline is oriented.
distancesPerpendicular : ResizeArray<float>
-
The offset distances perpendicular to the local plane.
A positive distance offsets in the direction of the computed normal.
For a counterclockwise polyline in xy-plane this is Upwards.
A negative distance offsets in the opposite direction.
pts : ResizeArray<Pnt>
-
The points of the polyline to offset.
Returns: ResizeArray<Pnt>
A new ResizeArray of Points.
|
Offsetting each segment by its own distance. For closed or open polylines in 3D. Fails if colinear segments are found (uses VarDistParallel.Fail). Uses default angles: colinear below 2.5 degrees, fails at U-turns above 175 degrees.
|
Full Usage:
offsetVariable' varDistParallelBehavior refNormal distancesInPlane distancesPerpendicular pts
Parameters:
VarDistParallel
-
The behavior to use when colinear segments with different offset distances are found.
refNormal : UnitVec
-
The reference normal vector to use for computing the local planes.
For a counterclockwise polyline in xy-plane this is Upwards. If its down the offset direction is flipped.
distancesInPlane : ResizeArray<float>
-
The offset distances in the local plane defined by two segments.
A positive distance offsets to the inside of the polyline.
A negative distance offsets to the outside.
No matter how the polyline is oriented.
distancesPerpendicular : ResizeArray<float>
-
The offset distances perpendicular to the local plane.
A positive distance offsets in the direction of the computed normal.
For a counterclockwise polyline in xy-plane this is Upwards.
A negative distance offsets in the opposite direction.
pts : ResizeArray<Pnt>
-
The points of the polyline to offset.
Returns: ResizeArray<Pnt>
A new ResizeArray of Points. If colinear segment handling is set to Skip the point count may differ from input.
|
Offsetting each segment by its own distance. For closed or open polylines in 3D. Uses default angles: colinear below 2.5 degrees, fails at U-turns above 175 degrees.
|
Full Usage:
offsetVariableWithDirections (pts, segmentDirs, offDirs, distsInPlane, distsPerpendicular, isClosed, varDistParallelBehavior)
Parameters:
ResizeArray<Pnt>
-
The points of the polyline to offset.
segmentDirs : ResizeArray<UnitVec>
-
The unit vectors of each segment in the polyline.
offDirs : ResizeArray<OffsetDirection voption>
-
The offset directions at each point of the polyline.
distsInPlane : IList<float>
-
The distance to offset in the local plane of each vertex.
distsPerpendicular : IList<float>
-
The distance to offset perpendicular to the local plane of each vertex.
isClosed : bool
-
Whether the polyline is closed (true) or open (false).
varDistParallelBehavior : VarDistParallel
-
The behavior to use when colinear segments with different offset distances are found.
Returns: ResizeArray<Pnt>
The offset points as a ResizeArray of Pnt.
|
Offsets a polyline by variable distances.
|
Full Usage:
openTolerance
Returns: float
|
The tolerance for considering points to be identical in the input polyline. The value is 1e-6
|
|
The core offset Algorithm for constant distance offsets. Returns the offset point based on the previous and next normals, the distance, and the precomputed cosine (= dot product of nPrev * nNext). (pt + (nPrev + nNext) * (dist / (1.0 + cosine)))
|
Full Usage:
sqOpenTolerance
Returns: float
|
The squared tolerance for open polylines.
|
Euclid