Header menu logo Euclid

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

ColinearPnt

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.

OffsetDirection

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.

VarDistParallel

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

getColinearNeighbors dirs

Full Usage: getColinearNeighbors dirs

Parameters:
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

dirs : ResizeArray<OffsetDirection voption>
Returns: ResizeArray<ColinearPnt>

getOffsetDirections (uvs, refNormal, isOpen, considerColinearBelow, failAtUTurnAbove)

Full Usage: getOffsetDirections (uvs, refNormal, isOpen, considerColinearBelow, failAtUTurnAbove)

Parameters:
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.

uvs : ResizeArray<UnitVec>
refNormal : UnitVec
isOpen : bool
considerColinearBelow : float<MeasureProduct<cosine, MeasureOne>>
failAtUTurnAbove : float<MeasureProduct<cosine, MeasureOne>>
Returns: ResizeArray<OffsetDirection voption>

getSegmentUnitVectors pts

Full Usage: getSegmentUnitVectors pts

Parameters:
    pts : ResizeArray<Pnt>

Returns: ResizeArray<UnitVec>

Computes the unit vectors of each segment in the polyline defined by pts. Fails if any two consecutive points are identical. Returns a ResizeArray of UnitVec, one less than the number of input points.

pts : ResizeArray<Pnt>
Returns: ResizeArray<UnitVec>

offset distInPlane distPerpendicular pts

Full Usage: offset distInPlane distPerpendicular pts

Parameters:
    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.

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.

offset' refNormal distInPlane distPerpendicular pts

Full Usage: offset' refNormal distInPlane distPerpendicular pts

Parameters:
    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.
    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.

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.

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.

offsetConstantWithDirections (pts, dirs, distInPlane, distPerpendicular)

Full Usage: offsetConstantWithDirections (pts, dirs, distInPlane, distPerpendicular)

Parameters:
    pts : 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.

pts : 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.

offsetVariable distancesInPlane distancesPerpendicular pts

Full Usage: offsetVariable distancesInPlane distancesPerpendicular pts

Parameters:
    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.

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.

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.

offsetVariable' varDistParallelBehavior refNormal distancesInPlane distancesPerpendicular pts

Full Usage: offsetVariable' varDistParallelBehavior refNormal distancesInPlane distancesPerpendicular pts

Parameters:
    varDistParallelBehavior : 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.

varDistParallelBehavior : 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.

offsetVariableWithDirections (pts, segmentDirs, offDirs, distsInPlane, distsPerpendicular, isClosed, varDistParallelBehavior)

Full Usage: offsetVariableWithDirections (pts, segmentDirs, offDirs, distsInPlane, distsPerpendicular, isClosed, varDistParallelBehavior)

Parameters:
    pts : 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.

pts : 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.

openTolerance

Full Usage: openTolerance

Returns: float

The tolerance for considering points to be identical in the input polyline. The value is 1e-6

Returns: float

setOffCorner pt dist nPrev nNext cosine

Full Usage: setOffCorner pt dist nPrev nNext cosine

Parameters:
Returns: Pnt
Modifiers: inline

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)))

pt : Pnt
dist : float
nPrev : UnitVec
nNext : UnitVec
cosine : float
Returns: Pnt

setOffCornerVar pt distPrev distNext nPrev nNext cosine vNext

Full Usage: setOffCornerVar pt distPrev distNext nPrev nNext cosine vNext

Parameters:
Returns: Pnt
Modifiers: inline

offset point calculation for variable distances:

pt : Pnt
distPrev : float
distNext : float
nPrev : UnitVec
nNext : UnitVec
cosine : float
vNext : UnitVec
Returns: Pnt

sqOpenTolerance

Full Usage: sqOpenTolerance

Returns: float

The squared tolerance for open polylines.

Returns: float

Type something to start searching.