Last updated

API / geotoolkit3d / util / Math3DUtil / Math3DUtil

Class: Math3DUtil

util.Math3DUtil.Math3DUtil

This utility class provides functions to deal with common 3D related math problems.

Table of contents

Constructors
Methods

Contents

Constructors

new Math3DUtil()

new Math3DUtil()

Methods

angleToEuler

Static angleToEuler(axis, angle, result?): Euler

Casts angles between two Vector3's to euler angles
See http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToEuler/index.htm

Parameters

Name Type Description
axisVector3axis of rotation
anglenumberangle of rotation
Optional resultEulerthe euler angle that can be returned as a result. If left empty, a new one will be created, if passed as parameter, it will be updated with the result.

Returns

Euler

result


areVectorsAlmostEqual

Static areVectorsAlmostEqual(a, b, epsilon): boolean

Return true if the given vectors are almost equals, relative to epsilon.

Parameters

Name Type Description
aVector3the first vector
bVector3the second vector
epsilonnumberif the difference in coordinates is smaller than epsilon, they are considered equal.

Returns

boolean


computeCellVolume

Static computeCellVolume(c): number

Compute the volume of the cell formed by the given set of 8 corners. This is achieved by dividing the cell into 6 tetrahedrons and computing the volume of each of them separately. Note that the cell corners must be given in the right order, following this schema: 0 ------- 1 |\ |
| \ |
| 2 ------- 3 4 -|----- 5 | \ | \ | | | 6 ------- 7

Parameters

Name Type Description
cnumber[][]array[8] containing in each position the array [x,y,z] values of each corner

Returns

number

The volume of the tetrahedron


computeHeronArea

Static computeHeronArea(p0, p1, p2): number

Computes area of a triangle using Heron's formula.

This function computes the area of the triangle made by the three given points.
To do so, it uses the Heron's stabilized formula:

Let a, b, c the length of each edge of the triangle with (a >= b >= c).
∆ := √((a+(b+c)) (c-(a-b)) (c+(a-b)) (a+(b-c)))

See

Heron's formula

Parameters

Name Type Description
p0Vector2The first point
p1Vector2The second point
p2Vector2The third point

Returns

number

The area of the triangle


computeTetrahedronVolume

Static computeTetrahedronVolume(p1, p2, p3, p4): number

Compute the volume of the tetrahedron formed by the given set of 4 points. The tetrahedron can be irregular and of any shape. Formula based on https://en.wikipedia.org/wiki/Tetrahedron#Volume

Parameters

Name Type Description
p1number[]x,y,z values of a point
p2number[]x,y,z values of a point
p3number[]x,y,z values of a point
p4number[]x,y,z values of a point

Returns

number

The volume of the tetrahedron


containsBox

Static containsBox(box1, box2): boolean

Returns if box2 is contained inside box1

Parameters

Name Type Description
box1Box2First box
box2Box2Second box

Returns

boolean

box contained


createFitBox

Static createFitBox(box1, box2): Box2

Returns a THREE.Box2 of the space contained by both boxes

Parameters

Name Type Description
box1Box2First box
box2Box2Second box

Returns

Box2

overlapping space


crossProduct

Static crossProduct(a, b, result?): number[]

Compute cross product of two array-based points and return as a new array

Parameters

Name Type Description
anumber[]array-based point1
bnumber[]array-based point2
Optional resultnumber[]array-based vector result to avoid array creation

Returns

number[]

array-based vector cross product result


degreeToRadians

Static degreeToRadians(angle): number

Convert an angle in degree to radians.

Parameters

Name Type Description
anglenumberThe angle value in degree

Returns

number

The angle in radians


directionToEuler

Static directionToEuler(direction, up, result?): Euler

Casts euler angles from direction and up vectors
See https://stackoverflow.com/questions/21622956/how-to-convert-direction-vector-to-euler-angles

Parameters

Name Type Description
directionVector3direction vector
upVector3up vector
Optional resultEulereuler angles

Returns

Euler

result


dotProduct

Static dotProduct(a, b): number

Compute dot product of two array-based points

Parameters

Name Type Description
anumber[]array-based point1
bnumber[]array-based point2

Returns

number

dot product


getBoxToBoxMatrix

Static getBoxToBoxMatrix(src, dst): Matrix4

Creates a box to box transformation matrix

Parameters

Name Type Description
srcBox3Source box
dstBox3Target box

Returns

Matrix4


intersect

