Class: VectorArray

PD. VectorArray


new VectorArray()

A helper class for performing vector math using array-based points, directions, matrices and quaternions.

When using this class, spatial positions, direction vectors and surface normals can be stored as arrays of 3 scalar numeric values in the form [x,y,z]. As some external geometry libraries are based on [x,y,z] arrays, and the fact that GPU and vertex attribute buffers are all eventually just flat arrays, it is sometimes more convenient and efficient to work directly with vector arrays rather than having to constantly convert them to and from {x,y,z} point objects.

Thus, this helper class is intended to allow vector math to be performed directly on vector arrays. The intent is to closely replicate the API of the THREE.Vector3 class, but passing in an initial vector array as the first argument of all methods in order to receive the results, rather than updating this as THREE.js does.

Along with this class, you can use the PD.PlaneArray, PD.MatrixArray, PD.QuaternionArray, PD.AxisArray and PD.VolumeArray classes for a full suit of array-based vector math.

NOTE: Any Float32Array with at least three items in the same [x,y,z] format can also be used entirely interchangeably as both output or input in all vector array methods.

Author:
  • drajmarsh

Members


:Array.<number>

ORIGIN <static>

A useful definition of the global origin ([0,0,0]).

Type
  • Array.<number>

:Array.<number>

X_AXIS <static>

A useful definition of the global X axis ([1,0,0]).

Type
  • Array.<number>

:Array.<number>

Y_AXIS <static>

A useful definition of the global Y axis ([0,1,0]).

Type
  • Array.<number>

:Array.<number>

Z_AXIS <static>

A useful definition of the global Z axis ([0,0,1]).

Type
  • Array.<number>

Methods


add(out, v) <static>

Adds the first three components of v to out.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

v Array.<number>

The [x,y,z] vector array to add.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

addRandomness(out, factor) <static>

Applies the given randomisation factor to the given vector in each axis.

The factor argument determines the maximum amount of variation to apply to each axial component, where variation is taken to mean the difference between the highest and lowest possible random value.

As an example, if you have a point at the position [1000, 12000, 0], and you use a randomisation factor of 100, then the resulting X axis value could vary anywhere from 950 to 1050 (1050 - 950 = 100). Similarly, the Y axis value could vary anywhere from 11950 to 12050, and the Z axis value from -50 to 50.

This method uses the PD.Utils.randomNumber method so you can seed it if you need to generate repeatable number sequences.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to modify.

factor number

The randomisation amount to apply in model units.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

addScalar(out, scalar) <static>

Adds the given scalar value to the 3 components of out.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

scalar number

The scalar numeric value to add.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

addScaledVector(out, v, scalar) <static>

Add v multiplied by s to the three components of out.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

v Array.<number>

The [x,y,z] vector array to add.

scalar number

The scalar value to multiply v by.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

addVectors(out, a, b) <static>

Sets out to the addition of the vectors a and b.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

a Array.<number>

The first [x,y,z] vector array to add.

b Array.<number>

The second [x,y,z] vector array to add.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

angleBetweenPoints(p1, p2, p3) <static>

Calculates the unsigned 3D angle between a line passing through three positions, in radians.

   p1                 p3
     \_ _.-angle-._ _/
       \_         _/
         \_     _/
           \_ _/
            p2
Parameters:
Name Type Description
p1 Array.<number>

The first [x,y,z] coordinate array.

p2 Array.<number>

The shared second [x,y,z] coordinate array.

p3 Array.<number>

The third [x,y,z] coordinate array.

Returns:

Returns the 3D angle in the range 0.0 to PI, in radians.

Type
number

angleBetweenVectors(v1, v2) <static>

Calculates the 3D angle between the two vector arrays, in radians.

Parameters:
Name Type Description
v1 Array.<number>

The first [x,y,z] direction vector array.

v2 Array.<number>

The second [x,y,z] direction vector array.

Returns:

Returns the 3D angle, in radians.

Type
number

angleTo(v1, v2) <static>

Calculates the angle between the given vector arrays, in radians.

Parameters:
Name Type Description
v1 Array.<number>

The first [x,y,z] vector array to calculate angle from.

v2 Array.<number>

The second [x,y,z] vector array to calculate angle to.

Returns:

Returns the angle between vector array, in radians.

Type
number

applyMatrix3(out, mtx) <static>

Multiplies out by the given 3x3 column-major matrix m.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

mtx Array.<number>

The 3x3 matrix array to multiply out by.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

applyMatrix4(out, mtx) <static>

Multiplies out by the given 4x4 column-major matrix m.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

mtx Array.<number>

The 4x4 matrix array to multiply out by, based on THREE.matrix4#elements.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

applyQuaternion(out, qut) <static>

Multiplies out by the [x,y,z,w] quaternion q.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

qut Array.<number>

The [x,y,z,w] quaternion array to multiply out by.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

areaOfTriangle(p1, p2, p3) <static>

Calculate the area of a triangle joining the three given coordinates.

Parameters:
Name Type Description
p1 Array.<number>

The first [x,y,z] coordinate array of the triangle.

p2 Array.<number>

The second [x,y,z] coordinate array of the triangle.

p3 Array.<number>

The third [x,y,z] coordinate array of the triangle.

Returns:

Returns the surface area, in model units squared.

Type
number

bezier(out, startPt, ctrlPt1, ctrlPt2, endPt, t) <static>

Cubic Bezier interpolation between two 3D positions and governed by two control points.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] coordinate array to receive the calculated result.

startPt Array.<number>

The [x,y,z] coordinate array of the curve start point.

ctrlPt1 Array.<number>

The [x,y,z] coordinate array of the first control point.

ctrlPt2 Array.<number>

The [x,y,z] coordinate array of the second control point.

endPt Array.<number>

The [x,y,z] coordinate array of the curve end point.

t number

The fractional value between the two positions ( 0 to 1).

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

calcNormalFromIndexedPathNewellMethod(out, indices, vertices) <static>

