Vector3d Class

3D vector with x,y,z as properties

Extends

Methods

Name Description
constructor(x: number0, y: number0, z: number0): Vector3d    
addCrossProductToTargetsInPlace(ax: number, ay: number, az: number, bx: number, by: number, bz: number, cx: number, cy: number, cz: number): void Accumulate a vector which is cross product vectors from origin (ax,ay,az) to targets (bx,by,bz) and (cx,cy,cz)  
angleFromPerpendicular(planeNormal: Vector3d): Angle Return the (strongly-typed) angle from this vector to the plane perpendicular to planeNormal.  
angleTo(vectorB: Vector3d): Angle Return the (strongly-typed) angle from this vector to vectorB.  
angleToXY(vectorB: Vector3d): Angle Return the (strongly-typed) angle from this vector to vectorB, using only the xy parts.  
clone(result?: Vector3d): Vector3d Copy xyz from this instance to a new (or optionally reused) Vector3d  
crossProduct(vectorB: Vector3d, result?: Vector3d): Vector3d Return the cross product of this vector and vectorB.  
crossProductMagnitude(vectorB: Readonly<WritableXYAndZ>): number Compute the magnitude of a cross product (without allocating a temporary vector object)  
crossProductMagnitudeSquared(vectorB: Readonly<WritableXYAndZ>): number Compute the squared magnitude of a cross product (without allocating a temporary vector object)  
crossProductStartEnd(pointA: Point3d, pointB: Point3d, result?: Vector3d): Vector3d Cross product with vector from pointA to pointB  
crossProductStartEndXY(pointA: Point3d, pointB: Point3d): number Cross product (xy parts only) with vector from pointA to pointB  
crossProductXY(vectorB: Vector3d): number Return the cross product of the instance and vectorB, using only the x and y parts.  
crossProductXYZ(x: number, y: number, z: number, result?: Vector3d): Vector3d Return cross product of this with the vector (x, y, z)  
dotProduct(vectorB: Readonly<WritableXYAndZ>): number Return the dot product of this vector with vectorB.  
dotProductStart3dEnd4d(pointA: Point3d, pointB: Point4d): number Returns the dot product with vector (pointB - pointA * pointB.w)  
dotProductStartEnd(pointA: Readonly<WritableXYAndZ>, pointB: Readonly<WritableXYAndZ>): number Returns the dot product of this vector with the with vector from pointA to pointB  
dotProductStartEndXY(pointA: Point3d, pointB: Point3d): number Dot product with vector from pointA to pointB, using only xy parts  
dotProductStartEndXYZ(pointA: Point3d, x: number, y: number, z: number): number Dot product with vector from pointA to pointB, with pointB given as x,y,z  
dotProductStartEndXYZW(pointA: Point3d, wx: number, wy: number, wz: number, w: number): number Dot product with vector from pointA to pointB, with pointB given as (weighted) wx,wy,wz,w  
dotProductXY(vectorB: Vector3d): number Return the dot product of the instance and vectorB, using only the x and y parts.  
dotProductXYZ(x: number, y: number, z: number0): number Dot product with vector (x,y,z)  
fractionOfProjectionToVector(target: Vector3d, defaultFraction: number0): number Return fractional length of the projection of the instance onto the target vector.  
interpolate(fraction: number, vectorB: Readonly<WritableXYAndZ>, result?: Vector3d): Vector3d Return a vector computed at fractional position between this vector and vectorB  
isParallelTo(other: Vector3d, oppositeIsParallel: booleanfalse, returnValueIfAnInputIsZeroLength: booleanfalse, options?: PerpParallelOptions): boolean Test if this vector is parallel to other.  
isPerpendicularTo(other: Vector3d, returnValueIfAnInputIsZeroLength: booleanfalse, options?: PerpParallelOptions): boolean Test if this vector is perpendicular to other.  
minus(vector: Readonly<WritableXYAndZ>, result?: Vector3d): Vector3d Return the vector difference this - vector  
negate(result?: Vector3d): Vector3d Return a new vector with components negated from the calling instance.  
normalize(result?: Vector3d): undefined | Vector3d Return a unit vector parallel with this.  
normalizeInPlace(): boolean If this vector has nonzero length, divide by the length to change to a unit vector.  
normalizeWithDefault(x: number, y: number, z: number, result?: Vector3d): Vector3d Normalize this vector, using given xyz as default if length is zero.  
normalizeWithLength(result?: Vector3d): { mag: number, v: undefined | Vector3d } Return a normalized instance and instance length.  
planarAngleTo(vectorB: Vector3d, planeNormal: Vector3d): Angle Return the (strongly-type) angle from this vector to vectorB,  
planarRadiansTo(vectorB: Vector3d, planeNormal: Vector3d): number Return the angle in radians (not as strongly-typed Angle) from this vector to vectorB,  
plus(vector: Readonly<WritableXYAndZ>, result?: Vector3d): Vector3d Return the vector sum this - vector  
plus2Scaled(vectorA: Readonly<WritableXYAndZ>, scalarA: number, vectorB: Readonly<WritableXYAndZ>, scalarB: number, result?: Vector3d): Vector3d Return the (strongly typed Vector3d) this Vector3d + vectorA * scalarA + vectorB * scalarB  
plus3Scaled(vectorA: Readonly<WritableXYAndZ>, scalarA: number, vectorB: Readonly<WritableXYAndZ>, scalarB: number, vectorC: Readonly<WritableXYAndZ>, scalarC: number, result?: Vector3d): Vector3d Return the (strongly typed Vector3d) thisVector3d + vectorA * scalarA + vectorB * scalarB + vectorC * scalarC  
plusScaled(vector: Readonly<WritableXYAndZ>, scaleFactor: number, result?: Vector3d): Vector3d Return vector + vector * scalar  
radiansFromPerpendicular(planeNormal: Vector3d): number Return the angle in radians (not as strongly typed Angle) from this vector to the plane perpendicular to planeNormal.  
radiansTo(vectorB: Vector3d): number Return the angle in radians (not as strongly typed Angle) from this vector to vectorB.  
rotate90Around(axis: Vector3d, result?: Vector3d): undefined | Vector3d Rotate this vector 90 degrees around an axis vector.  
rotate90CCWXY(result?: Vector3d): Vector3d Return a vector same length as this but rotate 90 degrees CCW  
rotate90CWXY(result?: Vector3d): Vector3d Return a vector same length as this but rotated 90 degrees clockwise  
rotate90Towards(target: Vector3d, result?: Vector3d): undefined | Vector3d Return a (new or optionally preallocated) vector that is rotated 90 degrees in  
rotateXY(angle: Angle, result?: Vector3d): Vector3d Rotate the xy parts of this vector around the z axis.  
safeDivideOrNull(denominator: number, result?: Vector3d): undefined | Vector3d Scale the instance by 1.0/denominator.  
scale(scale: number, result?: Vector3d): Vector3d Return vector * scalar  
scaleToLength(length: number, result?: Vector3d): undefined | Vector3d Return a vector in the direction of this but with specified length.  
setStartEnd(point0: Readonly<WritableXYAndZ>, point1: Readonly<WritableXYAndZ>): void Set (replace) xyz components so they are a vector from point0 to point1  
signedAngleTo(vectorB: Vector3d, vectorW: Vector3d): Angle Return the (strongly-typed) angle from this vector to vectorB, measured  
signedRadiansTo(vectorB: Vector3d, vectorW: Vector3d): number Return the angle in radians (not as strongly-typed Angle) from this vector to vectorB, measured  
sizedCrossProduct(vectorB: Vector3d, productLength: number, result?: Vector3d): undefined | Vector3d Compute cross product with vectorB  
smallerUnorientedAngleTo(vectorB: Vector3d): Angle Return the smallest (strongly typed) angle from the (bidirectional) line containing this  
smallerUnorientedRadiansTo(vectorB: Vector3d): number Return the smallest angle (in radians) from the (bidirectional) line containing this  
tripleProduct(vectorB: Vector3d, vectorC: Vector3d): number Return the triple product of the instance, vectorB, and vectorC  
tryNormalizeInPlace(smallestMagnitude: numberGeometry.smallFraction): boolean Try to normalize (divide by magnitude), storing the result in place.  
unitCrossProduct(vectorB: Vector3d, result?: Vector3d): undefined | Vector3d Compute the cross product of this vector with vectorB.  
unitCrossProductWithDefault(vectorB: Vector3d, x: number, y: number, z: number, result?: Vector3d): Vector3d Compute the cross product of this vector with vectorB and normalize it.  
unitPerpendicularXY(result?: Vector3d): Vector3d Return a vector which is in the xy plane, perpendicular to the xy part of this vector, and of unit length.  
create(x: number0, y: number0, z: number0, result?: Vector3d): Vector3d Static Return a Vector3d (new or reused from optional result)  
createAdd2Scaled(vectorA: Readonly<WritableXYAndZ>, scaleA: number, vectorB: Readonly<WritableXYAndZ>, scaleB: number, result?: Vector3d): Vector3d Static Return the (strongly typed Vector3d) thisVector3d + vectorA * scalarA + vectorB * scalarB  
createAdd2ScaledXYZ(ax: number, ay: number, az: number, scaleA: number, bx: number, by: number, bz: number, scaleB: number, result?: Vector3d): Vector3d Static Return the (strongly typed Vector3d) thisVector3d + vectorA * scalarA + vectorB * scalarB  
createAdd3Scaled(vectorA: Readonly<WritableXYAndZ>, scaleA: number, vectorB: Readonly<WritableXYAndZ>, scaleB: number, vectorC: Readonly<WritableXYAndZ>, scaleC: number, result?: Vector3d): Vector3d Static Return the (strongly typed Vector3d) thisVector3d + vectorA * scaleA + vectorB * scaleB + vectorC * scaleC  
createArrayFromPackedXYZ(data: Float64Array): Vector3d[] Static Return an array of vectors constructed from groups of 3 entries in a Float64Array.  
createCrossProduct(ux: number, uy: number, uz: number, vx: number, vy: number, vz: number, result?: Vector3d): Vector3d Static Create a vector which is cross product of two vectors supplied as separate arguments  
createCrossProductToPoints(origin: Readonly<WritableXYAndZ>, pointA: Readonly<WritableXYAndZ>, pointB: Readonly<WritableXYAndZ>, result?: Vector3d): Vector3d Static Return the cross product of the vectors from origin to pointA and pointB.  
createFrom(data: Float64Array | number[] | Readonly<WritableXAndY> | Readonly<WritableXYAndZ>, result?: Vector3d): Vector3d Static Copy contents from another Point3d, Point2d, Vector2d, or Vector3d  
createNormalized(x: number0, y: number0, z: number0, result?: Vector3d): undefined | Vector3d Static Create a normalized vector from the inputs.  
createNormalizedStartEnd(startPoint: Readonly<WritableXYAndZ>, endPoint: Readonly<WritableXYAndZ>, result?: Vector3d): undefined | Vector3d Static Create a normalized vector from startPoint to endPoint  
createPolar(r: number, theta: Angle, z?: number): Vector3d Static Return a vector defined by polar coordinates distance and angle from x axis  
createRotateVectorAroundVector(vector: Vector3d, axis: Vector3d, angle?: Angle): undefined | Vector3d Static Return a vector which is the input vector rotated by angle around the axis vector.  
createSpherical(r: number, theta: Angle, phi: Angle): Vector3d Static Return a vector defined in spherical coordinates.  
createStartEnd(start: Readonly<WritableXAndY> | Readonly<WritableXYAndZ>, end: Readonly<WritableXAndY> | Readonly<WritableXYAndZ>, result?: Vector3d): Vector3d Static Return a vector defined by start and end points (end - start).  
createStartEndXYZXYZ(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number, result?: Vector3d): Vector3d Static Return a vector (optionally in preallocated result, otherwise newly created) from [x0,y0,z0] to [x1,y1,z1]  
createUnitCrossProductToPoints(origin: Readonly<WritableXYAndZ>, pointA: Readonly<WritableXYAndZ>, pointB: Readonly<WritableXYAndZ>, result?: Vector3d): undefined | Vector3d Static Return the NORMALIZED cross product of the vectors from origin to pointA and pointB, or undefined  
createZero(result?: Vector3d): Vector3d Static Return a vector with 000 xyz parts.  
dotProductAsXYAndZ(dataA: Readonly<WritableXYAndZ>, dataB: Readonly<WritableXYAndZ>): number Static Return the dot product of the xyz components of two inputs that are XYAndZ but otherwise not explicitly Vector3d  
fromJSON(json?: XYZProps): Vector3d Static Convert json to Vector3d.  
unitX(scale: number1): Vector3d Static Return a unit X vector optionally multiplied by a scale  
unitY(scale: number1): Vector3d Static Return a unit Y vector optionally multiplied by a scale  
unitZ(scale: number1): Vector3d Static Return a unit Z vector optionally multiplied by a scale  