Static intersect(segment0p0, segment0p1, segment1p0, segment1p1): Vector2

Finds intersection between the given segments if there is any, null otherwise.

Parameters

Name Type Description
segment0p0Point | Vector2First segment first point
segment0p1Point | Vector2First segment second point
segment1p0Point | Vector2Second segment first point
segment1p1Point | Vector2Second segment second point

Returns

Vector2

The intersection point or null


intersectBox

Static intersectBox(b1, b2): boolean

Returns if the two boxes intersect

Parameters

Name Type Description
b1Box2First box
b2Box2Second box

Returns

boolean

box intersect


maxVector3

Static maxVector3(v1, v2): Vector3

Returns the maximum values of both vectors as a new vector

Parameters

Name Type Description
v1Vector3First vector
v2Vector3Second vector

Returns

Vector3

A new vector containing the maximum value for each component


minVector3

Static minVector3(v1, v2): Vector3

Returns the minimum values of both vectors as a new vector

Parameters

Name Type Description
v1Vector3First vector
v2Vector3Second vector

Returns

Vector3

A new vector containing the minimum value for each component


minimumCurvature

Static minimumCurvature(measuredDepth, inclination, azimuth, neg?): Object

This function turns measuredDepths inclinations and azimuth into XYZ deviation coordinates

Parameters

Name Type Description
measuredDepthnumber[]measured depth array
inclinationnumber[]inclination array
azimuthnumber[]azimuth array
Optional negbooleanresulting depths should be negative

Returns

Object

NameType
xnumber[]
ynumber[]
znumber[]

normal

Static normal(vertices, index0, index1, index2, normal?, nullvalue?): number[]

Computes the 'surface normal' of three vertex in the given array (at the given indices).
This will compute the normal vector of the plane made by the given 3 vertex.

Parameters

Name Type Description
verticesnumber[]The xyz values of the vertices
index0numberThe first vector index
index1numberThe second vector index
index2numberThe third vector index
Optional normalnumber[]Optional target array
Optional nullvaluenumberA nullvalue to ignore (cannot be NaN)

Returns

number[]

The resulting normal as an array of 3 components [x,y,z]


normalBufferAttribute

Static normalBufferAttribute(vertices, index0, index1, index2, normal?, nullvalue?): number[]

Computes the 'surface normal' of three vertex in the given array (at the given indices).
This will compute the normal vector of the plane made by the given 3 vertex.

Parameters

Name Type Description
verticesBufferAttribute | InterleavedBufferAttributeThe xyz values of the vertices
index0numberThe first vector index
index1numberThe second vector index
index2numberThe third vector index
Optional normalnumber[]Optional target array
Optional nullvaluenumberA nullvalue to ignore (cannot be NaN)

Returns

number[]

The resulting normal as an array of 3 components [x,y,z]


normalizeArray

Static normalizeArray(values, dststart?, dstend?, srcstart?, srcend?, nullvalue?, normednullvalue?): number[]

Creates a normalized version of the given array.
If given array's min&max are identical then the returned normalized values will be 'start + (end - start) / 2'.
If given srcstart is NaN the actual minimum will be used instead.
If given srcend is NaN the actual maximum will be used instead.

Parameters

Name Type Description
valuesnumber[]Values to normalize
Optional dststartnumberNormalization min value (ie normalized minimum value)
Optional dstendnumberNormalization max value (ie normalized maximum value)
Optional srcstartnumberOrigin min value, by default will be the array actual min
Optional srcendnumberOrigin max value, by default will be the array actual max
Optional nullvaluenumberA nullvalue to normalize differently, note that null and NaN are considered as nullvalue by default
Optional normednullvaluenumberThe normalized value to use in place of the nullvalue in the returned array

Returns

number[]

The normalized values


radiansToDegree

Static radiansToDegree(angle): number

Convert an angle in radians to degree.

Parameters

Name Type Description
anglenumberThe angle value in radians

Returns

number

The angle in degrees


resolveTransformMatrix3

Static resolveTransformMatrix3(src, dest): Matrix3

Returns transform matrix from three Vector3 to three Vector3

Parameters

Name Type Description
srcVector3[]three Vector3
destVector3[]three Vector3

Returns

Matrix3

this


resolveTransformMatrix4

Static resolveTransformMatrix4(src, dest): Matrix4

Returns transform matrix from four Vector3 to four Vector3

Parameters

Name Type Description
srcVector3[]four Vector3
destVector3[]four Vector3

Returns

Matrix4

this