Skip to content

editorGlobalsGeometryUtils

Class: GeometryUtils

Library for basic geometry util functions.

Hierarchy

  • GeometryUtils

Index

Methods

Methods

Static Private _cleanSeparationTestPoints

_cleanSeparationTestPoints(aPoints: ReadonlyVector3[], bPoints: ReadonlyVector3[]): object

Defined in src/util/GeometryUtils.ts:2770

Parameters:

Name Type
aPoints ReadonlyVector3[]
bPoints ReadonlyVector3[]

Returns: object

  • newA: ReadonlyVector3[]

  • newB: ReadonlyVector3[]


Static Private _get2dMappingFunctionToClosestAxisAlignedPlane

_get2dMappingFunctionToClosestAxisAlignedPlane(normal: ReadonlyVector3): function

Defined in src/util/GeometryUtils.ts:2819

Use two coordinates which don't result in zero length edges for 2d projection.

Parameters:

Name Type
normal ReadonlyVector3

Returns: function

▸ (Vector3: any): ArrayPoint2

Parameters:

Name Type
Vector3 any

Static Private _getPlaneXYVectors

_getPlaneXYVectors(plane: object): object

Defined in src/util/GeometryUtils.ts:2783

Parameters:

plane: object

Name Type
normal Vector3

Returns: object

  • xVector: Vector3‹›

  • yVector: Vector3‹›


Static _getSignedVolumeOfTriangle

_getSignedVolumeOfTriangle(a: ReadonlyVector3, b: ReadonlyVector3, c: ReadonlyVector3): number

Defined in src/util/GeometryUtils.ts:1481

Parameters:

Name Type
a ReadonlyVector3
b ReadonlyVector3
c ReadonlyVector3

Returns: number


Static Private _getVectorRelationsBetween

_getVectorRelationsBetween(candidate: ReadonlyVector3, existingBases: ReadonlyVector3[]): object

Defined in src/util/GeometryUtils.ts:2731

Parameters:

Name Type
candidate ReadonlyVector3
existingBases ReadonlyVector3[]

Returns: object

  • isCollinearToOneExistingBase: boolean

  • isOrthogonalToExistingBases: boolean


Static Private _outlineLineIntersections

_outlineLineIntersections(outline: ArrayPoint2[], lineOrigin: ReadonlyVector3, lineDirection: ReadonlyVector3, bothDirections: boolean): any[]

Defined in src/util/GeometryUtils.ts:2796

Parameters:

Name Type
outline ArrayPoint2[]
lineOrigin ReadonlyVector3
lineDirection ReadonlyVector3
bothDirections boolean

Returns: any[]


Static Private _ringPairs

_ringPairsT›(data: T[]): Array‹[T, T]›

Defined in src/util/GeometryUtils.ts:2759

Interprets input array as nodes and generates the edges of a circle including all nodes

Type parameters:

T

Parameters:

Name Type Description
data T[] the input data that will be converted in edges

Returns: Array‹[T, T]›


Static Private _roundPolygons

_roundPolygons(...polygons: ReadonlyVectorPolygon3D[]): VectorPolygon3D[]

Defined in src/util/GeometryUtils.ts:2722

Parameters:

Name Type
...polygons ReadonlyVectorPolygon3D[]

Returns: VectorPolygon3D[]


Static _signedDoubledTriangleArea

_signedDoubledTriangleArea(aX: number, aY: number, bX: number, bY: number, cX: number, cY: number): number

Defined in src/util/GeometryUtils.ts:1383

Formula taken from here http://geomalgorithms.com/a01-_area.html

Parameters:

Name Type
aX number
aY number
bX number
bY number
cX number
cY number

Returns: number


Static angleBetweenTwoVectors

angleBetweenTwoVectors(a: ReadonlyVector3, b: ReadonlyVector3, direction?: Vector3): number

Defined in src/util/GeometryUtils.ts:1330

Computes the signed angle between two vectors. The sign is based on the direction parameter and the right hand rule. Your thumb being the direction vector, a is your index finger extended forward and b the middle finger. The angle between index and middle finger will be considered positive by this implementation. Source: http://stackoverflow.com/a/33920320/1441859

Parameters:

Name Type Description
a ReadonlyVector3 -
b ReadonlyVector3 -
direction? Vector3 the rotation axis, optional

Returns: number

the angle between [-Math.PI, Math.PI]


Static anglesEqual

anglesEqual(angleA: number, angleB: number, epsilon: number): boolean

Defined in src/util/GeometryUtils.ts:2087

Determines whether two angles are equal

Parameters:

