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.
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
vtoout.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
vArray.<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
factorargument 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.randomNumbermethod so you can seed it if you need to generate repeatable number sequences.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to modify.
factornumber 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
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
scalarnumber 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
vmultiplied bysto the three components ofout.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
vArray.<number> The [x,y,z] vector array to add.
scalarnumber The scalar value to multiply
vby.Returns:
Returns the modified
out[x,y,z] vector array.- Type
- Array.<number>
-
addVectors(out, a, b) <static>
-
Sets
outto the addition of the vectorsaandb.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
aArray.<number> The first [x,y,z] vector array to add.
bArray.<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-._ _/ \_ _/ \_ _/ \_ _/ p2Parameters:
Name Type Description p1Array.<number> The first [x,y,z] coordinate array.
p2Array.<number> The shared second [x,y,z] coordinate array.
p3Array.<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 v1Array.<number> The first [x,y,z] direction vector array.
v2Array.<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 v1Array.<number> The first [x,y,z] vector array to calculate angle from.
v2Array.<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
outby the given 3x3 column-major matrixm.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
mtxArray.<number> The 3x3 matrix array to multiply
outby.Returns:
Returns the modified
out[x,y,z] vector array.- Type
- Array.<number>
-
applyMatrix4(out, mtx) <static>
-
Multiplies
outby the given 4x4 column-major matrixm.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
mtxArray.<number> The 4x4 matrix array to multiply
outby, based onTHREE.matrix4#elements.Returns:
Returns the modified
out[x,y,z] vector array.- Type
- Array.<number>
-
applyQuaternion(out, qut) <static>
-
Multiplies
outby the [x,y,z,w] quaternionq.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
qutArray.<number> The [x,y,z,w] quaternion array to multiply
outby.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 p1Array.<number> The first [x,y,z] coordinate array of the triangle.
p2Array.<number> The second [x,y,z] coordinate array of the triangle.
p3Array.<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
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] coordinate array to receive the calculated result.
startPtArray.<number> The [x,y,z] coordinate array of the curve start point.
ctrlPt1Array.<number> The [x,y,z] coordinate array of the first control point.
ctrlPt2Array.<number> The [x,y,z] coordinate array of the second control point.
endPtArray.<number> The [x,y,z] coordinate array of the curve end point.
tnumber 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 outArray.<number> The [x,y,z] vector array to receive the calculated normal.
indicesArray.<number> An array of ordinal indexes to points within the vertices array.
verticesArray.<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 outArray.<number> The [x,y,z] vector array to receive the calculated normal.
pathArray.<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 outArray.<number> The [x,y,z] vector array to receive the calculated normal.
pathArray.<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 p1NOTE: This method changes values within the
outparameter, but it cannot and must not be the same array asp1,p2orp3.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the calculated normal.
p1Array.<number> The first triangle vertex, given as a [x,y,z] coordinate array.
p2Array.<number> The second triangle vertex, given as a [x,y,z] coordinate array.
p3Array.<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
p2in 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 +------------------+ p2If the vector between
p1->p2is 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
outparameter, but it cannot and must not be the same array asp1, orp2.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the calculated normal.
p1Array.<number> The first triangle vertex, given as a [x,y,z] coordinate array.
p2Array.<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
outto an integer usingMath.ceil().NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<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
outto be within the given range.NOTE: This method changes values within the
outparameter and assumes thatmin<maxin each component.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
minArray.<number> The [x,y,z] vector array defining the minimum bounds.
maxArray.<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
outto be within the given range.NOTE: This method changes values within the
outparameter and assumes thatminValue<maxValue.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to limit.
minnumber The minimum length value.
maxnumber 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
outto be within the given range.NOTE: This method changes values within the
outparameter and assumes thatminValue<maxValue.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
minnumber The minimum bounds value.
maxnumber 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 outArray.<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 v1Array.<number> The first [x,y,z] vector array.
v2Array.<number> The second [x,y,z] vector array.
tolerancenumber <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 p1Parameters:
Name Type Description normalArray.<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
pathargument 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 thepolygonalargument 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 contoursArray.<Array.<number>> | Array.<Array.<Array.<number>>> One or more arrays of [x,y,z] coordinate arrays defining a closed polygon/polyline.
polygonalboolean 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
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] coordinate array to receive the result.
pathArray.<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.Vector2orPD.Pointobjects, use thePD.Utils.concaveHullXYmethod instead.The
concavityarguments 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 pointsArray.<number> An array of [x, y[, z]] vector arrays.
concavitynumber A relative measure of concavity, defaults to 1.0.
lengthThresholdnumber 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
vtoout.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
vArray.<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
vtooutwith the given offset.The optional
offsetargument allows you to copy the three values to a different part of theoutarray. It defines the index in the output array at which to start copying the three values.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Argument Description outArray.<number> The [x,y,z] vector array to receive the result.
vArray.<number> The [x,y,z] vector array to copy from.
offsetnumber <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,yandzcomponents ofp1toout.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
pntobject 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 xnumber | Array.<number> The X-axis component, an [x,y,z] vector array, or zero if not defined.
ynumber The Y-axis component, or zero if not defined.
znumber 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
outwithvand copies the result toout.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
vArray.<number> The [x,y,z] vector array to cross
outwith.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->p2andp1->p3, then usesPD.VectorArray.crossVectorsto compute the cross product.cross product + p2 , + , / , /\ / \/__/ \ / \ +------------------+ p3 p1NOTE: This method changes values within the
outparameter, but it cannot and must not be the same array asp1,p2orp3.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the calculated normal.
p1Array.<number> The first triangle vertex, given as a [x,y,z] coordinate array.
p2Array.<number> The second triangle vertex, given as a [x,y,z] coordinate array.
p3Array.<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
outto the cross product of two 3D vector arrays.NOTE: This method changes values within the
outparameter, however it is safe to use the same array asaorb.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
v1Array.<number> The first [x,y,z] vector array.
v2Array.<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 fromArray.<number> The reference [x,y,z] coordinate array to calculate distance from.
directionArray.<number> The normalised [x,y,z] vector array of the measurement direction.
toArray.<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 p1Array.<number> The first [x,y,z] coordinate array.
p2Array.<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 p1Array.<number> The first [x,y,z] coordinate array.
p2Array.<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 p1Array.<number> The first [x,y,z] coordinate array.
p2Array.<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 p1Array.<number> The first [x,y,z] coordinate array.
p2Array.<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 p1Array.<number> The first [x,y,z] coordinate array.
p2Array.<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
outbyv.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
vArray.<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
outby the given scalar value.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
scalarnumber 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 v1Array.<number> The first [x,y,z] vector array.
v2Array.<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.closeToorPD.VectorArray.manhattanDistanceTomethods instead.Parameters:
Name Type Description v1Array.<number> The first [x,y,z] vector array.
v2Array.<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
minandmaxvector arrays to fit the givenpt.NOTE: This method may change values within the
minandmaxparameters.Parameters:
Name Type Description minArray.<number> The [x,y,z] coordinate array defining the minimum bounds.
maxArray.<number> The [x,y,z] coordinate array defining the maximum bounds.
ptArray.<number> The [x,y,z] coordinate array to extend bounds to include.
-
fitExtentsToPoints(min, max, points) <static>
-
Extends the
minandmaxvector arrays to fit all of the givenpoints.NOTE: This method may change values within the
minandmaxparameters.Parameters:
Name Type Description minArray.<number> The [x,y,z] coordinate array defining the minimum bounds.
maxArray.<number> The [x,y,z] coordinate array defining the maximum bounds.
pointsArray.<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
minandmaxvector arrays to fit a sphere.NOTE: This method may change values within the
minandmaxparameters.Parameters:
Name Type Description minArray.<number> The [x,y,z] coordinate array defining the minimum bounds.
maxArray.<number> The [x,y,z] coordinate array defining the maximum bounds.
centerArray.<number> The [x,y,z] coordinate array of the sphere center.
radiusArray.<number> The radius of the sphere.
-
floor(out) <static>
-
Converts each component of
outto an integer usingMath.floor().NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<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 outArray.<number> The [x,y,z] vector array to get results from.
indexnumber 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->p2intersects the line segmentp3->p4in the XY plane.If the two lines intersect, this method will return true. If an
outarray 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 theoutargument.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 p1Array.<number> The first point on the first line segment.
p2Array.<number> The second point on the first line segment.
p3Array.<number> The first point on the second line segment.
p4Array.<number> The second point on the second line segment.
outArray.<number> <optional>
An optional point to receive the intersection.
Returns:
Returns true if segments intersect, and
outmodified.- 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 ptArray.<number> The intersection [x,y,z] coordinate array to test.
v1Array.<number> The first triangle [x,y,z] coordinate array.
v2Array.<number> The second triangle [x,y,z] coordinate array.
v3Array.<number> The third triangle [x,y,z] coordinate array.
normalArray.<number> The plane normal [nx,ny,nz] vector array.
Returns:
Returns true if the
ptis inside the triangle.- Type
- boolean
-
length(v) <static>
-
Computes the magnitude of the given vector.
Parameters:
Name Type Description vArray.<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 vArray.<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
outparameter, however it is safe to use the same array asvto change it in-place.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the calculated result.
vArray.<number> The [x,y,z] vector array to interpolate.
tnumber The fractional value along the vector (0 to 1).
Returns:
Returns the resulting
outvector.- Type
- Array.<number>
-
lerpVectors(out, v1, v2, t) <static>
-
Linearly interpolates between two 3D positions.
NOTE: This method changes values within the
outparameter, however it is safe to use the same array asv1orv2to change it in-place.Parameters:
Name Type Description outArray.<number> The [x,y,z] coordinate array to receive the calculated result.
v1Array.<number> The first [x,y,z] coordinate array.
v2Array.<number> The second [x,y,z] coordinate array.
tnumber The fractional value between the two positions ( 0 to 1).
Returns:
Returns the resulting
outvector.- Type
- Array.<number>
-
manhattanDistanceTo(p1, p2) <static>
-
Computes the Manhattan distance between the two coordinates.
Parameters:
Name Type Description p1Array.<number> The first [x,y,z] coordinate array.
p2Array.<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 vArray.<number> The [x,y,z] vector array to compute.
Returns:
Returns the Manhattan distance.
- Type
- number
-
max(out, v) <static>
-
Sets
outto the maximum of its component compared tov.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
vArray.<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
outto the maximum components of each of the given vectors.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Argument Description outArray.<number> The [x,y,z] vector array to receive the result.
argsArray.<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
outto the minimum of its components compared tov.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
vArray.<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
outto the minimum components of each of the given vectors.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Argument Description outArray.<number> The [x,y,z] vector array to receive the result.
argsArray.<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
outbyv.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
vArray.<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
outby the given scalar value.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
scalarnumber 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
outto the multiplication of a vectorvand scalarscale.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
vArray.<number> The [x,y,z] vector array to be multiplied.
scalarnumber 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
outto the multiplication of the vectorsaandb.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
aArray.<number> The first [x,y,z] vector array to multiply.
bArray.<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
outparameter, however it is safe to use the same array asvor simply give one argument to change it in-place.Parameters:
Name Type Argument Description outArray.<number> The [x,y,z] vector array to receive the result.
vArray.<number> <optional>
The [x,y,z] vector array to negate, set to
outif not supplied.Returns:
Returns the modified
out3D 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
outparameter, however it is safe to use the same array asvor simply give one argument to change it in-place.Parameters:
Name Type Argument Description outArray.<number> The [x,y,z] vector array to receive the result.
vArray.<number> <optional>
The [x,y,z] vector array to normalize, set to
outif 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
outparameter, however it is safe to use the same array asp1ofp2to change it in-place.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
p1Array.<number> The [x,y,z] coordinate array of the starting point.
p2Array.<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_ptsnumber <optional>
The number of hemispherical points to generate (4 to 2048), defaults to 48.
radiusnumber <optional>
The radius of the point distribution, defaults to 1.
domeboolean <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 detailnumber <optional>
The level of triangulation (0 to 32), defaults to 6.
radiusnumber <optional>
The radius of the point distribution, defaults to 1.
domeboolean <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
lngRingspoints will be for the equator. The nextlngRingspoints will be for the latitude one increment up from the equator towards the north pole. The nextlngRingspoints 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 pointDome
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
lngRingspoints will be for the equator. The nextlngRingspoints will be for the latitude one increment up from the equator. The nextlngRingspoints 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 ringParameters:
Name Type Argument Description latRingsnumber <optional>
The number of longitudinal divisions (1 to 178), defaults to 8.
lngRingsnumber <optional>
The number of latitudinal divisions (3 to 360), defaults to 16.
radiusnumber <optional>
The radius of the point distribution, defaults to 1.
domeboolean <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_ptsnumber <optional>
The number of random points to generate (6+), defaults to 48.
radiusnumber <optional>
The radius of the point distribution, defaults to 1.
domeboolean <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_ptsnumber <optional>
The number of hemispherical points to generate (4 to 2048), defaults to 48.
domeboolean <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 detailnumber <optional>
The level of triangulation (0 to 32), defaults to 6.
domeboolean <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_ptsnumber <optional>
The number of random polar points to generate (6+), defaults to 48.
domeboolean <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 azinumber The horizontal azimuth angle, in radians anti-clockwise from +X axis.
altnumber 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 azinumber The horizontal azimuth angle, in radians anti-clockwise from +X axis.
altnumber 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
outparameter.Parameters:
Name Type Description outArray.<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 modifiernumber <optional>
A dark/light modifier value (-0.9 to 0.9).
resultArray.<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
outto 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.randomNumbermethod so you can seed it if you need to generate repeatable number sequences.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<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
outpoint aroundaboutby the given angles.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The point to rotate.
aboutArray.<number> The [x,y,z] point about which to rotate.
azinumber The horizontal azimuth angle, in radians anti-clockwise from +X axis.
altnumber 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.rotatePointsAroundAxismethod.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
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] coordinate array defining the point to rotate.
originArray.<number> The [x,y,z] coordinate array defining the origin point to rotate about.
axisArray.<number> The [x,y,z] vector array defining the axial vector to rotate around.
anglenumber The angle of rotation, in radians.
Returns:
Returns
outset 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 pointsArray.<Array.<number>> An array of one or more [x,y,z] coordinate arrays to rotate.
originArray.<number> The [x,y,z] coordinate array defining the origin point to rotate about.
axisArray.<number> The [x,y,z] vector array defining the axial vector to rotate around.
anglenumber The angle of rotation, in radians.
Returns:
Returns the modified
pointsarray.- Type
- Array.<Array.<number>>
-
round(out) <static>
-
Rounds each component of
outto an integer usingMath.round().NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<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
outto an integer towards zero (up if negative, down if positive).NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<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
outparameter, however it is safe to use the same array asvto change it in-place.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the calculated result.
vArray.<number> The [x,y,z] vector array to scale.
scalenumber | Array.<number> The scale factor to multiply by, or an [sx,sy,sz] vector array.
Returns:
Returns the resulting
outvector.- 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 thecopy()method or, if a vector object, thecopyFromPoint()method.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
xnumber Either the X-axis component, a [x,y,z] vector array, a {x,y,z} vector object, or zero if not defined.
ynumber The Y-axis component, or zero if not defined.
znumber 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
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
indexnumber The index of the component to set (0 to 2).
valuenumber 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
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
xnumber The X-axis component, or zero if not defined.
ynumber The Y-axis component, or zero if not defined.
znumber 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
outvector.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to set.
lengthnumber 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 outArray.<number> The [x,y,z] vector array to receive the result.
scalarnumber 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
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
xnumber 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
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
ynumber 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
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
ynumber 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
outparameter, however it is safe to use the same array asv1orv2to change it in-place.Parameters:
Name Type Description outArray.<number> The [x,y,z] coordinate array to receive the calculated result.
v1Array.<number> The first [x,y,z] coordinate array.
v2Array.<number> The second [x,y,z] coordinate array.
tnumber The fractional value between the two positions ( 0 to 1).
Returns:
Returns the resulting
outvector.- 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.Indexerto 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 segmentsArray.<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 v1Array.<number> The first spherical coordinate as a normalised [x,y,z] vector array.
v2Array.<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 stereoArray.<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
vfromout.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
vArray.<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
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
scalarnumber 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
outto the subtraction of the vectorsaandb.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to receive the result.
aArray.<number> The [x,y,z] vector array to subtract from.
bArray.<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_POSor-1:PD.AXIS.X_NEGas the argument. To swap the X and Y axis, use3:PD.AXIS.Z_POSor-3:PD.AXIS.Z_NEGas the argument. To swap the X and Z axis, use2:PD.AXIS.Y_POSor-2:PD.AXIS.Y_NEGas the argument. To swap the axis back, simply use the same call with the same axis argument.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [x,y,z] vector array to modify.
axisPD.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 vecArray.<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
outcoordinate a distance ofradiusfromstartin the given angles.NOTE: This method changes values within the
outparameter, however it is safe to use the same instance asstartto change it in-place.Parameters:
Name Type Description outArray.<number> The [x,y,z] coordinate array to receive the result.
startArray.<number> The [x,y,z] coordinate array of the position to begin from.
radiusnumber The distance from the given start point.
azinumber The horizontal azimuth angle, in radians anti-clockwise from +X axis.
altnumber 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
distancefromstartin the given vector direction.NOTE: This method changes values within the
outparameter, however it is safe to use the same array asstartto change it in-place.Parameters:
Name Type Description outArray.<number> The [x,y,z] coordinate array to receive the result.
startArray.<number> The [x,y,z] coordinate array to begin from.
directionArray.<number> The normalized [x,y,z] vector array giving the direction of movement.
distancenumber 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
outparameter.Parameters:
Name Type Description outArray.<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
outparameter, with the first two array items being converted to their numeric values and the third item being replaced with the numeric value ofZ.Parameters:
Name Type Argument Description outArray.<number> The [x,y,z] vector array to validate.
Znumber <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
outparameter, however it is safe to use the same array asp1ofp2to change it in-place.Parameters:
Name Type Description outArray.<number> The [x,y,z] coordinate array to receive the calculated result.
p1Array.<number> The first [x,y,z] coordinate array.
p2Array.<number> The second [x,y,z] coordinate array.
Returns:
Returns the resulting
outvector.- Type
- Array.<number>