goog.math.Vec2
Classgoog.math.Vec2
> goog.math.Coordinate
goog.math.Vec2(x, y)
Class for a two-dimensional vector object and assorted functions useful for manipulating points.
x
{number
}
y
{number
}
.add(b)
Adds another vector to this vector in-place.
b
{!goog.math.Coordinate
}
goog.math.Vec2
}
.clone()
Returns a new copy of the coordinate.
goog.math.Vec2
}
.difference(a, b)
Returns the difference between two vectors as a new Vec2.
a
{!goog.math.Coordinate
}
b
{!goog.math.Coordinate
}
goog.math.Vec2
}
.distance
Returns the distance between two vectors.
a
{!goog.math.Coordinate
}
b
{!goog.math.Coordinate
}
number
}
.dot(a, b)
Returns the dot-product of two vectors.
a
{!goog.math.Coordinate
}
b
{!goog.math.Coordinate
}
number
}
.equals(b)
Compares this vector with another for equality.
b
{!goog.math.Vec2
}
boolean
}
.fromCoordinate(a)
Returns a new Vec2 object from a given coordinate.
a
{!goog.math.Coordinate
}
goog.math.Vec2
}
.invert()
Reverses the sign of the vector. Equivalent to scaling the vector by -1.
goog.math.Vec2
}
.lerp(a, b, x)
Returns a new Vec2 that is the linear interpolant between vectors a and b at scale-value x.
a
{!goog.math.Coordinate
}
b
{!goog.math.Coordinate
}
x
{number
}
goog.math.Vec2
}
.magnitude()
Returns the magnitude of the vector measured from the origin.
number
}
.normalize()
Normalizes the current vector to have a magnitude of 1.
goog.math.Vec2
}
.random()
goog.math.Vec2
}
.randomUnit()
goog.math.Vec2
}
.rotate(angle)
Rotates this vector in-place by a given angle, specified in radians.
angle
{number
}
goog.math.Vec2
}
.rotateAroundPoint(v, axisPoint, angle)
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.
v
{!goog.math.Vec2
}
axisPoint
{!goog.math.Vec2
}
angle
{number
}
goog.math.Vec2
}
.scale(s)
Scales the current vector by a constant.
s
{number
}
goog.math.Vec2
}
.squaredDistance
Returns the squared distance between two vectors.
a
{!goog.math.Coordinate
}
b
{!goog.math.Coordinate
}
number
}
.squaredMagnitude()
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.
number
}
.subtract(b)
Subtracts another vector from this vector in-place.
b
{!goog.math.Coordinate
}
goog.math.Vec2
}
.sum(a, b)
Returns the sum of two vectors as a new Vec2.
a
{!goog.math.Coordinate
}
b
{!goog.math.Coordinate
}
goog.math.Vec2
}
.toString()
Inherited from goog.math.Coordinate
.
Returns a nice string representing the coordinate.
string
}
.x
{number
}X-value
.y
{number
}Y-value