Calculates a normal direction from multiple points along an indexed path using Newell's Method.

Rather than the path consisting of an array of coordinates, an indexed path consists of an array of indexes into a separate array of vertices.

Newell's Method provides a very robust way of computing an 'average' normal from points which may vary quite considerably from being coplanar. This make it great for curves or situations where you simply don't know beforehand their coplanarity.

       normal
           \
     [4]----\-----------[3]
      |      \  /\         \
      |       \/__+         \
      |        \ / \        [2]
      |         +---+       /
      |                    /
      |                   /
      |                  /
     [0]---------------[1]

If the path is invalid or the normal cannot be calculated, it will default to the +Z axis.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the calculated normal.

indices Array.<number>

An array of ordinal indexes to points within the vertices array.

vertices Array.<Array.<number>>

An array of [x,y,z] coordinate arrays.

Returns:

Returns the modified out [x,y,z] normal vector array.

Type
Array.<number>

calcNormalFromPath(out, path) <static>

Calculates a normal direction from multiple points along a path.

This method assumes that all points on the path are pretty close to co-planar and calculates the normal from the average cross-product of each set of three consecutive non-co-linear vertices. This is a robust way of dealing with paths where the first valid triangle may be concave whilst all the rest are convex.

       normal
           \
     [4]----\-----------[3]
      |  .   \  /\      '  \
      |    .  \/__+   '     \
      |      . \ / \'   _ . [2]
      |        '+---+ '     /
      |      .   '         /
      |   .         '     /
      |.              ' /
     [0]---------------[1]

If the path is invalid or the normal cannot be calculated, it will default to the +Z axis.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the calculated normal.

path Array.<number>

An array of [x,y,z] coordinate arrays defining a polyline or polygon.

Returns:

Returns the modified out [x,y,z] normal vector array.

Type
Array.<number>

calcNormalFromPathNewellMethod(out, path) <static>

Calculates a normal direction from a sequence of points on a path using Newell's Method.

Newell's Method provides a very robust way of computing an 'average' normal from points which may vary quite considerably from being coplanar. This make it great for curves or situations where you simply don't know beforehand their coplanarity.

       normal
           \
     [4]----\-----------[3]
      |      \  /\         \
      |       \/__+         \
      |        \ / \        [2]
      |         +---+       /
      |                    /
      |                   /
      |                  /
     [0]---------------[1]

If the path is invalid or the normal cannot be calculated, it will default to the +Z axis.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the calculated normal.

path Array.<number>

An array of [x,y,z] coordinate arrays defining a polyline or polygon.

Returns:

Returns the modified out [x,y,z] normal vector array.

Type
Array.<number>

calcNormalFromThreePoints(out, p1, p2, p3) <static>

Computes a normal direction from the three points of a triangle.

This is effectively the normalised cross product of the two vectors between three points.

                p2
                +
    normal     /
        ,  /\ /
         \/__/
          \ / \
           +------------------+ p3
         p1

NOTE: This method changes values within the out parameter, but it cannot and must not be the same array as p1, p2 or p3.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the calculated normal.

p1 Array.<number>

The first triangle vertex, given as a [x,y,z] coordinate array.

p2 Array.<number>

The second triangle vertex, given as a [x,y,z] coordinate array.

p3 Array.<number>

The third triangle vertex, given as a [x,y,z] coordinate array.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

calcNormalFromTwoPoints(out, p1, p2) <static>

Computes a normal direction for two points forming a line.

This method first computes a suitable third point offset from p2 in one of the major axis based on the vector between the two given points. It then computes the normal from those three points.

  3rd
  point
     +
      ,
       ,     normal
        ,  /\ /
         \/__/
          \ / \
        p1 +------------------+ p2

If the vector between p1->p2 is more horizontal that vertical (abs(v[z]) < 0.5), then the +Z axis is used for the third point. If it is more vertical and its magnitude in the X axis is less than in the Y, then the +Y axis is used for the third point. If its magnitude in the Y axis is less, then the +X axis is used for the third point.

NOTE: This method changes values within the out parameter, but it cannot and must not be the same array as p1, or p2.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the calculated normal.

p1 Array.<number>

The first triangle vertex, given as a [x,y,z] coordinate array.

p2 Array.<number>

The second triangle vertex, given as a [x,y,z] coordinate array.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

ceil(out) <static>

Converts each component of out to an integer using Math.ceil().

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to be converted.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

clamp(out, min, max) <static>

Limits the components of out to be within the given range.

NOTE: This method changes values within the out parameter and assumes that min < max in each component.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

min Array.<number>

The [x,y,z] vector array defining the minimum bounds.

max Array.<number>

The [x,y,z] vector array defining the maximum bounds.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

clampLength(out, min, max) <static>

Limits the length of out to be within the given range.

NOTE: This method changes values within the out parameter and assumes that minValue < maxValue.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to limit.

min number

The minimum length value.

max number

The maximum length value.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

clampScalar(out, min, max) <static>

Limits each component of out to be within the given range.

NOTE: This method changes values within the out parameter and assumes that minValue < maxValue.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

min number

The minimum bounds value.

max number

The maximum bounds value.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

clone(out) <static>

Creates a copy of the given vector array.

This method simply returns out.slice() but is included for API compatibility.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to clone.

Returns:

Returns a new copied vector array.

Type
number

closeTo(v1, v2 [, tolerance]) <static>

Determines whether each axial component of the two vector arrays are within the given tolerance value of each other.

This method checks the absolute value of the difference between each of the first three array items to determine if they are not greater than the given tolerance. If any are greater, it returns false. If none are greater, it returns true.

Parameters:
Name Type Argument Description
v1 Array.<number>

The first [x,y,z] vector array.

v2 Array.<number>

The second [x,y,z] vector array.

tolerance number <optional>

The tolerance value to use, defaults to 1e-6.

Returns:

Returns true if all three axis are within tolerance.

