Vector2d Class

2D vector with x,y as properties

Extends

Implements

Methods

Name Description
constructor(x: number0, y: number0): Vector2d    
angleTo(vectorB: Readonly<WritableXAndY>): Angle Return the (strongly typed) signed angle from this to vectorB.  
clone(result?: Vector2d): Vector2d Return a new Vector2d with the same x,y  
crossProduct(vectorB: Readonly<WritableXAndY>): number Vector cross product {this CROSS vectorB}  
dotProduct(vectorB: Readonly<WritableXAndY>): number Return the dot product of this with vectorB  
dotProductStartEnd(pointA: Readonly<WritableXAndY>, pointB: Readonly<WritableXAndY>): number Dot product with vector from pointA to pointB  
fractionOfProjectionToVector(target: Vector2d, defaultFraction?: number): number Return fractional length of the projection of the instance onto the target vector.  
interpolate(fraction: number, vectorB: Vector2d, result?: Vector2d): Vector2d Return a vector computed at fractional position between this vector and vectorB  
isParallelTo(other: Vector2d, oppositeIsParallel: booleanfalse, returnValueIfAnInputIsZeroLength: booleanfalse, options?: PerpParallelOptions): boolean Test if this vector is parallel to other.  
isPerpendicularTo(other: Vector2d, returnValueIfAnInputIsZeroLength: booleanfalse, options?: PerpParallelOptions): boolean Test if this vector is perpendicular to other.  
minus(vector: Readonly<WritableXAndY>, result?: Vector2d): Vector2d Return {this - vector}.  
negate(result?: Vector2d): Vector2d Return a new vector with components negated from this instance.  
normalize(result?: Vector2d): undefined | Vector2d Return a unit vector in direction of this instance (undefined if this instance has near zero length)  
plus(vector: Readonly<WritableXAndY>, result?: Vector2d): Vector2d Return {this + vector}.  
plus2Scaled(vectorA: Readonly<WritableXAndY>, scalarA: number, vectorB: Readonly<WritableXAndY>, scalarB: number, result?: Vector2d): Vector2d Return {point + vectorA * scalarA + vectorB * scalarB}  
plus3Scaled(vectorA: Readonly<WritableXAndY>, scalarA: number, vectorB: Readonly<WritableXAndY>, scalarB: number, vectorC: Readonly<WritableXAndY>, scalarC: number, result?: Vector2d): Vector2d Return {this + vectorA * scalarA + vectorB * scalarB + vectorC * scalarC}  
plusScaled(vector: Readonly<WritableXAndY>, scaleFactor: number, result?: Vector2d): Vector2d Return {point + vector * scalar}  
radiansTo(vectorB: Readonly<WritableXAndY>): number Return the radians (as a simple number, not strongly typed Angle) signed angle from this to vectorB.  
rotate90CCWXY(result?: Vector2d): Vector2d Return a vector same length as this but rotated 90 degrees counter clockwise  
rotate90CWXY(result?: Vector2d): Vector2d Return a vector same length as this but rotated 90 degrees clockwise  
rotateXY(angle: Angle, result?: Vector2d): Vector2d Return a new Vector2d rotated CCW by given angle  
safeDivideOrNull(denominator: number, result?: Vector2d): undefined | Vector2d Return a (new or optionally reused) vector which is this divided by denominator  
scale(scale: number, result?: Vector2d): Vector2d Return {this * scale}  
scaleToLength(length: number, result?: Vector2d): undefined | Vector2d Return a vector parallel to this but with specified length  
unitPerpendicularXY(result?: Vector2d): Vector2d Return a unit vector perpendicular to this instance.  
create(x: number0, y: number0, result?: Vector2d): Vector2d Static Return a new Vector2d with given x and y  
createFrom(data: Float64Array | Readonly<WritableXAndY>, result?: Vector2d): Vector2d Static Copy contents from another Point3d, Point2d, Vector2d, or Vector3d, or leading entries of Float64Array  
createOffsetBisector(unitPerpA: Vector2d, unitPerpB: Vector2d, offset: number): undefined | Vector2d Static Return a vector that bisects the angle between two normals and extends to the intersection of two offset lines  
createPolar(r: number, theta: Angle): Vector2d Static Return a new Vector2d from polar coordinates for radius and Angle from x axis  
createStartEnd(point0: Readonly<WritableXAndY>, point1: Readonly<WritableXAndY>, result?: Vector2d): Vector2d Static Return a new Vector2d extending from point0 to point1  
createZero(result?: Vector2d): Vector2d Static Return a Vector2d with components 0,0  
fromJSON(json?: XYProps): Vector2d Static Set x and y from a JSON input such as [1,2] or {x:1, y:2}  
unitX(scale: number1): Vector2d Static Return a (new) Vector2d with components scale,0  
unitY(scale: number1): Vector2d Static Return a (new) Vector2d with components 0,scale  

