Vector4¶
Overview¶
Basic 4-dimensional vector, represented as (x,y).
@author Jonathan Olson <jonathan.olson@colorado.edu>
Class Vector4¶
Constructor¶
new Vector4( x : number, y : number, z : number, w : number )¶
Instance Methods¶
getMagnitude() : number¶
The magnitude (Euclidean/L2 Norm) of this vector, i.e. \(\sqrt{x^2+y^2+z^2+w^2}\).
getMagnitudeSquared() : number¶
The squared magnitude (square of the Euclidean/L2 Norm) of this vector, i.e. \(x^2+y^2+z^2+w^2\).
distance( point : Vector4 ) : number¶
The Euclidean distance between this vector (treated as a point) and another point.
distanceXYZW( x : number, y : number, z : number, w : number ) : number¶
The Euclidean distance between this vector (treated as a point) and another point (x,y,z,w).
distanceSquared( point : Vector4 ) : number¶
The squared Euclidean distance between this vector (treated as a point) and another point.
distanceSquaredXYZW( x : number, y : number, z : number, w : number ) : number¶
The squared Euclidean distance between this vector (treated as a point) and another point (x,y,z,w).
dot( v : Vector4 ) : number¶
The dot-product (Euclidean inner product) between this vector and another vector v.
dotXYZW( x : number, y : number, z : number, w : number ) : number¶
The dot-product (Euclidean inner product) between this vector and another vector (x,y,z,w).
angleBetween( v : Vector4 ) : number¶
The angle between this vector and another vector, in the range \(\theta\in[0, \pi]\).
Equal to \(\theta = \cos^{-1}( \hat{u} \cdot \hat{v} )\) where \(\hat{u}\) is this vector (normalized) and \(\hat{v}\) is the input vector (normalized).
equals( other : Vector4 ) : boolean¶
Exact equality comparison between this vector and another vector.
@param other @returns - Whether the two vectors have equal components
equalsEpsilon( other : Vector4, epsilon : number ) : boolean¶
Approximate equality comparison between this vector and another vector.
@returns - Whether difference between the two vectors has no component with an absolute value greater than epsilon.
isFinite() : boolean¶
Returns false if any component is NaN, infinity, or -infinity. Otherwise returns true.
copy( vector? : Vector4 ) : Vector4¶
Creates a copy of this vector, or if a vector is passed in, set that vector's values to ours.
This is the immutable form of the function set(), if a vector is provided. This will return a new vector, and will not modify this vector.
@param [vector] - If not provided, creates a v4 with filled in values. Otherwise, fills in the values of the provided vector so that it equals this vector.
normalized() : Vector4¶
Normalized (re-scaled) copy of this vector such that its magnitude is 1. If its initial magnitude is zero, an error is thrown.
This is the immutable form of the function normalize(). This will return a new vector, and will not modify this vector.
roundedSymmetric() : Vector4¶
Returns a copy of this vector with each component rounded by Utils.roundSymmetric.
This is the immutable form of the function roundSymmetric(). This will return a new vector, and will not modify this vector.
withMagnitude( magnitude : number ) : Vector4¶
Re-scaled copy of this vector such that it has the desired magnitude. If its initial magnitude is zero, an error is thrown. If the passed-in magnitude is negative, the direction of the resulting vector will be reversed.
This is the immutable form of the function setMagnitude(). This will return a new vector, and will not modify this vector.
timesScalar( scalar : number ) : Vector4¶
Copy of this vector, scaled by the desired scalar value.
This is the immutable form of the function multiplyScalar(). This will return a new vector, and will not modify this vector.
times( scalar : number ) : Vector4¶
Same as timesScalar.
This is the immutable form of the function multiply(). This will return a new vector, and will not modify this vector.
componentTimes( v : Vector4 ) : Vector4¶
Copy of this vector, multiplied component-wise by the passed-in vector v.
This is the immutable form of the function componentMultiply(). This will return a new vector, and will not modify this vector.
plus( v : Vector4 ) : Vector4¶
Addition of this vector and another vector, returning a copy.
This is the immutable form of the function add(). This will return a new vector, and will not modify this vector.
plusXYZW( x : number, y : number, z : number, w : number ) : Vector4¶
Addition of this vector and another vector (x,y,z,w), returning a copy.
This is the immutable form of the function addXYZW(). This will return a new vector, and will not modify this vector.
plusScalar( scalar : number ) : Vector4¶
Addition of this vector with a scalar (adds the scalar to every component), returning a copy.
This is the immutable form of the function addScalar(). This will return a new vector, and will not modify this vector.
minus( v : Vector4 ) : Vector4¶
Subtraction of this vector by another vector v, returning a copy.
This is the immutable form of the function subtract(). This will return a new vector, and will not modify this vector.
minusXYZW( x : number, y : number, z : number, w : number ) : Vector4¶
Subtraction of this vector by another vector (x,y,z,w), returning a copy.
This is the immutable form of the function subtractXYZW(). This will return a new vector, and will not modify this vector.
minusScalar( scalar : number ) : Vector4¶
Subtraction of this vector by a scalar (subtracts the scalar from every component), returning a copy.
This is the immutable form of the function subtractScalar(). This will return a new vector, and will not modify this vector.
dividedScalar( scalar : number ) : Vector4¶
Division of this vector by a scalar (divides every component by the scalar), returning a copy.
This is the immutable form of the function divideScalar(). This will return a new vector, and will not modify this vector.
negated() : Vector4¶
Negated copy of this vector (multiplies every component by -1).
This is the immutable form of the function negate(). This will return a new vector, and will not modify this vector.
blend( vector : Vector4, ratio : number ) : Vector4¶
A linear interpolation between this vector (ratio=0) and another vector (ratio=1).
@param vector @param ratio - Not necessarily constrained in [0, 1]
average( vector : Vector4 ) : Vector4¶
The average (midpoint) between this vector and another vector.
toString() : string¶
Debugging string for the vector.
toVector3() : Vector3¶
Converts this to a 3-dimensional vector, discarding the w-component.
setXYZW( x : number, y : number, z : number, w : number ) : Vector4¶
Sets all of the components of this vector, returning this.
setX( x : number ) : Vector4¶
Sets the x-component of this vector, returning this.
setY( y : number ) : Vector4¶
Sets the y-component of this vector, returning this.
setZ( z : number ) : Vector4¶
Sets the z-component of this vector, returning this.
setW( w : number ) : Vector4¶
Sets the w-component of this vector, returning this.
set( v : Vector4 ) : Vector4¶
Sets this vector to be a copy of another vector.
This is the mutable form of the function copy(). This will mutate (change) this vector, in addition to returning this vector itself.
setMagnitude( magnitude : number ) : Vector4¶
Sets the magnitude of this vector. If the passed-in magnitude is negative, this flips the vector and sets its magnitude to abs( magnitude ).
This is the mutable form of the function withMagnitude(). This will mutate (change) this vector, in addition to returning this vector itself.
add( v : Vector4 ) : Vector4¶
Adds another vector to this vector, changing this vector.
This is the mutable form of the function plus(). This will mutate (change) this vector, in addition to returning this vector itself.
addXYZW( x : number, y : number, z : number, w : number ) : Vector4¶
Adds another vector (x,y,z,w) to this vector, changing this vector.
This is the mutable form of the function plusXYZW(). This will mutate (change) this vector, in addition to returning this vector itself.
addScalar( scalar : number ) : Vector4¶
Adds a scalar to this vector (added to every component), changing this vector.
This is the mutable form of the function plusScalar(). This will mutate (change) this vector, in addition to returning this vector itself.
subtract( v : Vector4 ) : Vector4¶
Subtracts this vector by another vector, changing this vector.
This is the mutable form of the function minus(). This will mutate (change) this vector, in addition to returning this vector itself.
subtractXYZW( x : number, y : number, z : number, w : number ) : Vector4¶
Subtracts this vector by another vector (x,y,z,w), changing this vector.
This is the mutable form of the function minusXYZW(). This will mutate (change) this vector, in addition to returning this vector itself.
subtractScalar( scalar : number ) : Vector4¶
Subtracts this vector by a scalar (subtracts each component by the scalar), changing this vector.
This is the mutable form of the function minusScalar(). This will mutate (change) this vector, in addition to returning this vector itself.
multiplyScalar( scalar : number ) : Vector4¶
Multiplies this vector by a scalar (multiplies each component by the scalar), changing this vector.
This is the mutable form of the function timesScalar(). This will mutate (change) this vector, in addition to returning this vector itself.
multiply( scalar : number ) : Vector4¶
Multiplies this vector by a scalar (multiplies each component by the scalar), changing this vector. Same as multiplyScalar.
This is the mutable form of the function times(). This will mutate (change) this vector, in addition to returning this vector itself.
componentMultiply( v : Vector4 ) : Vector4¶
Multiplies this vector by another vector component-wise, changing this vector.
This is the mutable form of the function componentTimes(). This will mutate (change) this vector, in addition to returning this vector itself.
divideScalar( scalar : number ) : Vector4¶
Divides this vector by a scalar (divides each component by the scalar), changing this vector.
This is the mutable form of the function dividedScalar(). This will mutate (change) this vector, in addition to returning this vector itself.
negate() : Vector4¶
Negates this vector (multiplies each component by -1), changing this vector.
This is the mutable form of the function negated(). This will mutate (change) this vector, in addition to returning this vector itself.
normalize() : Vector4¶
Normalizes this vector (rescales to where the magnitude is 1), changing this vector.
This is the mutable form of the function normalized(). This will mutate (change) this vector, in addition to returning this vector itself.
roundSymmetric() : Vector4¶
Rounds each component of this vector with Utils.roundSymmetric.
This is the mutable form of the function roundedSymmetric(). This will mutate (change) this vector, in addition to returning the vector itself.
freeToPool()¶
Instance Properties¶
x : number¶
The X coordinate of the vector.
y : number¶
The Y coordinate of the vector.
z : number¶
The Z coordinate of the vector.
w : number¶
The W coordinate of the vector.
isVector4 : boolean¶
dimension : number¶
Static Properties¶
pool : Pool¶
(readonly)
ZERO : Vector4¶
X_UNIT : Vector4¶
Y_UNIT : Vector4¶
Z_UNIT : Vector4¶
W_UNIT : Vector4¶
Source Code¶
See the source for Vector4.ts in the dot repository.