Type
boolean

computeMajorAxis(normal) <static>

Determines the axis of maximum distance (±1:X, ±2:±Y, ±3:±Z).

This method assumes that the given vector is a normalized direction rather than a 3D coordinate.

                  Y
                 +
      Z         /
       +       /
        ,  /\ /
         \/__/___
          \ / \ /
           +------+ X
         p1
Parameters:
Name Type Description
normal Array.<number>

The [x,y,z] direction vector to test.

Returns:

Returns the appropriate axis (±1:X, ±2:±Y, ±3:±Z).

Type
number

computePathArea(contours, polygonal) <static>

Calculate the area of one or more closed shapes.

The path argument can be given as as either as a single contour defining the outer boundary of the shape or as multiple contours. When the path contains multiple contours, set the polygonal argument to true to define each subsequent contour as a hole within the boundary contour (the default) whose area is SUBTRACTED from the outer boundary. If set to false, each subsequent contour is considered an additional 'island' whose area is ADDED to the outer boundary.

Parameters:
Name Type Description
contours Array.<Array.<number>> | Array.<Array.<Array.<number>>>

One or more arrays of [x,y,z] coordinate arrays defining a closed polygon/polyline.

polygonal boolean

If true, any subsequent contours in the path define holes in the first one, defaults to true.

Returns:

Returns the surface area, in model units squared.

Type
number

computePathCenter(out, path) <static>

Calculate the geometric center of the given path.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] coordinate array to receive the result.

path Array.<Array.<number>>

An array of [x,y,z] coordinate arrays defining a closed polygon.

Returns:

Returns the surface area, in model units squared.

Type
number

concaveHullXY(points, concavity, lengthThreshold) <static>

Calculates the concave hull of an array of vector arrays in the XY plane.

NOTE: This method uses vector arrays in the form [x,y[,z]] rather than point objects. If you need to process an array of THREE.Vector3, THREE.Vector2 or PD.Point objects, use the PD.Utils.concaveHullXY method instead.

The concavity arguments is a relative measure of concavity, where a value of 1.0 results in a relatively detailed shape, and Infinity results in a convex hull. You can use values lower than 1, but they can produce pretty crazy shapes.

When a segment length is less than lengthThreshold, it stops being considered for further decomposition. Higher values result in a simpler shape.

The return value is an ordered array of points that define the line of the concave hull around the point cloud.

