t3d. Vector2

The vector 2 class

Constructor

new Vector2(xopt, yopt)

Parameters:
NameTypeAttributesDefaultDescription
xNumber<optional>
0the x value of this vector.
yNumber<optional>
0the y value of this vector.

Methods

add(v) → {t3d.Vector2}

Adds v to this vector.
Parameters:
NameTypeDescription
vt3d.Vector2
Returns:
Type: 
t3d.Vector2

addVectors(a, b) → {t3d.Vector2}

Sets this vector to a + b.
Parameters:
NameTypeDescription
at3d.Vector2
bt3d.Vector2
Returns:
Type: 
t3d.Vector2

angle() → {Number}

Computes the angle in radians of this vector with respect to the positive x-axis.
Returns:
Type: 
Number

clone() → {t3d.Vector2}

Returns a new Vector2 with the same x and y values as this one.
Returns:
Type: 
t3d.Vector2

copy(v) → {t3d.Vector2}

Copies the values of the passed Vector2's x and y properties to this Vector2.
Parameters:
NameTypeDescription
vt3d.Vector2
Returns:
Type: 
t3d.Vector2

distanceTo(v) → {Number}

Computes the distance from this vector to v.
Parameters:
NameTypeDescription
vt3d.Vector2
Returns:
Type: 
Number

distanceToSquared(v) → {Number}

Computes the squared distance from this vector to v. If you are just comparing the distance with another distance, you should compare the distance squared instead as it is slightly more efficient to calculate.
Parameters:
NameTypeDescription
vt3d.Vector2
Returns:
Type: 
Number

dot(a) → {Number}

Calculate the dot product of this vector and v.
Parameters:
NameTypeDescription
at3d.Vector2
Returns:
Type: 
Number

fromArray(array, offsetopt, denormalizeopt) → {t3d.Vector2}

Sets this vector's x value to be array[ offset ] and y value to be array[ offset + 1 ].
Parameters:
NameTypeAttributesDefaultDescription
arrayArray.<Number>the source array.
offsetNumber<optional>
0offset into the array.
denormalizeBoolean<optional>
falseif true, denormalize the values, and array should be a typed array.
Returns:
Type: 
t3d.Vector2

getLength() → {Number}

Computes the Euclidean length (straight-line length) from (0, 0) to (x, y).
Returns:
Type: 
Number

getLengthSquared() → {Number}

Computes the square of the Euclidean length (straight-line length) from (0, 0) to (x, y). If you are comparing the lengths of vectors, you should compare the length squared instead as it is slightly more efficient to calculate.
Returns:
Type: 
Number

lerpVectors(v1, v2, ratio) → {t3d.Vector2}

Sets this vector to be the vector linearly interpolated between v1 and v2 where ratio is the percent distance along the line connecting the two vectors - ratio = 0 will be v1, and ratio = 1 will be v2.
Parameters:
NameTypeDescription
v1t3d.Vector2the starting Vector2.
v2t3d.Vector2Vector2 to interpolate towards.
ratioNumberinterpolation factor, typically in the closed interval [0, 1].
Returns:
Type: 
t3d.Vector2

max(v) → {t3d.Vector2}

If this vector's x or y value is less than v's x or y value, replace that value with the corresponding max value.
Parameters:
NameTypeDescription
vt3d.Vector2
Returns:
Type: 
t3d.Vector2

min(v) → {t3d.Vector2}

If this vector's x or y value is greater than v's x or y value, replace that value with the corresponding min value.
Parameters:
NameTypeDescription
vt3d.Vector2
Returns:
Type: 
t3d.Vector2

multiplyScalar(scalar) → {t3d.Vector2}

Multiplies this vector by scalar.
Parameters:
NameTypeDescription
scalarNumber
Returns:
Type: 
t3d.Vector2

negate() → {t3d.Vector2}

Inverts this vector - i.e. sets x = -x, y = -y.
Returns:
Type: 
t3d.Vector2

normalize(thicknessopt) → {t3d.Vector2}

Converts this vector to a unit vector - that is, sets it equal to a vector with the same direction as this one, but length 1.
Parameters:
NameTypeAttributesDefaultDescription
thicknessNumber<optional>
1
Returns:
Type: 
t3d.Vector2

set(x, y) → {t3d.Vector2}

Sets the x and y components of this vector.
Parameters:
NameTypeDefaultDescription
xNumber0
yNumber0
Returns:
Type: 
t3d.Vector2

sub(v) → {t3d.Vector2}

Subtracts v from this vector.
Parameters:
NameTypeDescription
vt3d.Vector2
Returns:
Type: 
t3d.Vector2

subVectors(a, b) → {t3d.Vector2}

Sets this vector to a - b.
Parameters:
NameTypeDescription
at3d.Vector2
bt3d.Vector2
Returns:
Type: 
t3d.Vector2

subtract(a, target) → {t3d.Vector2}

Subtracts v from the vector.
Parameters:
NameTypeDescription
at3d.Vector2
targett3d.Vector2the result vector2
Returns:
Type: 
t3d.Vector2

toArray(arrayopt, offsetopt, normalizeopt) → {Array.<Number>}

Sets this array[ offset ] value to be vector's x and array[ offset + 1 ] to be vector's y.
Parameters:
NameTypeAttributesDefaultDescription
arrayArray.<Number><optional>
the target array.
offsetNumber<optional>
0offset into the array.
normalizeBoolean<optional>
falseif true, normalize the values, and array should be a typed array.
Returns:
Type: 
Array.<Number>