math.Vec2 Extends goog.math.Coordinate
Class for a two-dimensional vector object and assorted functions useful for manipulating points.

Inheritance

Constructor

goog.math.Vec2(xy)

Parameters

x :
The x coordinate for the vector.
y :
The y coordinate for the vector.

Instance Methods

Public Protected Private
Defined in goog.math.Vec2
add(b)
Adds another vector to this vector in-place. Uses goog.math.Vec2.sum(a, b) to return a new vector.
Arguments:
b :
The vector to add.
Returns:   This vector with b added.
code »
clone()
No description.
Returns:   A new vector with the same coordinates as this one.
code »
equals(b)
Compares this vector with another for equality.
Arguments:
b :
The other vector.
Returns:   Whether this vector has the same x and y as the given vector.
code »
invert()
Reverses the sign of the vector. Equivalent to scaling the vector by -1.
Returns:   The inverted vector.
code »
magnitude()
Returns the magnitude of the vector measured from the origin.
Returns:   The length of the vector.
code »
normalize()
Normalizes the current vector to have a magnitude of 1.
Returns:   The normalized vector.
code »
rotate(angle)
Rotates this vector in-place by a given angle, specified in radians.
Arguments:
angle :
The angle, in radians.
Returns:   This vector rotated angle radians.
code »
scale(s)
Scales the current vector by a constant.
Arguments:
s :
The scale factor.
Returns:   The scaled vector.
code »
squaredMagnitude()
Returns the squared magnitude of the vector measured from the origin. NOTE(user): Leaving out the square root is not a significant optimization in JavaScript.
Returns:   The length of the vector, squared.
code »
subtract(b)
Subtracts another vector from this vector in-place. Uses goog.math.Vec2.difference(a, b) to return a new vector.
Arguments:
b :
The vector to subtract.
Returns:   This vector with b subtracted.
code »
clone()
Returns a new copy of the coordinate.
Returns:   A clone of this coordinate.
code »
toString()
Returns a nice string representing the coordinate.
Returns:   In the form (50, 73).
code »

Instance Properties

Defined in goog.math.Vec2
x :
X-value
Code »
y :
Y-value
Code »
x :
X-value
Code »
y :
Y-value
Code »

Static Methods

goog.math.Vec2.difference(ab)
Returns the difference between two vectors as a new Vec2.
Arguments:
a :
The first vector.
b :
The second vector.
Returns:   The difference vector.
code »
goog.math.Vec2.distance(ab)
Returns the distance between two vectors.
Arguments:
a :
The first vector.
b :
The second vector.
Returns:   The distance.
code »
goog.math.Vec2.dot(ab)
Returns the dot-product of two vectors.
Arguments:
a :
The first vector.
b :
The second vector.
Returns:   The dot-product of the two vectors.
code »
goog.math.Vec2.equals(ab)
Compares vectors for equality.
Arguments:
a :
The first vector.
b :
The second vector.
Returns:   Whether the vectors have the same x and y coordinates.
code »
goog.math.Vec2.fromCoordinate(a)
Returns a new Vec2 object from a given coordinate.
Arguments:
a :
The coordinate.
Returns:   A new vector object.
code »
goog.math.Vec2.lerp(abx)
Returns a new Vec2 that is the linear interpolant between vectors a and b at scale-value x.
Arguments:
a :
Vector a.
b :
Vector b.
x :
The proportion between a and b.
Returns:   The interpolated vector.
code »
goog.math.Vec2.random()
No description.
Returns:   A random vector inside the unit-disc.
code »
goog.math.Vec2.randomUnit()
No description.
Returns:   A random unit-length vector.
code »
goog.math.Vec2.rotateAroundPoint(vaxisPointangle)
Rotates a vector by a given angle, specified in radians, relative to a given axis rotation point. The returned vector is a newly created instance - no in-place changes are done.
Arguments:
v :
A vector.
axisPoint :
The rotation axis point.
angle :
The angle, in radians.
Returns:   The rotated vector in a newly created instance.
code »
goog.math.Vec2.squaredDistance(ab)
Returns the squared distance between two vectors.
Arguments:
a :
The first vector.
b :
The second vector.
Returns:   The squared distance.
code »
goog.math.Vec2.sum(ab)
Returns the sum of two vectors as a new Vec2.
Arguments:
a :
The first vector.
b :
The second vector.
Returns:   The sum vector.
code »

Package math

Package Reference