Vector2d Class

2D vector with x,y as properties

Extends

Implements

Methods

Name Description
constructor(x: number = 0, y: number = 0): Vector2d    
angleTo(vectorB: XAndY): Angle return the (signed) angle from this to vectorB.  
clone(): Vector2d Return a new Vector2d with the same x,y  
crossProduct(vectorB: XAndY): number vector cross product {this CROSS vectorB}  
dotProduct(vectorB: XAndY): number return the dot product of this with vectorB  
dotProductStartEnd(pointA: XAndY, pointB: XAndY): number dot product with vector from pointA to pointB  
fractionOfProjectionToVector(target: Vector2d, defaultFraction?: number): number return the fractional projection of spaceVector onto this  
interpolate(fraction: number, right: Vector2d, result?: Vector2d): Vector2d return the interpolation {this + fraction * (right - this)}  
isParallelTo(other: Vector2d, oppositeIsParallel: boolean = false): boolean Test if this and other area parallel, with angle tolerance Geometry.smallAngleRadiansSquared.  
isPerpendicularTo(other: Vector2d): boolean Returns true if this vector is perpendicular to other.  
minus(vector: XAndY, result?: Vector2d): Vector2d return {this - vector}.  
negate(result?: Vector2d): Vector2d Return a new vector with components negated from this instance.  
normalize(result?: Vector2d): Vector2d | undefined Return a unit vector in direction of this instance (undefined if this instance has near zero length)  
plus(vector: XAndY, result?: Vector2d): Vector2d return {this + vector}.  
plus2Scaled(vectorA: XAndY, scalarA: number, vectorB: XAndY, scalarB: number, result?: Vector2d): Vector2d Return {point + vectorA * scalarA + vectorB * scalarB}  
plus3Scaled(vectorA: XAndY, scalarA: number, vectorB: XAndY, scalarB: number, vectorC: XAndY, scalarC: number, result?: Vector2d): Vector2d Return {this + vectorA * scalarA + vectorB * scalarB + vectorC * scalarC}  
plusScaled(vector: XAndY, scaleFactor: number, result?: Vector2d): Vector2d Return {point + vector * scalar}  
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): Vector2d | undefined Return a (new or optionally reused) vector which is this divided by denominator
* return undefined if denominator is zero.
 
scale(scale: number, result?: Vector2d): Vector2d Return {this * scale}  
scaleToLength(length: number, result?: Vector2d): Vector2d | undefined return a vector parallel to this but with specified length  
unitPerpendicularXY(result?: Vector2d): Vector2d Return a unit vector perpendicular to this instance.  
create(x: number = 0, y: number = 0, result?: Vector2d): Vector2d Static Return a new Vector2d with given x and y  
createFrom(data: XAndY | Float64Array, 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): Vector2d | undefined 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: XAndY, point1: XAndY, 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 Return a new Vector2d from json structured as [1,2] or {x:1,y:2}  
unitX(scale: number = 1): Vector2d Static Return a (new) Vector2d with components 1,0  
unitY(scale: number = 1): Vector2d Static Return a (new) Vector2d with components 0,1  

Inherited methods

Name Inherited from Description
distance(other: XAndY): number XY Return the distance from this point to other
distanceSquared(other: XAndY): number XY Return squared distance from this point to other
freeze(): void XY Freeze this instance (and its deep content) so it can be considered read-only
isAlmostEqual(other: XAndY, tol?: number): boolean XY Returns true if this and other have equal x,y parts within Geometry.smallMetricDistance.
isAlmostEqualMetric(other: XAndY): boolean XY returns true if x,y match other within metric tolerance
isAlmostEqualXY(x: number, y: number, tol?: number): boolean XY Returns true if this and other have equal x,y parts within Geometry.smallMetricDistance.
isExactEqual(other: XAndY): boolean XY returns true if the x,y components are exactly equal.
magnitude(): number XY Return the magnitude of the vector
magnitudeSquared(): number XY Return the squared magnitude of the vector.
maxAbs(): number XY Return the largest absolute value of any component
maxDiff(other: XAndY): number XY Return the largest absolute distance between corresponding components
set(x: number = 0, y: number = 0): void XY Set both x and y.
setFrom(other?: XAndY): void XY Set both x and y from other.
setFromJSON(json?: XYProps): void XY Set x and y from a JSON source such as [1,2] or {x:1, y:2}
setZero(): void XY Set both x and y to zero
toJSON(): XYProps XY return a json array [x,y]
toJSONXY(): XYProps XY return a json object {x: 1, y:2}
unitVectorTo(target: XAndY, result?: Vector2d): Vector2d | undefined XY Return a unit vector from this point to other
vectorTo(other: XAndY, result?: Vector2d): Vector2d XY Return a (full length) vector from this point to other
crossProductToPoints(origin: XAndY, targetA: XAndY, targetB: XAndY): number Static XY cross product of vectors from origin to targets

Inherited properties

Name Type Inherited from Description
isAlmostZero Accessor ReadOnly boolean XY returns true if the x,y components are both small by metric metric tolerance
x number XY x component
y number XY y component

Defined in

Last Updated: 08 January, 2020