This uses concaveman (https://github.com/mapbox/concaveman), a fast algorithm for finding concave and convex hulls in 2D points.

Parameters:
Name Type Description
points Array.<number>

An array of [x, y[, z]] vector arrays.

concavity number

A relative measure of concavity, defaults to 1.0.

lengthThreshold number

The minimum point radius to consider.

Returns:

Returns and array of 2D points.

Type
Array.<number>

copy(out, v) <static>

Copies the first three components of v to out.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

v Array.<number>

The [x,y,z] vector array to copy from.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

copyAtOffset(out, v [, offset]) <static>

Copies the first three components of v to out with the given offset.

The optional offset argument allows you to copy the three values to a different part of the out array. It defines the index in the output array at which to start copying the three values.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Argument Description
out Array.<number>

The [x,y,z] vector array to receive the result.

v Array.<number>

The [x,y,z] vector array to copy from.

offset number <optional>

The array index at which to copy the values, defaults to 0.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

copyFromPoint(out, pnt) <static>

Copies the x, y and z components of p1 to out.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

pnt object

The point-like {x,y,z} object to copy components from.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

create(x, y, z) <static>

Creates a new 3D vector array with the given x, y and z components.

This method offers some flexibility in terms of the arguments it accepts. You can provide 3 separate numeric values, an [x,y,z] vector array, a point-like {x,y,z} object or even no arguments at all to create a zero vector.

Parameters:
Name Type Description
x number | Array.<number>

The X-axis component, an [x,y,z] vector array, or zero if not defined.

y number

The Y-axis component, or zero if not defined.

z number

The Z-axis component, or zero if not defined.

Returns:

Returns a new [x,y,z] vector array.

Type
Array.<number>

cross(out, v) <static>

Crosses out with v and copies the result to out.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

v Array.<number>

The [x,y,z] vector array to cross out with.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

crossProductFromThreePoints(out, p1, p2, p3) <static>

Computes the cross product of the three points of a triangle.

This method first computes the vectors p1->p2 and p1->p3, then uses PD.VectorArray.crossVectors to compute the cross product.

 cross
 product
     +          p2
      ,         +
       ,       /
        ,  /\ /
         \/__/
          \ / \
           +------------------+ p3
         p1

NOTE: This method changes values within the out parameter, but it cannot and must not be the same array as p1, p2 or p3.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the calculated normal.

p1 Array.<number>

The first triangle vertex, given as a [x,y,z] coordinate array.

p2 Array.<number>

The second triangle vertex, given as a [x,y,z] coordinate array.

p3 Array.<number>

The third triangle vertex, given as a [x,y,z] coordinate array.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

crossVectors(out, v1, v2) <static>

Sets out to the cross product of two 3D vector arrays.

NOTE: This method changes values within the out parameter, however it is safe to use the same array as a or b.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

v1 Array.<number>

The first [x,y,z] vector array.

v2 Array.<number>

The second [x,y,z] vector array.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

distanceInVectorDirection(from, direction, to) <static>

Calculates the relative distance along a given vector given a 3D point.

This method is used when dragging something that is restricted to a given vector. It uses the Pythagorean theorem to determine the distance of the closest point between the given 3D position and the ray.

Parameters:
Name Type Description
from Array.<number>

The reference [x,y,z] coordinate array to calculate distance from.

direction Array.<number>

The normalised [x,y,z] vector array of the measurement direction.

to Array.<number>

The [x,y,z] coordinate array of the position to check.

Returns:

Returns the distance along the given vector.

Type
number

distanceTo(p1, p2) <static>

Calculate the distance between the two given coordinates.

Parameters:
Name Type Description
p1 Array.<number>

The first [x,y,z] coordinate array.

p2 Array.<number>

The second [x,y,z] coordinate array.

Returns:

Returns the distance between the coordinates, in model units.

Type
number

distanceToSquared(p1, p2) <static>

Calculate the squared distance between the two given coordinates.

Parameters:
Name Type Description
p1 Array.<number>

The first [x,y,z] coordinate array.

p2 Array.<number>

The second [x,y,z] coordinate array.

Returns:

Returns the squared distance.

Type
number

distanceXY(p1, p2) <static>

Calculate the distance between the two given coordinates in the XY plane only.

Parameters:
Name Type Description
p1 Array.<number>

The first [x,y,z] coordinate array.

p2 Array.<number>

The second [x,y,z] coordinate array.

Returns:

Returns the distance between the coordinates in the XY plane, in model units.

Type
number

distanceXZ(p1, p2) <static>

Calculate the distance between the two given coordinates in the XZ plane only.

Parameters:
Name Type Description
p1 Array.<number>

The first [x,y,z] coordinate array.

p2 Array.<number>

The second [x,y,z] coordinate array.

Returns:

Returns the distance between the coordinates in the XZ plane, in model units.

Type
number

distanceYZ(p1, p2) <static>

Calculate the distance between the two given coordinates in the YZ plane only.

Parameters:
Name Type Description
p1 Array.<number>

The first [x,y,z] coordinate array.

p2 Array.<number>

The second [x,y,z] coordinate array.

Returns:

Returns the distance between the coordinates in the YZ plane, in model units.

Type
number

divide(out, v) <static>

Divided the components of out by v.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

v Array.<number>

The [x,y,z] vector array to divide by.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

divideScalar(out, scalar) <static>

Divides the components of out by the given scalar value.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

scalar number

The scalar numeric value to divide by.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

dot(v1, v2) <static>

Calculates the dot product of two vector arrays.

Parameters:
Name Type Description
v1 Array.<number>

The first [x,y,z] vector array.

v2 Array.<number>

The second [x,y,z] vector array.

Returns:

Returns the dot product of the two vectors.

Type
number

equals(v1, v2) <static>

Determines if the two vector arrays have exactly the same values.

This method checks each of the X, Y and Z axis components to see if they are exactly equal (using the === operator). If you want to use some tolerance range, use the PD.VectorArray.closeTo or PD.VectorArray.manhattanDistanceTo methods instead.

Parameters:
Name Type Description
v1 Array.<number>

The first [x,y,z] vector array.

v2 Array.<number>

The second [x,y,z] vector array.

Returns:

Returns true if they are the same.

Type
boolean

fitExtents(min, max, pt) <static>

Extends the min and max vector arrays to fit the given pt.

NOTE: This method may change values within the min and max parameters.

Parameters:
Name Type Description
min Array.<number>

The [x,y,z] coordinate array defining the minimum bounds.

max Array.<number>

The [x,y,z] coordinate array defining the maximum bounds.

pt Array.<number>

The [x,y,z] coordinate array to extend bounds to include.


fitExtentsToPoints(min, max, points) <static>

Extends the min and max vector arrays to fit all of the given points.

NOTE: This method may change values within the min and max parameters.

Parameters:
Name Type Description
min Array.<number>

The [x,y,z] coordinate array defining the minimum bounds.

max Array.<number>

The [x,y,z] coordinate array defining the maximum bounds.

points Array.<Array.<number>>

An array of one or more [x,y,z] coordinate arrays to extend bounds to.


fitExtentsToSphere(min, max, center, radius) <static>

Extends the min and max vector arrays to fit a sphere.

NOTE: This method may change values within the min and max parameters.

Parameters:
Name Type Description
min Array.<number>

The [x,y,z] coordinate array defining the minimum bounds.

max Array.<number>

The [x,y,z] coordinate array defining the maximum bounds.

center Array.<number>

The [x,y,z] coordinate array of the sphere center.

radius Array.<number>

The radius of the sphere.


floor(out) <static>

Converts each component of out to an integer using Math.floor().

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to be converted.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

getComponent(out, index) <static>

Retrieves the value of the vector array at component index.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to get results from.

index number

The index of the component to get (0 to 2).

Returns:

Returns the value at the given component index.

Type
number

intersectLineSegmentsXY(p1, p2, p3, p4 [, out]) <static>

Calculates if the line segment p1->p2 intersects the line segment p3->p4 in the XY plane.

If the two lines intersect, this method will return true. If an out array is given, it will also set its values to the intersection point. If no intersection is found within the lengths of either line, this method returns false and not set any values in the out argument.

As this is a 2D intersection test, the Z value of the intersection point is computed by interpolating the intersection point between the Z values of p3->p4. This may not always be the most appropriate option, however it can be surprisingly accurate in many common situations. That is why it is done, but you are free to ignore or override the computed Z value.

Parameters:
Name Type Argument Description
p1 Array.<number>

The first point on the first line segment.

p2 Array.<number>

The second point on the first line segment.

p3 Array.<number>

The first point on the second line segment.

p4 Array.<number>

The second point on the second line segment.

out Array.<number> <optional>

An optional point to receive the intersection.

Returns:

Returns true if segments intersect, and out modified.

Type
boolean

isInsideTriangle(pt, v1, v2, v3, normal) <static>

Returns true if the given 3D point lies within the specified triangle.

This calculation assumes that the hit point and all triangle vertices lie on the same plane, so it is relatively fast as the normal is already given.

Parameters:
Name Type Description
pt Array.<number>

The intersection [x,y,z] coordinate array to test.

v1 Array.<number>

The first triangle [x,y,z] coordinate array.

v2 Array.<number>

The second triangle [x,y,z] coordinate array.

v3 Array.<number>

The third triangle [x,y,z] coordinate array.

normal Array.<number>

The plane normal [nx,ny,nz] vector array.

Returns:

Returns true if the pt is inside the triangle.

Type
boolean

length(v) <static>

Computes the magnitude of the given vector.

Parameters:
Name Type Description
v Array.<number>

The [x,y,z] vector array to compute.

Returns:

Returns the vector length.

Type
number

lengthSq(v) <static>

Computes the square of the magnitude of the given vector.

Parameters:
Name Type Description
v Array.<number>

The [x,y,z] vector array to compute.

Returns:

Returns the square of the vector length.

Type
number

lerp(out, v, t) <static>

Linearly interpolates along the vector's length.

NOTE: This method changes values within the out parameter, however it is safe to use the same array as v to change it in-place.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the calculated result.

v Array.<number>

The [x,y,z] vector array to interpolate.

t number

The fractional value along the vector (0 to 1).

Returns:

Returns the resulting out vector.

Type
Array.<number>

lerpVectors(out, v1, v2, t) <static>

Linearly interpolates between two 3D positions.

NOTE: This method changes values within the out parameter, however it is safe to use the same array as v1 or v2 to change it in-place.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] coordinate array to receive the calculated result.

