Home

# Class goog.math.Vec2

Class for a two-dimensional vector object and assorted functions useful for manipulating points.

extends goog.math.Coordinate

Instance Method Summary
| `add(!goog.math.Coordinate b) ⇒ !goog.math.Vec2` Adds another vector to this vector in-place.
| `clone() ⇒ !goog.math.Vec2`
| `equals(!goog.math.Vec2 b) ⇒ boolean` Compares this vector with another for equality.
| `invert() ⇒ !goog.math.Vec2` Reverses the sign of the vector. Equivalent to scaling the vector by -1.
| `magnitude() ⇒ number` Returns the magnitude of the vector measured from the origin.
| `normalize() ⇒ !goog.math.Vec2` Normalizes the current vector to have a magnitude of 1.
| `rotate(number angle) ⇒ !goog.math.Vec2` Rotates this vector in-place by a given angle, specified in radians.
| `scale(number s) ⇒ !goog.math.Vec2` Scales the current vector by a constant.
| `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.
| `subtract(!goog.math.Coordinate b) ⇒ !goog.math.Vec2` Subtracts another vector from this vector in-place.

Static Method Summary
| `difference(!goog.math.Coordinate a, !goog.math.Coordinate b) ⇒ !goog.math.Vec2` Returns the difference between two vectors as a new Vec2.
| `dot(!goog.math.Coordinate a, !goog.math.Coordinate b) ⇒ number` Returns the dot-product of two vectors.
| `fromCoordinate(!goog.math.Coordinate a) ⇒ !goog.math.Vec2` Returns a new Vec2 object from a given coordinate.
| `lerp(!goog.math.Coordinate a, !goog.math.Coordinate b, number x) ⇒ !goog.math.Vec2` Returns a new Vec2 that is the linear interpolant between vectors a and b at scale-value x.
| `random() ⇒ !goog.math.Vec2`
| `randomUnit() ⇒ !goog.math.Vec2`
| `rotateAroundPoint(!goog.math.Vec2 v, !goog.math.Vec2 axisPoint, number angle) ⇒ !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.
| `sum(!goog.math.Coordinate a, !goog.math.Coordinate b) ⇒ !goog.math.Vec2` Returns the sum of two vectors as a new Vec2.