craftyjs.github.com

Crafty.math.Vector2D

Vector2D uses the following form: <x, y>

public {Vector2D} Vector2D();

public {Vector2D} Vector2D(Vector2D);

public {Vector2D} Vector2D(Number, Number);

{Vector2D|Number=0} x
{Number=0} y
Back to top

.add

Adds the passed vector to this vector

public {Vector2D} add(Vector2D);

{vector2D} vecRH
Back to top

.angleBetween

Calculates the angle between the passed vector and this vector, using <0,0> as the point of reference. Angles returned have the range (−π, π].

public {Number} angleBetween(Vector2D);

{Vector2D} vecRH
Back to top

.angleTo

Calculates the angle to the passed vector from this vector, using this vector as the point of reference.

public {Number} angleTo(Vector2D);

{Vector2D} vecRH
Back to top

.clone

Creates an exact, numeric copy of the current matrix

public {Matrix2D} clone();

Back to top

.distance

Calculates the distance from this vector to the passed vector.

public {Number} distance(Vector2D);

{Vector2D} vecRH
Back to top

.distanceSq

Calculates the squared distance from this vector to the passed vector. This function avoids calculating the square root, thus being slightly faster than .distance( ).

public {Number} distanceSq(Vector2D);

{Vector2D} vecRH

See Also

Back to top

.divide

Divides this vector by the passed vector.

public {Vector2D} divide(Vector2D);

{Vector2D} vecRH
Back to top

.dotProduct

Calculates the dot product of this and the passed vectors

public {Number} dotProduct(Vector2D);

{Vector2D} vecRH
Back to top

.equals

Checks for the numeric equality of this matrix versus another.

public {Boolean} equals(Matrix2D);

{Matrix2D} mtrxRH
Back to top

.getNormal

Calculates a new right-handed normal vector for the line created by this and the passed vectors.

public {Vector2D} getNormal([Vector2D]);

{Vector2D=<0,0>} [vecRH]
Back to top

.isZero

Determines if this vector is equal to <0,0>

public {Boolean} isZero();

Back to top

.magnitude

Calculates the magnitude of this vector. Note: Function objects in JavaScript already have a 'length' member, hence the use of magnitude instead.

public {Number} magnitude();

Back to top

.magnitudeSq

Calculates the square of the magnitude of this vector. This function avoids calculating the square root, thus being slightly faster than .magnitude( ).

public {Number} magnitudeSq();

See Also

Back to top

.multiply

Multiplies this vector by the passed vector

public {Vector2D} multiply(Vector2D);

{Vector2D} vecRH
Back to top

.negate

Negates this vector (ie. <-x,-y>)

public {Vector2D} negate();

Back to top

.normalize

Normalizes this vector (scales the vector so that its new magnitude is 1) For vectors where magnitude is 0, <1,0> is returned.

public {Vector2D} normalize();

Back to top

.scale

Applies a post-scaling to this matrix

public {Matrix2D} scale(Number[, Number]);

{Number} scalarX
{Number} [scalarY] scalarX is used if scalarY is undefined
Back to top

.scaleToMagnitude

Scales this vector such that its new magnitude is equal to the passed value.

public {Vector2D} scaleToMagnitude(Number);

{Number} mag
Back to top

.setValues

Sets the values of this matrix

public {Matrix2D} setValues(Matrix2D);

public {Matrix2D} setValues(Number, Number, Number, Number, Number, Number);

{Matrix2D|Number} a
{Number} b
{Number} c
{Number} d
{Number} e
{Number} f
Back to top

.subtract

Subtracts the passed vector from this vector.

public {Vector2D} subtract(Vector2D);

{Vector2D} vecRH
Back to top

.toString

Returns the string representation of this matrix.

public {String} toString();

Back to top

.translate

Applies a post-translation to this matrix

public {Matrix2D} translate(Vector2D);

public {Matrix2D} translate(Number, Number);

{Number|Vector2D} dx
{Number} dy
Back to top

.tripleProduct

Calculates the triple product of three vectors. triple vector product = b(a•c) - a(b•c)

public {Vector2D} tripleProduct(Vector2D, Vector2D, Vector2D);

{Vector2D} a
{Vector2D} b
{Vector2D} c

Returns

{Vector2D} the triple product as a new vector