Name Type Default Description
angleA number - first angle, in radians
angleB number - second angle, in radians
epsilon number maximumRotationEqualityAngle maximum angle difference, in DEGREE (because it's better human readable that way)

Returns: boolean


Static averageNormal

averageNormal(normals: Vector3[]): Vector3

Defined in src/util/GeometryUtils.ts:75

Parameters:

Name Type
normals Vector3[]

Returns: Vector3


Static calculateTriangleArea

calculateTriangleArea(p0: ReadonlyVector3, p1: ReadonlyVector3, p2: ReadonlyVector3): number

Defined in src/util/GeometryUtils.ts:1402

formula found at https://math.stackexchange.com/a/128995

Parameters:

Name Type Description
p0 ReadonlyVector3 The vertices of the triangle
p1 ReadonlyVector3 The vertices of the triangle
p2 ReadonlyVector3 The vertices of the triangle

Returns: number


Static calculateXYatZ

calculateXYatZ(startPoint: ReadonlyVector3, endPoint: ReadonlyVector3, zValue: number): object

Defined in src/util/GeometryUtils.ts:1987

Uses slope of line to calculate point along the line

Parameters:

Name Type
startPoint ReadonlyVector3
endPoint ReadonlyVector3
zValue number

Returns: object

  • x: any

  • y: any

  • z: number = zValue


Static centerOfPoints

centerOfPoints(points: readonly ReadonlyVector3[], target: Vector3‹›): Vector3 | null

Defined in src/util/GeometryUtils.ts:450

Computes the arithmetic center of an array of points.

Parameters:

Name Type Default Description
points readonly ReadonlyVector3[] - points to compute the center of
target Vector3‹› new Vector3() -

Returns: Vector3 | null

the center point or null, if the array was empty


Static clampLineSegmentToAABB

clampLineSegmentToAABB(line: Line3, aabb: any): Line3

Defined in src/util/GeometryUtils.ts:1927

Parameters:

Name Type Description
line Line3 the line to test
aabb any the aabb to test against

Returns: Line3

the clamped line or null, if the line does not intersect


Static clampSimpleConvexPolygonAtLine

clampSimpleConvexPolygonAtLine(polygon: any, lineStart: ReadonlyVector3, lineEnd: ReadonlyVector3): void

Defined in src/util/GeometryUtils.ts:2287

Clamp everything that is to the right of line. polygon is mutated. The line is assumed to be infinite.

The algorithm identifies the indices at which the polygon crosses the line. These points are called exit and entry and will be inserted if necessary. Everything between exit and entry will then be removed from the polygon.

Parameters:

Name Type Description
polygon any the polygon to clamp. Must be convex and not have holes.
lineStart ReadonlyVector3 -
lineEnd ReadonlyVector3 -

Returns: void


Static computeNormalOfCCWPoints

computeNormalOfCCWPoints(points: readonly ReadonlyVector3[], target?: Vector3): Vector3

Defined in src/util/GeometryUtils.ts:589

Computes the normal of the points using Newell's method. The normal is computed assuming the the points are ordered CCW. https://www.khronos.org/opengl/wiki/Calculating_a_Surface_Normal#Newell.27s_Method

Parameters:

Name Type
points readonly ReadonlyVector3[]
target? Vector3

Returns: Vector3


Static connectAllUnsortedLineSegments

connectAllUnsortedLineSegments(lineSegments: ReadonlyVector3[][], startIndex: number, findAll: boolean): Vector3[][]

Defined in src/util/GeometryUtils.ts:2109

Given an array of unsorted line segments with start and end point, connect all the line segments in 3D to possibly multiple cycles.

Parameters:

Name Type Default Description
lineSegments ReadonlyVector3[][] - in the form [[Vector3, Vector3], …, [Vector3, Vector3]]
startIndex number 0 -
findAll boolean true if set to false, the search will stop after the first cycle was found

Returns: Vector3[][]

the connected line as an array of the connected line points


Static connectUnsortedLineSegments

connectUnsortedLineSegments(lineSegments: ReadonlyVector3[][], startIndex: number): Vector3[]

Defined in src/util/GeometryUtils.ts:2098

Given an array of unsorted line segments with start and end point, connect the line segments in 3D until the first cycle was found.

Parameters:

Name Type Default Description
lineSegments ReadonlyVector3[][] - in the form [[Vector3, Vector3], …, [Vector3, Vector3]]
startIndex number 0 -

Returns: Vector3[]

the connected line as an array of the connected line points


Static constructPlaneAtPoint

constructPlaneAtPoint(point: Vector3, normal: Vector3): IPlane

Defined in src/util/GeometryUtils.ts:576

Parameters:

Name Type
point Vector3
normal Vector3

Returns: IPlane


Static convexHullVertices

convexHullVertices(points: ReadonlyVector3[]): ArrayPoint2[]

Defined in src/util/GeometryUtils.ts:1310

Parameters:

Name Type
points ReadonlyVector3[]

Returns: ArrayPoint2[]


Static coplanarPolygons3DIntersect

coplanarPolygons3DIntersect(polygonA: ReadonlyVectorPolygon3D, polygonB: ReadonlyVectorPolygon3D, normal: ReadonlyVector3, clipper: PolygonClipper): boolean | Promise‹boolean›

Defined in src/util/GeometryUtils.ts:120

Given the outline and holes of two polygons, determine whether they intersect

Parameters:

Name Type Default
polygonA ReadonlyVectorPolygon3D -
polygonB ReadonlyVectorPolygon3D -
normal ReadonlyVector3 this.computeNormalOfCCWPoints(polygonA[0])
clipper PolygonClipper SyncPolygonClipperProvider.getInstance()

Returns: boolean | Promise‹boolean›


Static coplanarPolygons3DIntersection

coplanarPolygons3DIntersection(polygonA: VectorPolygon3D, polygonB: VectorPolygon3D, pointOnPlane: Vector3, normal: ReadonlyVector3, clipper: PolygonClipper, round: boolean): VectorPolygon3D[] | Promise‹VectorPolygon3D[]›

Defined in src/util/GeometryUtils.ts:146

Given the outline and holes of two polygons, determine the intersection polygon

Parameters:

Name Type Default
polygonA VectorPolygon3D -
polygonB VectorPolygon3D -
pointOnPlane Vector3 -
normal ReadonlyVector3 this.computeNormalOfCCWPoints(polygonA[0])
clipper PolygonClipper SyncPolygonClipperProvider.getInstance()
round boolean true

Returns: VectorPolygon3D[] | Promise‹VectorPolygon3D[]›


Static coplanarPolygonsRasterized3DIntersection

coplanarPolygonsRasterized3DIntersection(polygonA: VectorPolygon3D, polygonB: VectorPolygon3D, pointOnPlane: Vector3, normal: ReadonlyVector3, round: boolean, pixelBudget?: number): RasterizedPolygon3D

Defined in src/util/GeometryUtils.ts:197

Given the outline and holes of two polygons, determine the rasterized intersection. Returns null if there is no intersection which may happen because there is actually no intersection or due to a too low pixelBudget.

Parameters:

Name Type Default
polygonA VectorPolygon3D -
polygonB VectorPolygon3D -
pointOnPlane Vector3 -
normal ReadonlyVector3 this.computeNormalOfCCWPoints(polygonA[0])
round boolean true
pixelBudget? number -

Returns: RasterizedPolygon3D


Static cutGeometry

cutGeometry(geometry: Geometry | BufferGeometry, maxZ: number): Geometry

Defined in src/util/GeometryUtils.ts:1494

Cuts off a convex Geometry at the given z coordinate

Parameters:

Name Type
geometry Geometry | BufferGeometry
maxZ number

Returns: Geometry


Static deflateAndCleansePolygons

deflateAndCleansePolygons(unionOrArrayOfUnions: Polygon | Polygon[], deflationOffset: number): Polygon[]

Defined in src/util/GeometryUtils.ts:2642

Parameters:

Name Type
unionOrArrayOfUnions Polygon | Polygon[]
deflationOffset number

Returns: Polygon[]


Static deflatePolygon

deflatePolygon(polygon: Polygon, offset: number): MultiPolygon

Defined in src/util/GeometryUtils.ts:2230

Changes a polygon's size by shrinking its outline points "offset" units to the center. The difference to {@see offsetPolygon} is that it returns a MultiPolygon in case the deflating leads to a split into several polygons on negative offset values. Can not handle holes in the given polygons - they will be lost.

Parameters:

Name Type Description
polygon Polygon -
offset number should be negative.

Returns: MultiPolygon


Static degreesToRadians

degreesToRadians(degrees: number): number

Defined in src/util/GeometryUtils.ts:2575

Parameters:

Name Type
degrees number

Returns: number


Static directionsEqual

directionsEqual(directionA: ReadonlyVector3, directionB: ReadonlyVector3, epsilon: number, negatedEquals: boolean): boolean

Defined in src/util/GeometryUtils.ts:2063

Check direction of two Vector3s by normalizing them and comparing these normalized vectors. Hence, this is implicitly about angles and not about distances.

Parameters:

Name Type Default Description
directionA ReadonlyVector3 - normalized direction vector
directionB ReadonlyVector3 - normalized direction vector
epsilon number maximumRotationEqualityDistance threshold for equality
negatedEquals boolean false -

Returns: boolean

true when directionA is same direction to directionB with respect to epsilon


Static distanceBetweenLines

distanceBetweenLines(originA: ReadonlyVector3, directionA: Vector3, originB: ReadonlyVector3, directionB: Vector3): object | null

Defined in src/util/GeometryUtils.ts:971

Determines a pair of points on two lines with minimal distance. Source: http://wiki.unity3d.com/index.php/3d_Math_functions

Parameters:

Name Type Description
originA ReadonlyVector3 origin of first line
directionA Vector3 direction of first line
originB ReadonlyVector3 origin of second line
directionB Vector3 direction of second line

Returns: object | null

closest points on each line, the distances of those closest points to the origins and the distance between the two lines. null if lines are collinear.


Static Private findPolygonsFromLines

findPolygonsFromLines(lines: Vector3[][], cancelToken: CancelToken): Promise‹Vector3‹›[][]›

Defined in src/util/GeometryUtils.ts:2689

Parameters:

Name Type Description
lines Vector3[][] list of pairs of vector3 in one plane that describe 1 to n polygons
cancelToken CancelToken -

Returns: Promise‹Vector3‹›[][]›


Static fitLineThroughPoints

fitLineThroughPoints(points: ReadonlyVector3[], epsilon: number): Line3 | null

Defined in src/util/GeometryUtils.ts:475

Fit a line through points. todo: consider using a least squares approach Just takes the points which have the biggest euclidean distance and uses them as start and end. Wants all points to be on the line (within epsilon). If not, returns null.

Parameters:

Name Type Default Description
points ReadonlyVector3[] - need at least two
epsilon number maximumVectorEqualityDistance -

Returns: Line3 | null


Static fitPlaneThroughPoints

fitPlaneThroughPoints(points: readonly ReadonlyVector3[], epsilon: number): IFittedPlane | null

Defined in src/util/GeometryUtils.ts:514

Fits a plane through the point cloud using a geometric least-squares method. Source: http://stackoverflow.com/a/7557169

Parameters:

Name Type Default Description
points readonly ReadonlyVector3[] - points to compute the plane for
epsilon number Infinity if any of the points is farther than epsilon away from the plane, return null.

Returns: IFittedPlane | null

the plane (center, normal) that best fits through the point and the corresponding eigen-value as an indication for the planarity of the points (smaller values for more planar points)


Static getCenterOfGravity2D

getCenterOfGravity2D(points: ReadonlyVector3[], targetVector: Vector3‹›): Vector3

Defined in src/util/GeometryUtils.ts:1414

Taken from https://en.wikipedia.org/wiki/Centroid#Centroid_of_a_polygon

Parameters:

Name Type Default Description
points ReadonlyVector3[] - the points of the polygon
targetVector Vector3‹› new Vector3() -

Returns: Vector3


Static getCenterOfGravity3D

getCenterOfGravity3D(triangles: Array‹object›, vertices: ReadonlyVector3[], totalVolume: number): Vector3

Defined in src/util/GeometryUtils.ts:1433

As seen here http://wwwf.imperial.ac.uk/~rn/centroid.pdf

Parameters:

Name Type
triangles Array‹object›
vertices ReadonlyVector3[]
totalVolume number

Returns: Vector3


Static getDirectionOfLineTowardsPlane

getDirectionOfLineTowardsPlane(linePoint: Vector3, lineVector: Vector3, planePoint: Vector3, planeNormal: Vector3): object

Defined in src/util/GeometryUtils.ts:1156

Parameters:

Name Type
linePoint Vector3
lineVector Vector3
planePoint Vector3
planeNormal Vector3

Returns: object

  • direction: Vector3

  • negated: boolean


Static getIntersectionLineForPlaneObjects

getIntersectionLineForPlaneObjects(planeA: Plane, planeB: Plane): Line3 | null

Defined in src/util/GeometryUtils.ts:1595

Calculates intersection line between two three.js plane objects. Returns null when the planes have the same normal (or opposite).

Parameters:

Name Type
planeA Plane
planeB Plane

Returns: Line3 | null


Static getLineLineIntersection

getLineLineIntersection(a: Line3, b: Line3, epsilon: number): Line3 | null

Defined in src/util/GeometryUtils.ts:1509

Intersect two lines in 3D. The lines are treated as infinite lines, not line segments. Implementation of Paul Bourke"s "The shortest line between two lines in 3D". http://paulbourke.net/geometry/pointlineplane/ http://paulbourke.net/geometry/pointlineplane/lineline.c

Parameters:

Name Type Default Description
a Line3 - a line (treated as infinite, not segment)
b Line3 - a line (treated as infinite, not segment)
epsilon number 0.001 -

Returns: Line3 | null

the shortest possible line from line a to line b. returns null for parallel and collinear lines


Static getLineSegmentLineSegmentIntersection

getLineSegmentLineSegmentIntersection(a: Line3, b: Line3, epsilon: number): Vector3 | null

Defined in src/util/GeometryUtils.ts:1570

Intersect two lines in 3D. The lines are treated as finite segments, not infinite lines. Uses GeometryUtils.getLineLineIntersection for the line intersection calculation and then checks if the intersection point is on both segments.

Parameters:

Name Type Default Description
a Line3 - a line (treated as a segment, not infinite)
b Line3 - a line (treated as a segment, not infinite)
epsilon number 0.001 -

Returns: Vector3 | null

the intersection point of a and b returns null if there exists no such point


Static getLineSegmentOverlap

getLineSegmentOverlap(startA: ReadonlyVector3, endA: ReadonlyVector3, startB: ReadonlyVector3, endB: ReadonlyVector3, maxDistance: number): any[]

Defined in src/util/GeometryUtils.ts:2495

Parameters:

Name Type Default
startA ReadonlyVector3 -
endA ReadonlyVector3 -
startB ReadonlyVector3 -
endB ReadonlyVector3 -
maxDistance number maximumVectorEqualityDistance

Returns: any[]


Static getOutermostPointOnLine

getOutermostPointOnLine(array: ReadonlyVector3[]): Vector3

Defined in src/util/GeometryUtils.ts:1960

Assumes all points to be on a line. Determines the outermost point. Of both possible outermost points, the one with the smaller coordinates is chosen

Parameters:

Name Type Description
array ReadonlyVector3[] of points

Returns: Vector3

the outermost point with smallest coordinates


Static getPerpendicularVector

getPerpendicularVector(__namedParameters: object): Vector3

Defined in src/util/GeometryUtils.ts:2013

Algorithm taken from here http://blog.selfshadow.com/2011/10/17/perp-vectors/

Parameters:

__namedParameters: object

Name Type
x any
y any
z any

Returns: Vector3

a new Vector3 instance, that is perpendicular to the given vector. The direction is not fully specified (the rotation around the initial vector is 1 DoF), so it chooses arbitrarily (but deterministically).

The resulting vector is normalized;

If the input is a zero vector, a zero vector will be returned.


Static getPlaneCycleIntersection

getPlaneCycleIntersection(plane: Plane, cycle: readonly ReadonlyVector3[], params: object): Array‹object›

Defined in src/util/GeometryUtils.ts:1641

Intersects a plane with a Vector3 cycle.

Parameters:

plane: Plane

cycle: readonly ReadonlyVector3[]

params: object

Name Type
ignoreSegmentsInPlane? boolean
tolerance? number

Returns: Array‹object›

an array that, for each intersection, contains the start and end point of the section and the intersection point


Static getPlaneLineIntersection

getPlaneLineIntersection(planeNormal: ReadonlyVector3, planeConstant: number, lineStart: ReadonlyVector3, lineEnd: ReadonlyVector3, clamp: boolean, target?: Vector3, epsilon: number, nullIfCoplanar: boolean): Vector3 | null

Defined in src/util/GeometryUtils.ts:1695

Taken from Plane, but with optional clamping

Parameters:

Name Type Default Description
planeNormal ReadonlyVector3 - -
planeConstant number - -
lineStart ReadonlyVector3 - -
lineEnd ReadonlyVector3 - -
clamp boolean true -
target? Vector3 - -
epsilon number 0 lines are seen as coplanar to the plane wrt this epsilon
nullIfCoplanar boolean false -

Returns: Vector3 | null


Static getPlaneLineIntersectionWithRelativePositionOnLine

getPlaneLineIntersectionWithRelativePositionOnLine(planeNormal: ReadonlyVector3, planeConstant: number, lineStart: ReadonlyVector3, lineEnd: ReadonlyVector3, clamp: boolean, target?: Vector3, epsilon: number, nullIfCoplanar: boolean): object

Defined in src/util/GeometryUtils.ts:1721

Similar to getPlaneLineIntersection but also returns the relative position on the line where 0 is lineStart and 1 is lineEnd

Parameters:

Name Type Default
planeNormal ReadonlyVector3 -
planeConstant number -
lineStart ReadonlyVector3 -
lineEnd ReadonlyVector3 -
clamp boolean true
target? Vector3 -
epsilon number 0
nullIfCoplanar boolean false

Returns: object

  • intersection: Vector3 | null

  • t: number | null


Static getPlanePlaneIntersectionLine

getPlanePlaneIntersectionLine(positionA: ReadonlyVector3, normalA: ReadonlyVector3, positionB: ReadonlyVector3, normalB: ReadonlyVector3): Line3 | null

Defined in src/util/GeometryUtils.ts:1607

Calculates intersection line between two planes. Returns null when the planes have the same normal (or opposite).

Parameters:

Name Type
positionA ReadonlyVector3
normalA ReadonlyVector3
positionB ReadonlyVector3
normalB ReadonlyVector3

Returns: Line3 | null


Static getPositionOfPointProjectedToLine

getPositionOfPointProjectedToLine(line: Line3, point: ReadonlyVector3): Vector3

Defined in src/util/GeometryUtils.ts:953

Calculates the position of point when projecting it onto line along a line's orthogonal. Treats line as infinite. / l P / \ / v / P' /

Parameters:

Name Type Description
line Line3 the line which the point should be projected on
point ReadonlyVector3 the point that should be projected onto the line

Returns: Vector3

the position of the projected point, now lying on line


Static getRayAABBIntersection

getRayAABBIntersection(ray: Ray, aabb: AABB, desiredValue?: "boolean" | "first" | "last" | "both", invDirection?: ReadonlyVector3): false | true | Vector3‹› | Vector3‹›[]

Defined in src/util/GeometryUtils.ts:1830

Intersects the ray and the AABB whether there was an intersection or the intersection points. Method adapted from https://people.csail.mit.edu/amy/papers/box-jgt.pdf This method is not as optimized as https://tavianator.com/fast-branchless-raybounding-box-intersections-part-2-nans but it behaves more nicely in edge cases such as degenerate bounding boxes (e.g. the AABBs of planar surfaces).

Parameters:

Name Type Description
ray Ray the ray to test
aabb AABB the aabb to test
desiredValue? "boolean" | "first" | "last" | "both" Which intersection point should be returned. May be - "boolean" returns true, if there was an intersection, false otherwise - "first" returns the first intersection with the aabb, or null - "last" returns the last intersection with the aabb, or null - "both" returns an array containing both intersections with the aabb (even if one of them is behind the ray origin!), or null, if there is no intersection at all
invDirection? ReadonlyVector3 You may optionally specify the inverse ray direction, which is used to replace division operations with multiplications. Make sure to not have -0 values anywhere.

Returns: false | true | Vector3‹› | Vector3‹›[]


Static getScalarForPointOnLine

getScalarForPointOnLine(origin: Vector3, direction: Vector3, point: Vector3): number | null

Defined in src/util/GeometryUtils.ts:842

Take a line with an origin and a direction and a point which lies on the line and return the constant factor where origin + factor * direction = point Throws if the point is not on the line.

Parameters:

Name Type
origin Vector3
direction Vector3
point Vector3

Returns: number | null


Static getThreeIFittedPlaneIntersection

getThreeIFittedPlaneIntersection(planeA: IFittedPlane, planeB: IFittedPlane, planeC: IFittedPlane): Vector3 | null

Defined in src/util/GeometryUtils.ts:1764

Parameters:

Name Type
planeA IFittedPlane
planeB IFittedPlane
planeC IFittedPlane

Returns: Vector3 | null


Static getThreePlaneIntersection

getThreePlaneIntersection(point1: ReadonlyVector3, normal1: ReadonlyVector3, point2: ReadonlyVector3, normal2: ReadonlyVector3, point3: ReadonlyVector3, normal3: ReadonlyVector3): Vector3

Defined in src/util/GeometryUtils.ts:1793

It's not about three.js planes but we intersect 3 planes.

Parameters:

Name Type Description
point1 ReadonlyVector3 a point that lies in the first plane
normal1 ReadonlyVector3 the normal of the first plane
point2 ReadonlyVector3 a point that lies in the second plane
normal2 ReadonlyVector3 the normal of the second plane
point3 ReadonlyVector3 a point that lies in the third plane
normal3 ReadonlyVector3 the normal of the third plane

Returns: Vector3

the intersection point of the three planes or null if there is none


Static getUnionOfPolygonsByDeflating

getUnionOfPolygonsByDeflating(polygon: MultiPolygon, inflationOffset: number): Polygon[]

Defined in src/util/GeometryUtils.ts:2620

Parameters:

Name Type Default
polygon MultiPolygon -
inflationOffset number Config.get("modelLimits.maximumPositionPrecision")

Returns: Polygon[]


Static getVolume

getVolume(faces: Array‹object›, vertices: ReadonlyVector3[]): number

Defined in src/util/GeometryUtils.ts:1473

As seen here http://stackoverflow.com/a/1568551/1441859

Parameters:

Name Type
faces Array‹object›
vertices ReadonlyVector3[]

Returns: number


Static inverseLerp

inverseLerp(a: ReadonlyVector3, b: ReadonlyVector3, v: ReadonlyVector3): number

Defined in src/util/GeometryUtils.ts:264

Parameters:

Name Type
a ReadonlyVector3
b ReadonlyVector3
v ReadonlyVector3

Returns: number


Static isVoxelModel

isVoxelModel(polygons: ReadonlyVectorPolygon3D[]): boolean

Defined in src/util/GeometryUtils.ts:2544

Checks the polygons' normals to see if they create a three dimensional orthogonal system. Because of that, the input polygons can be rotated by any shared degree. If that's the case, the model created by polygons is a voxel model. Can handle slightly inexact normals as defined by GeometryUtils.directionsEqual & GeometryUtils.vectorsPerpendicular.

Parameters:

Name Type
polygons ReadonlyVectorPolygon3D[]

Returns: boolean


Static lineLineIntersection2D

lineLineIntersection2D(originA: ReadonlyVector3, directionA: ReadonlyVector3, originB: ReadonlyVector3, directionB: ReadonlyVector3): Vector3 | null

Defined in src/util/GeometryUtils.ts:1058

Source: http://stackoverflow.com/a/4543530

Parameters:

Name Type Description
originA ReadonlyVector3 the origin of the first line
directionA ReadonlyVector3 the direction of the first line
originB ReadonlyVector3 the origin of the second line
directionB ReadonlyVector3 the direction of the second line

Returns: Vector3 | null

the intersection point of the two lines or null if the lines are parallel


Static lineLineIntersection3D

lineLineIntersection3D(a: Line3, b: Line3, epsilon: number): Vector3 | null

Defined in src/util/GeometryUtils.ts:1008

Intersection of two lines in 3D space.

Parameters:

Name Type Default
a Line3 -
b Line3 -
epsilon number maximumVectorEqualityDistance

Returns: Vector3 | null

the point where the lines intersect or null if they do not intersect


Static lineLineSegmentIntersection2D

lineLineSegmentIntersection2D(segmentStart: ReadonlyVector3, segmentEnd: ReadonlyVector3, lineOrigin: ReadonlyVector3, lineDirection: ReadonlyVector3, bothDirections: boolean, distanceEpsilon: number): Vector3

Defined in src/util/GeometryUtils.ts:1093

Source: https://rootllama.wordpress.com/2014/06/20/ray-line-segment-intersection-test-in-2d/

Parameters:

Name Type Default Description
segmentStart ReadonlyVector3 - the start of the line segment to intersect
segmentEnd ReadonlyVector3 - the end of the line segment to intersect
lineOrigin ReadonlyVector3 - the origin of the line
lineDirection ReadonlyVector3 - the direction of the line
bothDirections boolean - if false, intersections in negative line direction will be discarded
distanceEpsilon number 0.01 the tolerance that is used to determine whether there was an intersection with the line segment

Returns: Vector3

the intersection point or null if there was no intersection


Static lineLineSegmentIntersection2DInner

lineLineSegmentIntersection2DInner(segmentStart: ReadonlyVector3, segmentEnd: ReadonlyVector3, lineOrigin: ReadonlyVector3, lineDirection: ReadonlyVector3, bothDirections: boolean, distanceEpsilon: number): Vector3 | null

Defined in src/util/GeometryUtils.ts:1132

It calculates the intersection between a line and a line segment, but - opposed to lineLineSegmentIntersection2D it does not consider touching of the line segments end points and the line as an intersection. Returns null when we don't find an intersection

Parameters:

Name Type Default
segmentStart ReadonlyVector3 -
segmentEnd ReadonlyVector3 -
lineOrigin ReadonlyVector3 -
lineDirection ReadonlyVector3 -
bothDirections boolean -
distanceEpsilon number 0.01

Returns: Vector3 | null


Static lineLineSegmentIntersection3D

lineLineSegmentIntersection3D(line: Line3, segment: Line3): Vector3 | null

Defined in src/util/GeometryUtils.ts:1024

Intersection of a line and a segment with fixed length

Parameters:

Name Type
line Line3
segment Line3

Returns: Vector3 | null

the point where the line and the segment intersect or null if they do not intersect


Static lineSegmentInAABB

lineSegmentInAABB(line: Line3, aabb: any): boolean

Defined in src/util/GeometryUtils.ts:1950

Parameters:

Name Type Description
line Line3 the line to test
aabb any the aabb to test against

Returns: boolean

whether line is (partly) inside of aabb


Static lineSegmentLineSegmentIntersection2D

lineSegmentLineSegmentIntersection2D(pA0: ReadonlyVector3, pA1: ReadonlyVector3, pB0: ReadonlyVector3, pB1: ReadonlyVector3, distanceEpsilon: number): Vector3 | null

Defined in src/util/GeometryUtils.ts:83

Similar to lineIntersection2D, but returns null if the intersection point is outside of either line segment

Parameters:

Name Type
pA0 ReadonlyVector3
pA1 ReadonlyVector3
pB0 ReadonlyVector3
pB1 ReadonlyVector3
distanceEpsilon number

Returns: Vector3 | null

intersection point (z = 0)


Static lineSegmentLineSegmentIntersection2DInner

lineSegmentLineSegmentIntersection2DInner(pA0: ReadonlyVector3, pA1: ReadonlyVector3, pB0: ReadonlyVector3, pB1: ReadonlyVector3, distanceEpsilon: number): Vector3 | null

Defined in src/util/GeometryUtils.ts:240

similar to lineSegmentLineSegmentIntersection2D, but also returning null (no intersection), when the line segments only touch each other and don't actually cross.

Parameters:

Name Type Default
pA0 ReadonlyVector3 -
pA1 ReadonlyVector3 -
pB0 ReadonlyVector3 -
pB1 ReadonlyVector3 -
distanceEpsilon number maximumVectorEqualityDistance

Returns: Vector3 | null


Static lineSegmentsOverlap

lineSegmentsOverlap(startA: ReadonlyVector3, endA: ReadonlyVector3, startB: ReadonlyVector3, endB: ReadonlyVector3, maxDistance: number): boolean

Defined in src/util/GeometryUtils.ts:2465

Parameters:

Name Type Default
startA ReadonlyVector3 -
endA ReadonlyVector3 -
startB ReadonlyVector3 -
endB ReadonlyVector3 -
maxDistance number maximumVectorEqualityDistance

Returns: boolean


Static lineSideOfPoint

lineSideOfPoint(start: ReadonlyVector3, end: ReadonlyVector3, point: any, epsilon: any): number

Defined in src/util/GeometryUtils.ts:806

Determines which side (positive or negative) of a given 2D line a point is on. Z values of the points are ignored.

Parameters:

Name Type Default Description
start ReadonlyVector3 - start point of a segment of the infinite line
end ReadonlyVector3 - end point of a segment of the infinite line
point any - point to check
epsilon any Config.get("modelLimits.maximumPositionEqualityDistance") a distance smaller than that will be counted as "on the line"

Returns: number

side of the point relative to the line (either -1, 1 or 0)


Static lineSphereIntersectionsParameters

lineSphereIntersectionsParameters(lineOrigin: ReadonlyVector3, lineDirection: ReadonlyVector3, center: ReadonlyVector3, radius: number, radiusSquared: number, nearestPoint: boolean): number[]

Defined in src/util/GeometryUtils.ts:2593

calculates the intersections between a line and a sphere

Parameters:

Name Type Default Description
lineOrigin ReadonlyVector3 - point on the line
lineDirection ReadonlyVector3 - direction of the line
center ReadonlyVector3 - center point of the sphere
radius number - radius of the sphere
radiusSquared number Math.pow(radius, 2) convenience
nearestPoint boolean false Whether to return the parameter of the nearest point instead of no point when there's no intersection

Returns: number[]

0 - 2 parameters specifying points on the line by distance from lineOrigin


Static linesCollinear

linesCollinear(lineAOrigin: ReadonlyVector3, lineADirection: ReadonlyVector3, lineBOrigin: ReadonlyVector3, lineBDirection: ReadonlyVector3, allowReverse: boolean, maxDistance: number): boolean

Defined in src/util/GeometryUtils.ts:2447

Parameters:

Name Type Default
lineAOrigin ReadonlyVector3 -
lineADirection ReadonlyVector3 -
lineBOrigin ReadonlyVector3 -
lineBDirection ReadonlyVector3 -
allowReverse boolean true
maxDistance number maximumVectorEqualityDistance

Returns: boolean


Static linesCollinearityScore

linesCollinearityScore(lineA: Line3, lineB: Line3): number

Defined in src/util/GeometryUtils.ts:1555

Parameters:

Name Type
lineA Line3
lineB Line3

Returns: number


Static mapDifferenceAngleToNormalVectorDistance

mapDifferenceAngleToNormalVectorDistance(angle: number): number

Defined in src/util/GeometryUtils.ts:441

Maps a "max 2°" difference" to "max x length difference between two normal vectors"

Parameters:

Name Type Description
angle number in degree

Returns: number


Static mirrorDirection

mirrorDirection(direction: Vector3, mirrorMatrix: Matrix4): Vector3

Defined in src/util/GeometryUtils.ts:2610

Parameters:

Name Type
direction Vector3
mirrorMatrix Matrix4

Returns: Vector3


Static mirrorDirectionAtPlane

mirrorDirectionAtPlane(direction: ReadonlyVector3, planeNormal: ReadonlyVector3, target: Vector3‹›): Vector3‹›

Defined in src/util/GeometryUtils.ts:2528

Parameters:

Name Type Default
direction ReadonlyVector3 -
planeNormal ReadonlyVector3 -
target Vector3‹› new Vector3()

Returns: Vector3‹›


Static mirrorPositionAtPlane

mirrorPositionAtPlane(position: ReadonlyVector3, plane: Plane, target: Vector3‹›): Vector3‹›

Defined in src/util/GeometryUtils.ts:2523

Parameters:

Name Type Default
position ReadonlyVector3 -
plane Plane -
target Vector3‹› new Vector3()

Returns: Vector3‹›


Static moduloVectors

moduloVectors(vectorA: ReadonlyVector3, vectorB: ReadonlyVector3, target: Vector3‹›): Vector3‹›

Defined in src/util/GeometryUtils.ts:2048

Performs a modulo operation component-wise. The modulo operation is the variation found in MathUtils.modulo, i.e. the sign of the result is the same as that of the divisor.

Parameters:

Name Type Default
vectorA ReadonlyVector3 -
vectorB ReadonlyVector3 -
target Vector3‹› new Vector3()

Returns: Vector3‹›


Static offsetPolygon

offsetPolygon(polygon: Polygon, offset: any): Polygon

Defined in src/util/GeometryUtils.ts:2216

Changes a polygon's size by moving its outline points "offset" units away from the center. For deflation this only works reliably for convex polygons. If a concave polygon is passed, and it is split into several polygons only the first polygon result is returned. This leads to polygons being lost. To fix this think about using {@see deflatePolygon}.

Parameters:

Name Type Description
polygon Polygon -
offset any can be negative. Negative values shrink the polygon

Returns: Polygon


Static planeDistanceToPoint

planeDistanceToPoint(__namedParameters: object, point: ReadonlyVector3): number

Defined in src/util/GeometryUtils.ts:697

Directed distance of the plane to the point, i.e. it may be negative.

Parameters:

__namedParameters: object

Name Type
constant number
normal Vector3‹›

point: ReadonlyVector3

Returns: number


Static planeSideOfPoint

planeSideOfPoint(plane: object, point: ReadonlyVector3, epsilon: number): number

Defined in src/util/GeometryUtils.ts:682

Determines which side (positive or negative) of a given plane a point is on. Plane p: normal * x = constant epsilon = 0 for compatibility to old methods using this, Config.get "modelLimits.maximumPositionEqualityDistance" is reasonable

Parameters:

plane: object

normal and constant of the plane

Name Type
constant number
normal Vector3

point: ReadonlyVector3

point to check

Default value epsilon: number= 0

the epsilon to determine whether the point lies in the plane (= return 0)

Returns: number

side of the point relative to the plane (either -1, 1 or 0)


Static planesCoplanar

planesCoplanar(planeA: object, planeB: object, allowReverse: boolean, maxDistance: number): boolean

Defined in src/util/GeometryUtils.ts:2405

Check whether two planes are coplanar.

Parameters:

planeA: object

Name Type
constant number
normal ReadonlyVector3

planeB: object

Name Type
constant number
normal ReadonlyVector3

Default value allowReverse: boolean= true

If true, the two planes may face in opposite directions and are still considered coplanar.

Default value maxDistance: number= maximumVectorEqualityDistance

Returns: boolean


Static pointDistanceToLineSegment

pointDistanceToLineSegment(point: ReadonlyVector3, start: ReadonlyVector3, end: ReadonlyVector3, clampToLine: boolean): number

Defined in src/util/GeometryUtils.ts:862

Calculates the distance of a point to a line segment given by start and end. Source: http://geomalgorithms.com/a02-_lines.html

Parameters:

Name Type Default Description
point ReadonlyVector3 - to compute distance to
start ReadonlyVector3 - point of the line segment
end ReadonlyVector3 - point of the line segment
clampToLine boolean true (optional) whether to clamp the returned value to the line segment, defaults to true

Returns: number

distance between point and line segment


Static pointInTriangle2D

pointInTriangle2D(point: Vector3, trianglePoints: [Vector3, Vector3, Vector3], epsilon: number, allowEpsilonDistance: boolean): boolean

Defined in src/util/GeometryUtils.ts:710

Check if a 2D point lies in a 2D triangle.

Parameters:

Name Type Default Description
point Vector3 - -
trianglePoints [Vector3, Vector3, Vector3] - -
epsilon number maximumVectorEqualityDistance -
allowEpsilonDistance boolean true If true, points are considered to be inside even if they are < epsilon-length outside/within the triangle If false, points aren't considered to be inside if they are within an epsilon-length distance near the triangle border

Returns: boolean


Static pointInVectorPolygon3D

pointInVectorPolygon3D(point: ReadonlyVector3, polygon: ReadonlyVectorPolygon3D): boolean

Defined in src/util/GeometryUtils.ts:750

Return true when the point lies within the polygon. We also return true when it's within positionEqualityDistance of an edge.

Parameters:

Name Type
point ReadonlyVector3
polygon ReadonlyVectorPolygon3D

Returns: boolean


Static pointOnLine

pointOnLine(point: ReadonlyVector3, start: ReadonlyVector3, end: ReadonlyVector3, epsilon: number): boolean

Defined in src/util/GeometryUtils.ts:931

Treats the given line as infinite. If you want to check if the point is on the line defined between start and end, use GeometryUtils.pointOnLineSegment

Parameters:

Name Type Default
point ReadonlyVector3 -
start ReadonlyVector3 -
end ReadonlyVector3 -
epsilon number maximumVectorEqualityDistance

Returns: boolean


Static pointOnLineSegment

pointOnLineSegment(point: ReadonlyVector3, start: ReadonlyVector3, end: ReadonlyVector3, epsilon: number): boolean

Defined in src/util/GeometryUtils.ts:918

Treats the given line as finite. If you want to check if the point is on the vector defined through start and end, use GeometryUtils.pointOnLine

Parameters:

Name Type Default
point ReadonlyVector3 -
start ReadonlyVector3 -
end ReadonlyVector3 -
epsilon number maximumVectorEqualityDistance

Returns: boolean


Static pointSetsCanBeSeparated

pointSetsCanBeSeparated(aPoints: ReadonlyVector3[], bPoints: ReadonlyVector3[]): Promise‹boolean›

Defined in src/util/GeometryUtils.ts:1198

Examine, if two given sets of points can be separated clearly by a line. Points exactly on the line are always fine. That means, that there can be multiple coordinates present in both sets while they are still separable.

Parameters:

Name Type Description
aPoints ReadonlyVector3[] a collection of points
bPoints ReadonlyVector3[] the other collection of points

Returns: Promise‹boolean›

true iff a line can be drawn to separate these two point sets


Static pointsAreCollinear

pointsAreCollinear(points: ReadonlyVector3[], epsilon: number): boolean

Defined in src/util/GeometryUtils.ts:1185

Opposed to checking for direction equality, rather fit a line through the points and ensure that all points are at most epsilon from the line apart.

Parameters:

Name Type Default
points ReadonlyVector3[] -
epsilon number maximumVectorEqualityDistance

Returns: boolean


Static pointsAreCoplanar

pointsAreCoplanar(points: ReadonlyVector3[], plane?: IPlane, epsilon: number): boolean

Defined in src/util/GeometryUtils.ts:553

Return true if there exists a plane that contains all points by epsilon distance. (see definition: https://en.wikipedia.org/wiki/Coplanarity) True if # points <= 3 (even if they lay at the same position).

throws if you supply more than three points and fitPlaneThroughPoints fails. (todo: fix this)

Parameters:

Name Type Default
points ReadonlyVector3[] -
plane? IPlane -
epsilon number maximumVectorEqualityDistance

Returns: boolean


Static polygon3dLineIntersections

polygon3dLineIntersections(polygon: VectorPolygon3D, lineOrigin: ReadonlyVector3, lineDirection: ReadonlyVector3): Vector3‹›[]

Defined in src/util/GeometryUtils.ts:2188

Parameters:

Name Type
polygon VectorPolygon3D
lineOrigin ReadonlyVector3
lineDirection ReadonlyVector3

Returns: Vector3‹›[]


Static polygonArea

polygonArea(points: readonly ReadonlyVector3[]): number

Defined in src/util/GeometryUtils.ts:643

Computes the area of a polygon Source: http://stackoverflow.com/a/12643315

Parameters:

Name Type Description
points readonly ReadonlyVector3[] vertices of the polygon

Returns: number

the area of the polygon


Static polygonLineIntersections

polygonLineIntersections(polygon: any, lineOrigin: ReadonlyVector3, lineDirection: ReadonlyVector3, bothDirections: boolean): Vector3[]

Defined in src/util/GeometryUtils.ts:2241

Parameters:

Name Type Default Description
polygon any - [Polygon
lineOrigin ReadonlyVector3 - -
lineDirection ReadonlyVector3 - -
bothDirections boolean true -

Returns: Vector3[]

the intersections of the line with the polygon sorted by distance from start


Static polygonPerimeter

polygonPerimeter(points: readonly ReadonlyVector3[]): number

Defined in src/util/GeometryUtils.ts:662

Computes the perimeter of a polygon

Parameters:

Name Type Description
points readonly ReadonlyVector3[] vertices of the polygon

Returns: number

the perimeter of the polygon


Static projectPointsOntoGivenPlane

projectPointsOntoGivenPlane(points: readonly ReadonlyVector3[], plane: object, nestedArray: boolean): number[] | ArrayPoint2[]

Defined in src/util/GeometryUtils.ts:308

Determine 2D coordinates of points relative to a 3D plane

Parameters:

points: readonly ReadonlyVector3[]

point locations in 3D space, will be skewed if not on the plane

plane: object

An object defining the center and normal of a plane. Typically the result of fitPlaneThroughPoints

Name Type
center Vector3
normal Vector3

Default value nestedArray: boolean= false

(optional) true if the returned coordinates should be in separate arrays

Returns: number[] | ArrayPoint2[]

2D coordinates of points either in separate or continuous array


Static projectPointsOntoPlane

projectPointsOntoPlane(points: Vector3[], normal?: Vector3, constant: number, center: Vector3‹›, nestedArray: boolean): number[] | any[]

Defined in src/util/GeometryUtils.ts:283

Determine 2D coordinates of points relative to a 3D plane

Parameters:

Name Type Default Description
points Vector3[] - point locations in 3D space, will be skewed if not on the plane
normal? Vector3 - (optional) normal vector defining the plane
constant number 0 (optional) constant defining the plane (distance from origin)
center Vector3‹› new Vector3() -
nestedArray boolean false (optional) true if the returned coordinates should be in separate arrays

Returns: number[] | any[]

2D coordinates of points either in separate or continuous array


Static projectedPointInPolygon3D

projectedPointInPolygon3D(point: Vector3, outline: readonly ReadonlyVector3[], holes: ReadonlyArray‹readonly ReadonlyVector3[]›, normal: ReadonlyVector3): boolean

Defined in src/util/GeometryUtils.ts:618

Test if a point on a polygon's plane lies within the polygon by projecting all points on a coordinate plane and applying a 2D test.

Parameters:

Name Type Default Description
point Vector3 - Point to test, should lie within the polygon's plane.
outline readonly ReadonlyVector3[] - Polygon points which get connected in order, doesn't have to be ccw (result for points on edges/vertices might change with winding direction).
holes ReadonlyArray‹readonly ReadonlyVector3[]› - -
normal ReadonlyVector3 this.computeNormalOfCCWPoints(outline) (optional) Polygon's normal (or some other vector not in the polygon's plane), sign doesn't matter.

Returns: boolean

true, if the point is in the polygon or on ([start, end[) an edge facing in a positive axis direction. false, if the point is outside or on ([start, end[) an edge facing in all negative axis direction. undefined (false or true), if the point is not on the polygon's plane.


Static projectedPointOnLineSegment

projectedPointOnLineSegment(point: ReadonlyVector3, start: ReadonlyVector3, end: ReadonlyVector3, epsilon: number): boolean

Defined in src/util/GeometryUtils.ts:896

Return true, if the projection of the point is on the line segment.

Parameters:

Name Type Description
point ReadonlyVector3 -
start ReadonlyVector3 -
end ReadonlyVector3 -
epsilon number If positive, points that are outside of the line segment by epsilon, will be considered inside. If false, points have to be inside the line segment by at least epsilon to be considered inside.

Returns: boolean


Static radiansToDegrees

radiansToDegrees(radians: number): number

Defined in src/util/GeometryUtils.ts:2579

Parameters:

Name Type
radians number

Returns: number


Static removeCollinearMiddlePoints

removeCollinearMiddlePoints(points: ReadonlyVector3[]): ReadonlyVector3[]

Defined in src/util/GeometryUtils.ts:1290

Finds maximum and minimum points (along x, if not possible y axis) and removes all points that are on the section between the two points. Used to clean inputs for canBeSeparated tests.

Parameters:

Name Type
points ReadonlyVector3[]

Returns: ReadonlyVector3[]


Static roundVecCoordinates

roundVecCoordinates(vec: object, digits: number, separator: string, preferZero: boolean): string

Defined in src/util/GeometryUtils.ts:60

Stringifies a vector after rounding its coordinates to x digits.

Parameters:

vec: object

vector to be rounded and stringified - can be a Vector2 oder Vector3

Name Type
x number
y number
z? number

digits: number

number of digits the number should have at most after the decimal point

Default value separator: string= ","

string which should be placed between two rounded coordinates (default: ",")

Default value preferZero: boolean= false

if a coordinate is close to zero, it gets set to zero (default: false)

Returns: string

rounded stringified vector


Static scaleLineAroundCenter

scaleLineAroundCenter(start: Vector3, end: Vector3, scaleFactor: number): void

Defined in src/util/GeometryUtils.ts:1998

Parameters:

Name Type
start Vector3
end Vector3
scaleFactor number

Returns: void


Static segmentSegmentIntersection3D

segmentSegmentIntersection3D(segmentA: Line3, segmentB: Line3, epsilon: number): Vector3 | null

Defined in src/util/GeometryUtils.ts:1035

Intersection of two segments with fixed lengths

Parameters:

Name Type Default
segmentA Line3 -
segmentB Line3 -
epsilon number maximumVectorEqualityDistance

Returns: Vector3 | null

the point where the segments intersect or null if they do not intersect


Static sideOfLine

sideOfLine(start: ReadonlyVector3, end: ReadonlyVector3, point: ReadonlyVector3): number

Defined in src/util/GeometryUtils.ts:1391

Parameters:

Name Type
start ReadonlyVector3
end ReadonlyVector3
point ReadonlyVector3

Returns: number


Static signedDoubledTriangleArea

signedDoubledTriangleArea(a: ReadonlyVector3, b: ReadonlyVector3, c: ReadonlyVector3): number

Defined in src/util/GeometryUtils.ts:253

Efficiently computes the signed, doubled area of a 2d triangle.

Parameters:

Name Type
a ReadonlyVector3
b ReadonlyVector3
c ReadonlyVector3

Returns: number


Static signedDoubledTriangleAreaArrays

signedDoubledTriangleAreaArrays(__namedParameters: [number, number], __namedParameters: [number, number], __namedParameters: [number, number]): number

Defined in src/util/GeometryUtils.ts:260

Efficiently computes the signed, doubled area of a 2d triangle.

Parameters:

Name Type
__namedParameters [number, number]
__namedParameters [number, number]
__namedParameters [number, number]

Returns: number


Static spaceEvenlyOnLine

spaceEvenlyOnLine(start: Vector3, end: Vector3, maxDistanceBetweenTwoPoints: number, minDistanceToStartEnd: number): Vector3[]

Defined in src/util/GeometryUtils.ts:379

Spaces points on a line.

The distance between two points will be maxDistanceBetweenTwoPoints except for the distance to start and end, which will be smaller or equal. Start and end will not be included in the result. To not include points near the start and end points, a minDistanceToStartEnd is needed

Example:

Given:    |            |   (with maxDistanceBetweenTwoPoints = 2)
Result:     |  |  |  |

Parameters:

Name Type Default Description
start Vector3 - The start point of the line in 3D
end Vector3 - The end point of the line in 3D
maxDistanceBetweenTwoPoints number - The maximum (and preferred) distance between two points
minDistanceToStartEnd number 0.001 The minimum distance of a point to the start or end point

Returns: Vector3[]

Points on the line, excluding start and end


Static spaceSectionsEvenlyOnLineWithStretch

spaceSectionsEvenlyOnLineWithStretch(start: Vector3, end: Vector3, width: number, enforceParity?: "even" | "odd"): Vector3[]

Defined in src/util/GeometryUtils.ts:409

Places sections between start and end. Sections have a width slightly higher than given width, so that there is no gap between sections. Will include start and end in result

Parameters:

Name Type
start Vector3
end Vector3
width number
enforceParity? "even" | "odd"

Returns: Vector3[]


Static toVector3

toVector3(vector2: ReadonlyVector2): Vector3

Defined in src/util/GeometryUtils.ts:2571

Parameters:

Name Type
vector2 ReadonlyVector2

Returns: Vector3


Static transformToTangentSpace

transformToTangentSpace(point: ReadonlyVector3, normal: Vector3, tangent: Vector3): Vector3

Defined in src/util/GeometryUtils.ts:827

Transforms a point to the new coordinate system given by normal and tangent (and the implicit bitangent) They are all normalized. TBN Space = the space of tangent, bitangent and normal, here often local space of surface. The z direction equals the normal, so if you set it to 0 after the transformation to TBN Space the point is in the plane. Likewise, the x axis is mapped to the tangent and the y-direction to the bitangent.

Parameters:

Name Type Description
point ReadonlyVector3 the point to be transformed. A new point is returned, does not change the given point
normal Vector3 -
tangent Vector3 -

Returns: Vector3


Static unprojectPointsFromPlane

unprojectPointsFromPlane(points2D: Vector3[], plane: object, nestedArray: boolean): number[] | ArrayPoint3[]

Defined in src/util/GeometryUtils.ts:338

Given a plane and 2D points on that plane, this method can reverse GeometryUtils.projectPointsOntoGivenPlane, back-projecting the points to their original 3D positions.

Parameters:

points2D: Vector3[]

plane: object

An object defining the center and normal of a plane. Typically the result of fitPlaneThroughPoints

Name Type
center Vector3
normal Vector3

Default value nestedArray: boolean= false

(optional) true if the returned coordinates should be in separate arrays

Returns: number[] | ArrayPoint3[]

3D coordinates of points either in separate or continuous array ToDo: having only one return type would be easier for typescript type checking


Static validateAfterCleansingAndRoundingPolygon

validateAfterCleansingAndRoundingPolygon(polygon: Polygon | MultiPolygon): boolean

Defined in src/util/GeometryUtils.ts:2665

Parameters:

Name Type
polygon Polygon | MultiPolygon

Returns: boolean

false if the given polygon has degenerated after rounding.


Static vectorIsInPlane

vectorIsInPlane(vector: Vector3, plane: IPlane, epsilon: number): boolean

Defined in src/util/GeometryUtils.ts:572

Parameters:

Name Type Default
vector Vector3 -
plane IPlane -
epsilon number maxDotProductPerpendicularDistance

Returns: boolean


Static vectorsCollinear

vectorsCollinear(v1: ReadonlyVector3, v2: ReadonlyVector3, allowReverse: boolean, tolerance: number): boolean

Defined in src/util/GeometryUtils.ts:2437

Check if two given vectors are collinear

Parameters:

Name Type Default Description
v1 ReadonlyVector3 - Vector 1
v2 ReadonlyVector3 - Vector 2
allowReverse boolean true Allow Vectors pointing in opposite directions
tolerance number maximumRotationEqualityAngle Tolerance between angles in radians

Returns: boolean


Static vectorsEqual

vectorsEqualU›(vectorA: U, vectorB: U, epsilon: number): boolean

Defined in src/util/GeometryUtils.ts:2036

Check equality of two Vector3s by comparing the distance with an epsilon

Type parameters:

U: ReadonlyVector3 | ReadonlyVector2

Parameters:

Name Type Default Description
vectorA U - first vector
vectorB U - second vector
epsilon number maximumVectorEqualityDistance threshold for equality

Returns: boolean

true when vectorA is equal to vectorB with respect to epsilon


Static vectorsPerpendicular

vectorsPerpendicular(vectorA: ReadonlyVector3, vectorB: ReadonlyVector3, epsilon: number): boolean

Defined in src/util/GeometryUtils.ts:1372

Dot product will be zero when they are perpendicular.

Parameters:

Name Type Default
vectorA ReadonlyVector3 -
vectorB ReadonlyVector3 -
epsilon number maxDotProductPerpendicularDistance

Returns: boolean