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 : number
The x coordinate for the vector.
y : number
The y coordinate for the vector.

Instance Methods

Public Protected Private
Defined in goog.math.Vec2
add(b) !goog.math.Vec2
Adds another vector to this vector in-place.
Arguments:
b : !goog.math.Coordinate
The vector to add.
Returns: !goog.math.Vec2  This vector with b added.
code »
clone() !goog.math.Vec2
No description.
Returns: !goog.math.Vec2  A new vector with the same coordinates as this one.
code »
equals(b) boolean
Compares this vector with another for equality.
Arguments:
b : !goog.math.Vec2
The other vector.
Returns: boolean  Whether this vector has the same x and y as the given vector.
code »
invert() !goog.math.Vec2
Reverses the sign of the vector. Equivalent to scaling the vector by -1.
Returns: !goog.math.Vec2  The inverted vector.
code »
magnitude() number
Returns the magnitude of the vector measured from the origin.
Returns: number  The length of the vector.
code »
normalize() !goog.math.Vec2
Normalizes the current vector to have a magnitude of 1.
Returns: !goog.math.Vec2  The normalized vector.
code »
rotate(angle) !goog.math.Vec2
Rotates this vector in-place by a given angle, specified in radians.
Arguments:
angle : number
The angle, in radians.
Returns: !goog.math.Vec2  This vector rotated angle radians.
code »
scale() !goog.math.Vec2
No description.
Returns: !goog.math.Vec2  This coordinate after scaling.
code »
squaredMagnitude() number
Returns the squared magnitude of the vector measured from the origin. NOTE(brenneman): Leaving out the square root is not a significant optimization in JavaScript.
Returns: number  The length of the vector, squared.
code »
subtract(b) !goog.math.Vec2
Subtracts another vector from this vector in-place.
Arguments:
b : !goog.math.Coordinate
The vector to subtract.
Returns: !goog.math.Vec2  This vector with b subtracted.
code »
ceil() !goog.math.Coordinate
Rounds the x and y fields to the next larger integer values.
Returns: !goog.math.Coordinate  This coordinate with ceil'd fields.
code »
clone() !goog.math.Coordinate
Returns a new copy of the coordinate.
Returns: !goog.math.Coordinate  A clone of this coordinate.
code »
floor() !goog.math.Coordinate
Rounds the x and y fields to the next smaller integer values.
Returns: !goog.math.Coordinate  This coordinate with floored fields.
code »
rotateDegrees(degreesopt_center)
Rotates this coordinate clockwise about the origin (or, optionally, the given center) by the given angle, in degrees.
Arguments:
degrees : number
The angle by which to rotate this coordinate clockwise about the given center, in degrees.
opt_center : !goog.math.Coordinate=
The center of rotation. Defaults to (0, 0) if not given.
code »
rotateRadians(radiansopt_center)
Rotates this coordinate clockwise about the origin (or, optionally, the given center) by the given angle, in radians.
Arguments:
radians : number
The angle by which to rotate this coordinate clockwise about the given center, in radians.
opt_center : !goog.math.Coordinate=
The center of rotation. Defaults to (0, 0) if not given.
code »
round() !goog.math.Coordinate
Rounds the x and y fields to the nearest integer values.
Returns: !goog.math.Coordinate  This coordinate with rounded fields.
code »
scale(sxopt_sy) !goog.math.Coordinate
Scales this coordinate by the given scale factors. The x and y values are scaled by sx and opt_sy respectively. If opt_sy is not given, then sx is used for both x and y.
Arguments:
sx : number
The scale factor to use for the x dimension.
opt_sy : number=
The scale factor to use for the y dimension.
Returns: !goog.math.Coordinate  This coordinate after scaling.
code »
toString() string
Returns a nice string representing the coordinate.
Returns: string  In the form (50, 73).
code »
translate(txopt_ty) !goog.math.Coordinate
Translates this box by the given offsets. If a goog.math.Coordinate is given, then the x and y values are translated by the coordinate's x and y. Otherwise, x and y are translated by tx and opt_ty respectively.
Arguments:
tx : number | goog.math.Coordinate
The value to translate x by or the the coordinate to translate this coordinate by.
opt_ty : number=
The value to translate y by.
Returns: !goog.math.Coordinate  This coordinate after translating.
code »

Instance Properties

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

Static Methods

goog.math.Vec2.difference(ab) !goog.math.Vec2
Returns the difference between two vectors as a new Vec2.
Arguments:
a : !goog.math.Coordinate
The first vector.
b : !goog.math.Coordinate
The second vector.
Returns: !goog.math.Vec2  The difference vector.
code »
goog.math.Vec2.distance(ab) number
Returns the distance between two vectors.
Arguments:
a : !goog.math.Coordinate
The first vector.
b : !goog.math.Coordinate
The second vector.
Returns: number  The distance.
code »
goog.math.Vec2.dot(ab) number
Returns the dot-product of two vectors.
Arguments:
a : !goog.math.Coordinate
The first vector.
b : !goog.math.Coordinate
The second vector.
Returns: number  The dot-product of the two vectors.
code »
goog.math.Vec2.equals(ab) boolean
Compares vectors for equality.
Arguments:
a : !goog.math.Coordinate
The first vector.
b : !goog.math.Coordinate
The second vector.
Returns: boolean  Whether the vectors have the same x and y coordinates.
code »
goog.math.Vec2.fromCoordinate(a) !goog.math.Vec2
Returns a new Vec2 object from a given coordinate.
Arguments:
a : !goog.math.Coordinate
The coordinate.
Returns: !goog.math.Vec2  A new vector object.
code »
goog.math.Vec2.lerp(abx) !goog.math.Vec2
Returns a new Vec2 that is the linear interpolant between vectors a and b at scale-value x.
Arguments:
a : !goog.math.Coordinate
Vector a.
b : !goog.math.Coordinate
Vector b.
x : number
The proportion between a and b.
Returns: !goog.math.Vec2  The interpolated vector.
code »
goog.math.Vec2.random() !goog.math.Vec2
No description.
Returns: !goog.math.Vec2  A random vector inside the unit-disc.
code »
goog.math.Vec2.randomUnit() !goog.math.Vec2
No description.
Returns: !goog.math.Vec2  A random unit-length vector.
code »
goog.math.Vec2.rotateAroundPoint(vaxisPointangle) !goog.math.Vec2
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 : !goog.math.Vec2
A vector.
axisPoint : !goog.math.Vec2
The rotation axis point.
angle : number
The angle, in radians.
Returns: !goog.math.Vec2  The rotated vector in a newly created instance.
code »
goog.math.Vec2.squaredDistance(ab) number
Returns the squared distance between two vectors.
Arguments:
a : !goog.math.Coordinate
The first vector.
b : !goog.math.Coordinate
The second vector.
Returns: number  The squared distance.
code »
goog.math.Vec2.sum(ab) !goog.math.Vec2
Returns the sum of two vectors as a new Vec2.
Arguments:
a : !goog.math.Coordinate
The first vector.
b : !goog.math.Coordinate
The second vector.
Returns: !goog.math.Vec2  The sum vector.
code »

Static Properties

goog.math.Vec2.superClass_ :
No description.
Code »

Package math

Package Reference