Inherited methods

Name Inherited from Description
addInPlace(other: Readonly<WritableXYAndZ>): void Inherited XYZ Add x,y,z from other in place.
addScaledInPlace(other: Readonly<WritableXYAndZ>, scale: number): void Inherited XYZ Add (in place) the scaled x,y,z of other
addXYZInPlace(dx: number0.0, dy: number0.0, dz: number0.0): void Inherited XYZ Add to x, y, z parts
at(index: number): number Inherited XYZ Return the x,y, z component corresponding to 0,1,2
cloneAsPoint3d(): Point3d Inherited XYZ Clone strongly typed as Point3d
distance(other: Readonly<WritableXYAndZ>): number Inherited XYZ Return the distance from this point to other
distanceSquared(other: Readonly<WritableXYAndZ>): number Inherited XYZ Return squared distance from this point to other
distanceSquaredXY(other: Readonly<WritableXAndY>): number Inherited XYZ Return squared XY distance from this point to other
distanceXY(other: Readonly<WritableXAndY>): number Inherited XYZ Return the XY distance from this point to other
freeze(): Readonly<Vector3d> Inherited XYZ Freeze this XYZ
indexOfMaxAbs(): number Inherited XYZ Return the index (0,1,2) of the x,y,z component with largest absolute value
isAlmostEqual(other: Readonly<Readonly<WritableXYAndZ>>, tol?: number): boolean Inherited XYZ Returns true if this and other have equal x,y,z parts within Geometry.smallMetricDistance.
isAlmostEqualMetric(other: Readonly<WritableXYAndZ>): boolean Inherited XYZ Equality test with Geometry.smallMetricDistance tolerance
isAlmostEqualPointPlusScaledVector(other: Readonly<WritableXYAndZ>, vector: Readonly<WritableXYAndZ>, scale: number, tol?: number): boolean Inherited XYZ Return true if this and {other + vector*scale} have equal x,y,z parts within Geometry.smallMetricDistance.
isAlmostEqualXY(other: Readonly<WritableXAndY>, tol?: number): boolean Inherited XYZ Return true if this and other have equal x,y parts within Geometry.smallMetricDistance.
isAlmostEqualXYZ(x: number, y: number, z: number, tol?: number): boolean Inherited XYZ Return true if this and other have equal x,y,z parts within Geometry.smallMetricDistance.
isExactEqual(other: Readonly<WritableXYAndZ>): boolean Inherited XYZ Exact equality test.
magnitude(): number Inherited XYZ Return the sqrt of the sum of squared x,y,z parts
magnitudeSquared(): number Inherited XYZ Return the sum of squared x,y,z parts
magnitudeSquaredXY(): number Inherited XYZ Return the sum of squared x,y parts
magnitudeXY(): number Inherited XYZ Return sqrt of the sum of squared x,y parts
maxAbs(): number Inherited XYZ Return the largest absolute value of any component
maxDiff(other: Readonly<WritableXYAndZ>): number Inherited XYZ Return the largest absolute distance between corresponding components
scaledVectorTo(other: Readonly<WritableXYAndZ>, scale: number, result?: Vector3d): Vector3d Inherited XYZ Return a multiple of a the (full length) vector from this point to other
scaleInPlace(scale: number): void Inherited XYZ Multiply the x, y, z parts by scale.
set(x: number0, y: number0, z: number0): void Inherited XYZ Set the x,y,z parts.
setAt(index: number, value: number): void Inherited XYZ Set value at index 0 or 1 or 2
setFrom(other: Float64Array | Readonly<WritableXAndY> | Readonly<WritableXYAndZ>): void Inherited XYZ Set the x,y,z parts from one of these input types
setFromJSON(json?: XYZProps): void Inherited XYZ Set the x,y,z properties from one of several json forms:
setFromPoint3d(other?: Readonly<WritableXYAndZ>): void Inherited XYZ Set the x,y,z parts from a Point3d.
setFromVector3d(other?: Vector3d): void Inherited XYZ Set the x,y,z parts from a Vector3d
setZero(): void Inherited XYZ Set the x,y,z parts to zero.
subtractInPlace(other: Readonly<WritableXYAndZ>): void Inherited XYZ Subtract x,y,z from other in place.
toArray(): number[] Inherited XYZ Return as an array [x,y,z]
toFloat64Array(): Float64Array Inherited XYZ Pack the x,y,z values in a Float64Array.
toJSON(): XYZProps Inherited XYZ Return a JSON object as array [x,y,z]
toJSONXYZ(): XYZProps Inherited XYZ Return a JSON object as key value pairs {x: value, y: value, z: value}
unitVectorTo(target: Readonly<WritableXYAndZ>, result?: Vector3d): undefined | Vector3d Inherited XYZ Return a unit vector from this vector to other.
vectorTo(other: Readonly<WritableXYAndZ>, result?: Vector3d): Vector3d Inherited XYZ Return a (full length) vector from this point to other
accessX(arg: any, defaultValue?: number): undefined | number Static Inherited XYZ Look for (in order) an x coordinate present as:
accessY(arg: any, defaultValue?: number): undefined | number Static Inherited XYZ Look for (in order) a y coordinate present as:
accessZ(arg: any, defaultValue?: number): undefined | number Static Inherited XYZ Look for (in order) a z coordinate present as:
hasZ(arg: any): arg is Readonly<WriteableHasZ> Static Inherited XYZ Type guard to determine whether an object has a member called "z"
isAnyImmediatePointType(arg: any): arg is number[] | Readonly<WritableXAndY> | Readonly<WritableXYAndZ> Static Inherited XYZ Test if arg is any of:
isXAndY(arg: any): arg is Readonly<WritableXAndY> Static Inherited XYZ Type guard for XAndY.
isXYAndZ(arg: any): arg is Readonly<WritableXYAndZ> Static Inherited XYZ Type guard for XYAndZ.
x(xyz: XYZProps, defaultValue: number0): number Static Inherited XYZ Access x part of XYZProps (which may be .x or [0])
y(xyz: XYZProps, defaultValue: number0): number Static Inherited XYZ Access x part of XYZProps (which may be .x or [0])
z(xyz: XYZProps, defaultValue: number0): number Static Inherited XYZ Access x part of XYZProps (which may be .x or [0])

Inherited properties

Name Type Inherited from Description
isAlmostZero Accessor Inherited ReadOnly boolean XYZ Return true if the x,y,z components are all nearly zero to tolerance Geometry.smallMetricDistance
isZero Accessor Inherited ReadOnly boolean XYZ Return true if the x,y,z components are all exactly zero
x Inherited number XYZ x coordinate
y Inherited number XYZ y coordinate
z Inherited number XYZ z coordinate

Defined in

Last Updated: 17 December, 2024