new PlaneArray()
A helper class for performing vector math using [a,b,c,d] array-based plane equations.
The array entries represent components of the Ax + By + Cz + D = 0
plane equation. When stored this way, the first three entries in the
plane array are also a vector array defining the normal direction, and
can be used directly in many PD.VectorArray methods.
Any Float32Array with at least four items in the same [a,b,c,d] format
can also be used entirely interchangeably as both output or input in all
plane array methods.
Methods
-
clone(out) <static>
-
Creates a copy of the given plane array.
This method simply returns
out.slice()but is included for API compatibility.Parameters:
Name Type Description outArray.<number> The [a,b,c,d] plane array to clone.
Returns:
Returns a new copied plane array.
- Type
- number
-
computeFromIndexedPath(out, indices, vertices) <static>
-
Computes the [a,b,c,d] plane array from the surface normal of given array of connected points.
This method calculates the surface normal from multiple points along a path using Newell's Method, which provides a very robust way of computing an 'average' normal from points which may vary quite considerably from being coplanar.
NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [a,b,c,d] plane array to set.
indicesArray.<number> An array of ordinal indexes to points within the vertices array.
verticesArray.<number> A repository of [x,y,z] coordinate arrays that
indices.Returns:
Returns the given [a,b,c,d] plane array.
- Type
- Array.<number>
-
computeFromPath(out, path) <static>
-
Computes the [a,b,c,d] plane array from the surface normal of given array of connected points.
This method calculates the surface normal from multiple points along a path using Newell's Method, which provides a very robust way of computing an 'average' normal from points which may vary quite considerably from being coplanar.
NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [a,b,c,d] plane array to set.
pathArray.<number> An array of [x,y,z] coordinate arrays defining a polyline or polygon.
Returns:
Returns the given [a,b,c,d] plane array.
- Type
- Array.<number>
-
computeInclinedFromLine(out, rayPos, rayDir, angle) <static>
-
Calculates an [a,b,c,d] plane array that is inclined by the given angle from a line that is roughly horizontal.
NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [a,b,c,d] plane array to receive the result.
rayPosArray.<number> The [x,y,z] vector array giving the first point on a line.
rayDirArray.<number> The [x,y,z] vector array giving the second point on a line.
anglenumber The tilt angle of the plane in radians (0:horizontal to PI/2:vertical).
Returns:
Returns the modified
out[a,b,c,d] plane array.- Type
- Array.<number>
-
coplanarPoint(out, plane1) <static>
-
Projects the origin onto the give plane.
NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> An [x,y,z] vector array to receive the planar point.
plane1Array.<number> The [a,b,c,d] plane array to project the point onto.
Returns:
Returns the
out[x,y,z] vector array.- Type
- Array.<number>
-
copy(out, pln) <static>
-
Copies the first four components of
ptoout.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [a,b,c,d] plane array to receive the result.
plnArray.<number> The [a,b,c,d] plane array to copy from.
Returns:
Returns the modified
out[a,b,c,d] plane array.- Type
- Array.<number>
-
create( [a] [, b] [, c] [, d]) <static>
-
Creates a new [a,b,c,d] plane array with the given components.
The four (4) array entries represent components of the plane equation
Ax + By + Cz + D = 0, where the first three (3) entries are also a [x,y,z] vector array representing the surface normal direction.Parameters:
Name Type Argument Description anumber <optional>
The A (X-axis) component, or zero if not defined.
bnumber <optional>
The B (Y-axis) component, or zero if not defined.
cnumber <optional>
The C (Z-axis) component, or one if not defined.
dnumber <optional>
The D constant component, or zero if not defined.
Returns:
Returns a new [a,b,c,d] plane array.
- Type
- Array.<number>
-
distanceTo(plane, pt) <static>
-
Computes the signed distance from a 3D point to given plane.
Parameters:
Name Type Description planeArray.<number> The [a,b,c,d] plane array to test.
ptArray.<number> The [x,y,z] vector array of the point.
Returns:
Returns the signed distance to the plane.
- Type
- number
-
inFront(plane, pt) <static>
-
Checks if a 3D points is on the same side of the given plane as its normal is pointing.
Parameters:
Name Type Description planeArray.<number> The [a,b,c,d] plane array to test.
ptArray.<number> The [x,y,z] vector array of the point to check.
Returns:
Returns true if point is on same side of plane as its normal.
- Type
- boolean
-
intersectLine(out, p1, p2, plane [, min]) <static>
-
Calculates the intersection point of a line and plane.
This method calculates intersections beyond both ends of the line, not just inside it. If you want to only intersect in front of p1, set the
minargument to 0. If you want to only intersect in front of p2, set theminargument to 1.NOTE: If successful, this method changes values within the
outparameter to the intersection point. Otherwise it sets it to thep1position as this must lie directly on the plane.Parameters:
Name Type Argument Description outArray.<number> The [x,y,z] vector array to receive the result.
p1Array.<number> The [x,y,z] vector array defining the line start position.
p2Array.<number> The [x,y,z] vector array defining the line end position.
planeArray.<number> The [a,b,c,d] plane array to intersect the ray with.
minnumber <optional>
The minimum distance along the line, defaults to
-Infinity.Returns:
Returns the modified
out[x,y,z] vector array.- Type
- Array.<number>
-
intersectRay(out, rayPos, rayDir, plane [, min]) <static>
-
Calculates the intersection point of a ray and plane.
This method calculates intersections on both sides of the ray, not just in its direction of travel. If you want to only intersect in its direction of travel, set the
minargument to 0.NOTE: If successful, this method changes values within the
outparameter to the intersection point. Otherwise it sets it to the ray origin position as that must lie directly on the plane.Parameters:
Name Type Argument Description outArray.<number> The [x,y,z] vector array to receive the result.
rayPosArray.<number> The [x,y,z] vector array giving the origin point of the ray.
rayDirArray.<number> The [x,y,z] vector array giving the travel direction of the ray.
planeArray.<number> The [a,b,c,d] plane array to intersect the ray with.
minnumber <optional>
The minimum distance along the ray, defaults to
-Infinity.Returns:
Returns the modified
out[x,y,z] vector array.- Type
- Array.<number>
-
intersectThreePlanes(out, plane1, plane2, plane3) <static>
-
Computes the point of intersection between three planes.
NOTE: If successful, this method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> An [x,y,z] vector array to receive the intersection point.
plane1Array.<number> The first [a,b,c,d] plane array to intersect.
plane2Array.<number> The second [a,b,c,d] plane array to intersect.
plane3Array.<number> The third [a,b,c,d] plane array to intersect.
Returns:
Returns true if a valid intersection point was found and copied to the
outargument, otherwise false andoutis not set.- Type
- boolean
-
isOnSameSide(plane, p1, p2) <static>
-
Checks if two 3D points are on the same side of the given plane.
Parameters:
Name Type Description planeArray.<number> The [a,b,c,d] plane array to test.
p1Array.<number> The [x,y,z] vector array of the first point.
p2Array.<number> The [x,y,z] vector array of the second point.
Returns:
Returns true if both points are on same side of the plane.
- Type
- boolean
-
negate(out [, pln]) <static>
-
Reverses the sign of each component of a plane array.
NOTE: This method changes values within the
outparameter, however it is safe to use the same array aspor simply give one argument to change it in-place.Parameters:
Name Type Argument Description outArray.<number> The [a,b,c,d] plane array to receive the result.
plnArray.<number> <optional>
The [a,b,c,d] plane array to negate, set to
outif not supplied.Returns:
Returns the modified
outplane array.- Type
- Array.<number>
-
projectPoint(out, plane, pt) <static>
-
Projects a point onto the given plane using its normal.
Parameters:
Name Type Description outArray.<number> The [x,y,z] coordinate array to receive the result.
planeArray.<number> The [a,b,c,d] plane array to project onto.
ptArray.<number> The [x,y,z] coordinate array of the point to project.
Returns:
Returns the modified
out[x,y,z] coordinate array.- Type
- Array.<number>
-
set(out, a, b, c, d) <static>
-
Sets the [a,b,c,d] plane array to the given components.
This method offers some flexibility in terms of the arguments it accepts. You can provide 4 separate numeric values or just a single [a,b,c,d] plane array, a 4D point-like {x,y,z,w} object, or even no arguments at all to create a unit plane.
NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [a,b,c,d] plane array to receive the result.
anumber The A (X-axis) component, or zero if not defined.
bnumber The B (Y-axis) component, or zero if not defined.
cnumber The C (Z-axis) component, or one if not defined.
dnumber The D constant component, or zero if not defined.
Returns:
Returns the resulting
out[a,b,c,d] plane array.- Type
- Array.<number>
-
setComponents(out, a, b, c, d) <static>
-
Sets the [a,b,c,d] plane array by its individual components.
This method differs from the
set()method in that you must provide all 4 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 the separate component values.NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [a,b,c,d] plane array to receive the result.
anumber The A (X-axis) component, or zero if not defined.
bnumber The B (Y-axis) component, or zero if not defined.
cnumber The C (Z-axis) component, or one if not defined.
dnumber The D constant component, or zero if not defined.
Returns:
Returns the resulting
out[a,b,c,d] plane array.- Type
- Array.<number>
-
setFromCoplanarPoints(out, v1, v2, v3) <static>
-
Computes the [a,b,c,d] plane array from three points that lie on the plane.
NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [a,b,c,d] plane array to set.
v1Array.<number> An [x,y,z] vector array defining the first point on the plane.
v2Array.<number> An [x,y,z] vector array defining the second point on the plane.
v3Array.<number> An [x,y,z] vector array defining the third point on the plane.
Returns:
Returns the given [a,b,c,d] plane array.
- Type
- Array.<number>
-
setFromNormalAndCoplanarPoint(out, normal, point) <static>
-
Computes the [a,b,c,d] plane array from with the given normal and passing through the given point.
NOTE: This method changes values within the
outparameter.Parameters:
Name Type Description outArray.<number> The [a,b,c,d] plane array to set.
normalArray.<number> An [x,y,z] vector array defining the normal, which must be normalized.
pointArray.<number> An [x,y,z] vector array oa point that sits on the plane.
Returns:
Returns the given [a,b,c,d] plane array.
- Type
- Array.<number>