v1 Array.<number>

The first [x,y,z] coordinate array.

v2 Array.<number>

The second [x,y,z] coordinate array.

t number

The fractional value between the two positions ( 0 to 1).

Returns:

Returns the resulting out vector.

Type
Array.<number>

manhattanDistanceTo(p1, p2) <static>

Computes the Manhattan distance between the two coordinates.

Parameters:
Name Type Description
p1 Array.<number>

The first [x,y,z] coordinate array.

p2 Array.<number>

The second [x,y,z] coordinate array.

Returns:

Returns the Manhattan distance.

Type
number

manhattanLength(v) <static>

Computes the Manhattan length of the given.

Parameters:
Name Type Description
v Array.<number>

The [x,y,z] vector array to compute.

Returns:

Returns the Manhattan distance.

Type
number

max(out, v) <static>

Sets out to the maximum of its component compared to v.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

v Array.<number>

The [x,y,z] vector array to check maximum values of.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

maxOf(out, args) <static>

Sets out to the maximum components of each of the given vectors.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Argument Description
out Array.<number>

The [x,y,z] vector array to receive the result.

args Array.<number> <repeatable>

Two or more [x,y,z] vector array to get maximum values of.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

min(out, v) <static>

Sets out to the minimum of its components compared to v.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

v Array.<number>

The [x,y,z] vector array to check minimum values of.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

minOf(out, args) <static>

Sets out to the minimum components of each of the given vectors.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Argument Description
out Array.<number>

The [x,y,z] vector array to receive the result.

args Array.<number> <repeatable>

Two or more [x,y,z] vector array to get minimum values of.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

multiply(out, v) <static>

Multiplies the components of out by v.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

v Array.<number>

The [x,y,z] vector array to multiply by.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

multiplyScalar(out, scalar) <static>

Multiplies the components of out by the given scalar value.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

scalar number

The scalar numeric value to multiply by.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

multiplyVectorByScalar(out, v, scalar) <static>

Sets out to the multiplication of a vector v and scalar scale.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

v Array.<number>

The [x,y,z] vector array to be multiplied.

scalar number

The scalar numeric value to multiply by.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

multiplyVectors(out, a, b) <static>

Sets out to the multiplication of the vectors a and b.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

a Array.<number>

The first [x,y,z] vector array to multiply.

b Array.<number>

The second [x,y,z] vector array to multiply.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

negate(out [, v]) <static>

Reverses the sign of each component of a vector array.

NOTE: This method changes values within the out parameter, however it is safe to use the same array as v or simply give one argument to change it in-place.

Parameters:
Name Type Argument Description
out Array.<number>

The [x,y,z] vector array to receive the result.

v Array.<number> <optional>

The [x,y,z] vector array to negate, set to out if not supplied.

Returns:

Returns the modified out 3D vector array.

Type
Array.<number>

normalize(out [, v]) <static>

Resizes a vector array to unit length (len == 1.0).

NOTE: This method changes values within the out parameter, however it is safe to use the same array as v or simply give one argument to change it in-place.

Parameters:
Name Type Argument Description
out Array.<number>

The [x,y,z] vector array to receive the result.

v Array.<number> <optional>

The [x,y,z] vector array to normalize, set to out if not supplied.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

normalizedVectorBetween(out, p1, p2) <static>

Computes the direction vector between two points and normalises it to unit length (len := 1.0).

NOTE: This method changes values within the out parameter, however it is safe to use the same array as p1 of p2 to change it in-place.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

p1 Array.<number>

The [x,y,z] coordinate array of the starting point.

p2 Array.<number>

The [x,y,z] coordinate array of the ending point.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

pointCloud_Fibonacci( [num_pts] [, radius] [, dome]) <static>

Generates a set of points distributed over the surface of a sphere based on a Fibonacci spiral.

The Fibonacci spiral gives a reasonable approximation of equally-spaced points over a sphere or hemisphere.

Parameters:
Name Type Argument Description
num_pts number <optional>

The number of hemispherical points to generate (4 to 2048), defaults to 48.

radius number <optional>

The radius of the point distribution, defaults to 1.

dome boolean <optional>

Generate a hemisphere instead of a sphere, defaults to false.

Returns:

Returns an array of [x,y,z] vector arrays.

Type
Array.<Array.<number>>

pointCloud_Geodesic( [detail] [, radius] [, dome]) <static>

Generates a set of 3D geodesic points distributed over the surface of a sphere.

This distribution is generated by progressively dividing into spherical triangles and then inflating the interpolated points to the radius of the sphere.

Parameters:
Name Type Argument Description
detail number <optional>

The level of triangulation (0 to 32), defaults to 6.

radius number <optional>

The radius of the point distribution, defaults to 1.

dome boolean <optional>

Generate a hemisphere instead of a sphere, defaults to false.

