This vector class implements vectors and operations on them in three-dimensional space. Basic algebraic operations on vectors, vector copying and the chaining mechanism are supported
new Vector3D(x, y, z)
- creates new vector with(x, y, z)
coordinatesnew Vector3D(x)
- creates new vector with(x, x, x)
coordinates
static fromTwoPoints(point1, point2): Vector3D
- creates new Vector3D instance from two points.point1
andpoint2
are arrays of numberscopy(): Vector3D
- returns new Vector3D with the same coordinatesadd(vector: Vector3D): Vector3D
orsubtract(vector: Vector3D): Vector3D
- adds / subtracts a vector from originaltimes(alpha: number): Vector3D
- returns vector multiplied by scalaralpha
isEqual(vector: Vector3D): boolean
- checks ifvector
equals original vectornormalize(): Vector3D
- normalizes original vectorscalarMultiplyBy(vector: Vector3D): number
- dot product of vectorsset(vector: Vector3D): Vector3D
- sets coords ofvector
to the original vectorsetComponents({ x, y, z }: { x: number | undefined, y: number | undefined, z: number | undefined }): Vector3D
- sets coords of the vector individuallytoString(): string
- return string likevector(x, y, z)
coords
- stores the coordinates of vector (readwrite).length
- stores length of vector (readonly)