Inherited methods

Name Inherited from Description
at(index: number): number Inherited XY Return the x,y component corresponding to 0,1
distance(other: Readonly<WritableXAndY>): number Inherited XY Return the distance from this point to other
distanceSquared(other: Readonly<WritableXAndY>): number Inherited XY Return squared distance from this point to other
freeze(): Readonly<Vector2d> Inherited XY Freeze this instance so it is read-only
indexOfMaxAbs(): number Inherited XY Return the index (0,1) of the x,y component with largest absolute value
isAlmostEqual(other: Readonly<WritableXAndY>, tol?: number): boolean Inherited XY Returns true if this and other have equal x,y parts within Geometry.smallMetricDistance.
isAlmostEqualMetric(other: Readonly<WritableXAndY>, distanceTol: numberGeometry.smallMetricDistance): boolean Inherited XY Returns true if x,y match other within metric tolerance
isAlmostEqualXY(x: number, y: number, tol?: number): boolean Inherited XY Returns true if this and other have equal x,y parts within Geometry.smallMetricDistance.
isExactEqual(other: Readonly<WritableXAndY>): boolean Inherited XY Returns true if the x,y components are exactly equal.
magnitude(): number Inherited XY Return the magnitude of the vector
magnitudeSquared(): number Inherited XY Return the squared magnitude of the vector.
maxAbs(): number Inherited XY Return the largest absolute value of any component
maxDiff(other: Readonly<WritableXAndY>): number Inherited XY Return the largest absolute distance between corresponding components
set(x: number0, y: number0): void Inherited XY Set both x and y.
setAt(index: number, value: number): void Inherited XY Set value at index 0 or 1
setFrom(other?: Readonly<WritableXAndY>): void Inherited XY Set both x and y from other.
setFromJSON(json?: XYProps): void Inherited XY Set x and y from a JSON input such as [1,2] or {x:1, y:2}
setZero(): void Inherited XY Set both x and y to zero
toJSON(): XYProps Inherited XY Return a json array [x,y]
toJSONXY(): XYProps Inherited XY Return a json object {x: 1, y:2}
unitVectorTo(other: Readonly<WritableXAndY>, result?: Vector2d): undefined | Vector2d Inherited XY Return a unit vector from this point to other
vectorTo(other: Readonly<WritableXAndY>, result?: Vector2d): Vector2d Inherited XY Return a (full length) vector from this point to other
crossProductToPoints(origin: Readonly<WritableXAndY>, targetA: Readonly<WritableXAndY>, targetB: Readonly<WritableXAndY>): number Static Inherited XY Cross product of vectors from origin to targets

Inherited properties

Name Type Inherited from Description
isAlmostZero Accessor Inherited ReadOnly boolean XY Returns true if the x,y components are both small by metric metric tolerance
isZero Accessor Inherited ReadOnly boolean XY Return true if the x and y components are all exactly zero
x Inherited number XY x component
y Inherited number XY y component

Defined in

Last Updated: 17 December, 2024