Returns:

Returns an array of [x,y,z] vector arrays.

Type
Array.<Array.<number>>

pointCloud_LatLong( [latRings] [, lngRings] [, radius] [, dome]) <static>

Generates a set of [x,y,z] coordinates distributed equally by angle over the surface of a sphere.

Sphere

For a sphere, the north and south poles are generated as the last two points in the point array. Points are added in concentric latitudinal rings starting at the equator and running towards North and South in alternate rings. Thus, the first lngRings points will be for the equator. The next lngRings points will be for the latitude one increment up from the equator towards the north pole. The next lngRings points will be for the latitude one increment down from the equator towards the south pole, and so on. The total number of points should therefore be (2 * latRings * lngRings) + 2.

            Second last point
              , - ~ ' ~ - ,
          , ' - - - - - - - ' ,     - - - 4th ring
        ,                       ,
       , - - - - - - - - - - - - ,  - - - 2nd ring
      ,             |             ,
      + - - - - - - + - - - - - - + - - - 1st ring
      ,             |             ,
       , - - - - - - - - - - - - ,  - - - 3rd ring
        ,                       ,
          , - - - - - - - - - ,     - - - 5th ring
            ' - , _ _ _ , - '
                Last point

Dome

For a dome, the north pole will be the very last point in the array. Points are added in concentric latitudinal rings starting at the equator and running upwards towards the North pole. Thus, the first lngRings points will be for the equator. The next lngRings points will be for the latitude one increment up from the equator. The next lngRings points will be for the latitude another increment up from the last one, and so on. The total number of points should therefore be (latRings * lngRings) + 2.

                Last point
              , - ~ ' ~ - ,
          , ' - - - - - - - ' ,     - - - 3rd ring
        ,                       ,
       , - - - - - - - - - - - - ,  - - - 2nd ring
      ,             |             ,
      + - - - - - - + - - - - - - + - - - 1st ring
Parameters:
Name Type Argument Description
latRings number <optional>

The number of longitudinal divisions (1 to 178), defaults to 8.

lngRings number <optional>

The number of latitudinal divisions (3 to 360), defaults to 16.

radius number <optional>

The radius of the point distribution, defaults to 1.

dome boolean <optional>

Generate a hemisphere instead of a sphere, defaults to false.

Returns:

Returns an array of [x,y,z] vector arrays.

Type
Array.<Array.<number>>

pointCloud_Random( [num_pts] [, radius] [, dome]) <static>

Generates a set of completely random 3D coordinates over the surface of a sphere.

To ensure a valid distribution, 6 core points are added to form a random tetrahedron, which is why the minimum number of points is 6.

Parameters:
Name Type Argument Description
num_pts number <optional>

The number of random points to generate (6+), defaults to 48.

radius number <optional>

The radius of the point distribution, defaults to 1.

dome boolean <optional>

Generate a hemisphere instead of a sphere, defaults to false.

Returns:

Returns an array of [x,y,z] vector arrays.

Type
Array.<Array.<number>>

polarPoints_Fibonacci( [num_pts] [, dome]) <static>

Generates a set of [azi,alt] polar coordinates from a Fibonacci spiral over the surface of a dome or sphere.

Polar coordinates are useful for analysing a spherical surface as if it were a flat plane, or for generating spherical surfaces with algorithmically varying radii.

The Fibonacci spiral gives a reasonable approximation of equally-spaced points over a sphere or hemisphere.

Parameters:
Name Type Argument Description
num_pts number <optional>

The number of hemispherical points to generate (4 to 2048), defaults to 48.

dome boolean <optional>

Generate a hemisphere instead of a sphere, defaults to false.

Returns:

Returns an array of [azi,alt] polar arrays.

Type
Array.<Array.<number>>

polarPoints_Geodesic( [detail] [, dome]) <static>

Generates a set of [azi,alt] polar coordinates for geodesic points distributed over the surface of a dome or sphere.

Polar coordinates are useful for analysing a spherical surface as if it were a flat plane, or for generating spherical surfaces with algorithmically varying radii.

This distribution is generated by progressively dividing into spherical triangles and then inflating the interpolated points to the radius of the sphere.

Parameters:
Name Type Argument Description
detail number <optional>

The level of triangulation (0 to 32), defaults to 6.

dome boolean <optional>

Generate a hemisphere instead of a sphere, defaults to false.

Returns:

Returns an array of [azi,alt] polar arrays.

Type
Array.<Array.<number>>

polarPoints_Random( [num_pts] [, dome]) <static>

Generates a set of completely random 3D coordinates over the surface of a sphere. Generates a set of completely random [azi,alt] polar coordinates in the range 0 to 360 for azimuth and either 0 to 90 (dome) or -90 to 90 (sphere) for altitude.

To ensure a valid distribution, 6 core points are added to form a random tetrahedron, which is why the minimum number of points is 6.

Parameters:
Name Type Argument Description
num_pts number <optional>

The number of random polar points to generate (6+), defaults to 48.

dome boolean <optional>

Generate a hemisphere instead of a sphere, defaults to false.

Returns:

Returns an array of [x,y,z] vector arrays.

Type
Array.<Array.<number>>

polarToCartesian(azi, alt) <static>

Converts 2D polar coordinates to 3D cartesian coordinates.

Parameters:
Name Type Description
azi number

The horizontal azimuth angle, in radians anti-clockwise from +X axis.

alt number

The vertical angle, in radians above the horizontal plane.

Returns:

Returns a 3D [x,y,z] coordinate array.

Type
Array.<number>

polarToStereo(azi, alt) <static>

Converts spherical polar coordinates to 2D stereographic coordinates.

Parameters:
Name Type Description
azi number

The horizontal azimuth angle, in radians anti-clockwise from +X axis.

alt number

The vertical angle, in radians above the horizontal plane.

Returns:

Returns a 2D [x,y] coordinate array.

Type
Array.<number>

