Offset3D Module
A module containing the core algorithms for offsetting 3D polylines. Normally you would not use this directly; prefer the Polyline3D 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<ColinearPoint>
|
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<float>
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:
getSegmentUnitVectors xyzs
Parameters:
ResizeArray<float>
Returns: ResizeArray<float>
|
Computes the unit vectors of each segment in the polyline defined by the X, Y and Z interleaved ResizeArray xyzs (x0, y0, z0, x1, y1, z1, ...). Fails if any two consecutive points are identical. Returns an X, Y and Z interleaved ResizeArray of the segment unit vectors, with one vector less than the number of input points.
|
Full Usage:
offset distInPlane distPerpendicular xyzs
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.
xyzs : ResizeArray<float>
-
The interleaved coordinates (x0, y0, z0, x1, y1, z1, ...) of the polyline to offset.
Returns: ResizeArray<float>
A new ResizeArray of interleaved coordinates.
|
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 xyzs
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.
xyzs : ResizeArray<float>
-
The interleaved coordinates (x0, y0, z0, x1, y1, z1, ...) of the polyline to offset.
Returns: ResizeArray<float>
A new ResizeArray of interleaved coordinates.
|
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 (xyzs, dirs, distInPlane, distPerpendicular)
Parameters:
ResizeArray<float>
-
The interleaved coordinates (x0, y0, z0, x1, y1, z1, ...) 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<float>
The offset points as a ResizeArray of interleaved coordinates.
|
Offsets a polyline by a constant distance.
|
Full Usage:
offsetVariable distancesInPlane distancesPerpendicular xyzs
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.
xyzs : ResizeArray<float>
-
The interleaved coordinates (x0, y0, z0, x1, y1, z1, ...) of the polyline to offset.
Returns: ResizeArray<float>
A new ResizeArray of interleaved coordinates.
|
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 xyzs
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.
xyzs : ResizeArray<float>
-
The interleaved coordinates (x0, y0, z0, x1, y1, z1, ...) of the polyline to offset.
Returns: ResizeArray<float>
A new ResizeArray of interleaved coordinates. 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 (xyzs, segmentDirs, offDirs, distsInPlane, distsPerpendicular, isClosed, varDistParallelBehavior)
Parameters:
ResizeArray<float>
-
The interleaved coordinates (x0, y0, z0, x1, y1, z1, ...) of the polyline to offset.
segmentDirs : ResizeArray<float>
-
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<float>
The offset points as a ResizeArray of interleaved coordinates.
|
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
|
Full Usage:
removeUTurns (xyzs, uvs, minCos)
Parameters:
ResizeArray<float>
-
The interleaved coordinates of the polyline.
uvs : ResizeArray<float>
-
The precomputed X, Y and Z interleaved segment unit vectors (one per segment, as from getSegmentUnitVectors).
minCos : float<MeasureProduct<cosine, MeasureOne>>
-
The minimum cosine value for detecting U-turns.
Returns: ResizeArray<float>
If no U-turns are present, the original ResizeArray is returned.
If U-turns are present, a new ResizeArray of coordinates is returned with the U-turns removed.
|
Removes Sharp U-Turns from an X, Y and Z interleaved ResizeArray, like Polyline3D is using.
|
The core offset Algorithm for constant distance offsets. Writes the offset point into the result buffer based on the previous and next normals, the distance, and the precomputed cosine (= dot product of nPrev * nNext). res.Add ((nPrev + nNext) * (dist / (1.0 + cosine)) + perpDir * distPerp + pt) |
|
Full Usage:
setOffCornerVar (res, x, y, z, distInPlanePrev, distInPlaneNext, distPerp, nPrev, nNext, perpDir, cosine, vNext)
Parameters:
ResizeArray<float>
x : float
y : float
z : float
distInPlanePrev : float
distInPlaneNext : float
distPerp : float
nPrev : UnitVec
nNext : UnitVec
perpDir : UnitVec
cosine : float
vNext : UnitVec
Modifiers: inline |
|
Full Usage:
sqOpenTolerance
Returns: float
|
The squared tolerance for open polylines.
|
Euclid