random(out) <static>

Generate a set of random random values between 0 and 1.

This method will set the first three items in the vector array to a decimal value between 0 and 1, representing the representing the X, Y and Z axis components. This method uses Math.random().

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

randomColor( [modifier] [, result]) <static>

Returns a random color array.

This method will set the first three items in the color array to a decimal value between 0 and 1, representing the red, green and blue components of the color. This method uses Math.random.

Parameters:
Name Type Argument Description
modifier number <optional>

A dark/light modifier value (-0.9 to 0.9).

result Array.<number> <optional>

An optional array to receive the randomised results.

Returns:

Returns the given array or a new array with a random colours assigned.

Type
Array.<number>

randomDirection(out) <static>

Sets out to a random normalized direction vector.

This method uses a randomisation method designed to produce better spherical distributions of points. it will set the first three items in the vector array to a decimal value between 0 and 1, representing the X, Y and Z axis components.

This method uses the PD.Utils.randomNumber method so you can seed it if you need to generate repeatable number sequences.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

rotateBySphericalCoordinates(out, about, azi, alt) <static>

Rotates the out point around about by the given angles.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The point to rotate.

about Array.<number>

The [x,y,z] point about which to rotate.

azi number

The horizontal azimuth angle, in radians anti-clockwise from +X axis.

alt number

The vertical angle, in radians above the horizontal plane.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

rotatePointAroundAxis(out, origin, axis, angle) <static>

Rotates a coordinates array around the given origin/axis by the given angle.

Don't use this method to rotate multiple points by the same values as it initialises a quaternion on every call. Use instead the PD.VectorArray.rotatePointsAroundAxis method.

The origin is effectively the point about which the rotation should take place. It is subtracted from the point prior to the rotation, then added back afterwards.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] coordinate array defining the point to rotate.

origin Array.<number>

The [x,y,z] coordinate array defining the origin point to rotate about.

axis Array.<number>

The [x,y,z] vector array defining the axial vector to rotate around.

angle number

The angle of rotation, in radians.

Returns:

Returns out set to the rotated position.

Type
Array.<number>

rotatePointsAroundAxis(points, origin, axis, angle) <static>

Rotates an array of coordinate vectors around the given origin/axis by the given angle.

The origin is effectively the point about which the rotation should take place. It is subtracted from the point prior to the rotation, then added back afterwards.

Parameters:
Name Type Description
points Array.<Array.<number>>

An array of one or more [x,y,z] coordinate arrays to rotate.

origin Array.<number>

The [x,y,z] coordinate array defining the origin point to rotate about.

axis Array.<number>

The [x,y,z] vector array defining the axial vector to rotate around.

angle number

The angle of rotation, in radians.

Returns:

Returns the modified points array.

Type
Array.<Array.<number>>

round(out) <static>

Rounds each component of out to an integer using Math.round().

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to be rounded.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

roundToZero(out) <static>

Rounds each component of out to an integer towards zero (up if negative, down if positive).

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to be rounded.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

scale(out, v, scale) <static>

Multiplies each component of a vector by the given scale factor.

NOTE: This method changes values within the out parameter, however it is safe to use the same array as v to change it in-place.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the calculated result.

v Array.<number>

The [x,y,z] vector array to scale.

scale number | Array.<number>

The scale factor to multiply by, or an [sx,sy,sz] vector array.

Returns:

Returns the resulting out vector.

Type
Array.<number>

set(out, x, y, z) <static>

Sets the new values for a vector to the given components.

This method offers some flexibility in terms of the arguments it accepts. You can provide 3 separate numeric values or just a single [x,y,z] vector array, a point-like {x,y,z} object or even no arguments at all to create a zero vector.

If you are setting 3 component values, you can optionally use the setComponents() method instead which is a little faster as it does no type checking. If you definitely know that you have a vector array, then you can use the copy() method or, if a vector object, the copyFromPoint() method.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

x number

Either the X-axis component, a [x,y,z] vector array, a {x,y,z} vector object, or zero if not defined.

y number

The Y-axis component, or zero if not defined.

z number

The Z-axis component, or zero if not defined.

Returns:

Returns the resulting out [x,y,z] vector array.

Type
Array.<number>

setComponent(out, index, value) <static>

Set the vector array component index to the given scalar value.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

index number

The index of the component to set (0 to 2).

value number

The new value for the component index.

Returns:

Returns the out [x,y,z] vector array.

Type
Array.<number>

setComponents(out, x, y, z) <static>

Sets the vector to the given components.

This method differs from the set() method in that you must provide the 3 components as separate numeric values. It does not perform any type checking, which makes it a bit faster in situations where you can reliably provide separate component values.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

x number

The X-axis component, or zero if not defined.

y number

The Y-axis component, or zero if not defined.

z number

The Z-axis component, or zero if not defined.

Returns:

Returns the resulting out [x,y,z] vector array.

Type
Array.<number>

setLength(out, length) <static>

Sets a new magnitude for the out vector.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to set.

length number

The new magnitude of the vector array.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

setScalar(out, scalar) <static>

Set the three vector array components to the given scalar value.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

scalar number

The number to set each component to.

Returns:

Returns the out [x,y,z] vector array.

Type
Array.<number>

setX(out, x) <static>

Set the X-axis vector array component to the given scalar value.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

x number

The new value for the X-axis component.

Returns:

Returns the out [x,y,z] vector array.

Type
Array.<number>

setY(out, y) <static>

Set the Y-axis vector array component to the given scalar value.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

y number

The new value for the Y-axis component.

Returns:

Returns the out [x,y,z] vector array.

Type
Array.<number>

setZ(out, y) <static>

Set the Z-axis vector array component to the given scalar value.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

y number

The new value for the Z-axis component.

Returns:

Returns the out [x,y,z] vector array.

Type
Array.<number>

slerpVectors(out, v1, v2, t) <static>

Spherical linear interpolation between two 3D positions.

NOTE: This method changes values within the out parameter, however it is safe to use the same array as v1 or v2 to change it in-place.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] coordinate array to receive the calculated result.

v1 Array.<number>

The first [x,y,z] coordinate array.

v2 Array.<number>

The second [x,y,z] coordinate array.

t number

The fractional value between the two positions ( 0 to 1).

Returns:

Returns the resulting out vector.

Type
Array.<number>

sortSegmentsIntoPaths(segments) <static>

Converts an unordered list of [start,end] line segments into one or more connected paths or loops.

Each segment must be an array of two [x,y,z] vertexes defining its start and end 3D positions. For this method to work, each 3D spatial position needs to be a unique array - meaning that if you have two segments with coincident start or end points, they must be the same array instance rather than two separate arrays with the same values. You can use a PD.Indexer to ensure that this is the case.

This method is mainly used when cutting or slicing shapes to assemble the cut edges that lie on a cutting plane into faces or profiles.

Parameters:
Name Type Description
segments Array.<Array.<number>>

An array of unordered [start,end] line fragments.

Returns:

Returns one or more assembled face loops.

Type
Array.<Array.<number>>

sphericalInterpolate(v1, v2) <static>

Interpolates between two normalised spherical coordinates sitting on the surface of a unit sphere.

Parameters:
Name Type Description
v1 Array.<number>

The first spherical coordinate as a normalised [x,y,z] vector array.

v2 Array.<number>

The second spherical coordinate as a normalised [x,y,z] vector array.

Returns:

Returns the interpolated point as a new normalised [x,y,z] vector array.

Type
Array.<number>

stereoToCartesian(stereo) <static>

Converts 2D coordinates to cartesian relative to the center.

Parameters:
Name Type Description
stereo Array.<number>

An [azi,alt] polar position array.

Returns:

Returns an [x,y,z] coordinate array.

Type
Array.<number>

sub(out, v) <static>

Subtracts the first three components of v from out.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

v Array.<number>

The [x,y,z] vector array to subtract.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

subScalar(out, scalar) <static>

Subtracts the given scalar value from the 3 components of out.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

scalar number

The scalar numeric value to subtract.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

subVectors(out, a, b) <static>

Sets out to the subtraction of the vectors a and b.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to receive the result.

a Array.<number>

The [x,y,z] vector array to subtract from.

b Array.<number>

The [x,y,z] vector array to subtract.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

swapAxis(out, axis) <static>

Swaps the component values of a point in plane of the given axis.

To swap the Y and Z axis, use 1:PD.AXIS.X_POS or -1:PD.AXIS.X_NEG as the argument. To swap the X and Y axis, use 3:PD.AXIS.Z_POS or -3:PD.AXIS.Z_NEG as the argument. To swap the X and Z axis, use 2:PD.AXIS.Y_POS or -2:PD.AXIS.Y_NEG as the argument. To swap the axis back, simply use the same call with the same axis argument.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to modify.

axis PD.AXIS

The axis of the plane to swap components in.

Returns:

Returns the out [x,y,z] vector array.

Type
Array.<number>

toSphericalCoordinates(vec) <static>

Calculates the azimuth and altitude angle of a direction vector and returns an [azi,alt] array, in radians.

The azimuth angle is returned in radians CCW from the +X axis, and the altitude angle is in radians above the horizontal.

Parameters:
Name Type Description
vec Array.<number>

The [x,y,z] direction vector array.

Returns:

Returns the spherical angles as an [azi,alt,radius] array, in radians.

Type
Array.<number>

translateBySphericalCoordinates(out, start, radius, azi, alt) <static>

Moves the out coordinate a distance of radius from start in the given angles.

NOTE: This method changes values within the out parameter, however it is safe to use the same instance as start to change it in-place.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] coordinate array to receive the result.

start Array.<number>

The [x,y,z] coordinate array of the position to begin from.

radius number

The distance from the given start point.

azi number

The horizontal azimuth angle, in radians anti-clockwise from +X axis.

alt number

The vertical angle, in radians above the horizontal plane.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

translateInVectorDirection(out, start, direction, distance) <static>

Calculates the position distance from start in the given vector direction.

NOTE: This method changes values within the out parameter, however it is safe to use the same array as start to change it in-place.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] coordinate array to receive the result.

start Array.<number>

The [x,y,z] coordinate array to begin from.

direction Array.<number>

The normalized [x,y,z] vector array giving the direction of movement.

distance number

The scalar distance to move in the vector direction.

Returns:

Returns the modified out [x,y,z] vector array.

Type
Array.<number>

validate(out) <static>

Ensures that the given vector array is a valid array with numeric x, y and z values in the first three entries.

NOTE: This method changes values within the out parameter.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] vector array to validate.

Returns:

Returns a valid [x,y,z] vector array.

Type
Array.<number>

validateAs2D(out [, Z]) <static>

Ensures that the given vector array is a valid array with three numeric values, but with the third set to Z.

Use this method when you require a valid 2D point that still has x, y and z entries, but where you need to control the z value.

NOTE: This method changes values within the out parameter, with the first two array items being converted to their numeric values and the third item being replaced with the numeric value of Z.

Parameters:
Name Type Argument Description
out Array.<number>

The [x,y,z] vector array to validate.

Z number <optional>

The value to set the third array item, defaults to zero.

Returns:

Returns a valid [x,y,z] vector array.

Type
Array.<number>

vectorBetween(out, p1, p2) <static>

Calculates the vector between two 3D coordinate arrays.

NOTE: This method changes values within the out parameter, however it is safe to use the same array as p1 of p2 to change it in-place.

Parameters:
Name Type Description
out Array.<number>

The [x,y,z] coordinate array to receive the calculated result.

p1 Array.<number>

The first [x,y,z] coordinate array.

p2 Array.<number>

The second [x,y,z] coordinate array.

Returns:

Returns the resulting out vector.

Type
Array.<number>