The goog.math.Vec3 Class

goog.math.Vec3
> goog.math.Coordinate3

goog.math.Vec3(x, y, z)

Class for a three-dimensional vector object and assorted functions useful for manipulation. Inherits from goog.math.Coordinate3 so that a Vec3 may be passed in to any function that requires a Coordinate.

x {number}
The x value for the vector.
y {number}
The y value for the vector.
z {number}
The z value for the vector.

.add(b)

Adds another vector to this vector in-place.

b {goog.math.Vec3}
The vector to add.
returns {!goog.math.Vec3}
This vector with {@code b} added.

.clone()

Creates a new copy of this Vec3.

returns {!goog.math.Vec3}
A new vector with the same coordinates as this one.

.cross(a, b)

Returns the cross-product of two vectors.

a {goog.math.Vec3}
The first vector.
b {goog.math.Vec3}
The second vector.
returns {!goog.math.Vec3}
The cross-product of the two vectors.

.difference(a, b)

Returns the difference of two vectors as a new Vec3.

a {goog.math.Vec3}
The first vector.
b {goog.math.Vec3}
The second vector.
returns {!goog.math.Vec3}
The difference vector.

.distance

Returns the distance between two vectors.

a {goog.math.Vec3}
The first vector.
b {goog.math.Vec3}
The second vector.
returns {number}
The distance.

.dot(a, b)

Returns the dot-product of two vectors.

a {goog.math.Vec3}
The first vector.
b {goog.math.Vec3}
The second vector.
returns {number}
The dot-product of the two vectors.

.equals(b)

Compares this vector with another for equality.

b {goog.math.Vec3}
The other vector.
returns {boolean}
True if this vector's x, y and z equal the given vector's x, y, and z, respectively.

.fromCoordinate3(a)

Returns a new Vec3 object from a given coordinate.

a {goog.math.Coordinate3}
The coordinate.
returns {!goog.math.Vec3}
A new vector object.

.invert()

Reverses the sign of the vector. Equivalent to scaling the vector by -1.

returns {!goog.math.Vec3}
This vector, inverted.

.lerp(a, b, x)

Returns a new Vec3 that is the linear interpolant between vectors a and b at scale-value x.

a {goog.math.Vec3}
Vector a.
b {goog.math.Vec3}
Vector b.
x {number}
The proportion between a and b.
returns {!goog.math.Vec3}
The interpolated vector.

.magnitude()

Returns the magnitude of the vector measured from the origin.

returns {number}
The length of the vector.

.normalize()

Normalizes the current vector to have a magnitude of 1.

returns {!goog.math.Vec3}
This vector, normalized.

.random()

Generates a random vector inside the unit sphere.

returns {!goog.math.Vec3}
A random vector.

.randomUnit()

Generates a random unit vector. http://mathworld.wolfram.com/SpherePointPicking.html Using (6), (7), and (8) to generate coordinates.

returns {!goog.math.Vec3}
A random unit-length vector.

.scale(s)

Scales the current vector by a constant.

s {number}
The scale factor.
returns {!goog.math.Vec3}
This vector, scaled.

.squaredDistance

Returns the squared distance between two vectors.

a {goog.math.Vec3}
The first vector.
b {goog.math.Vec3}
The second vector.
returns {number}
The squared distance.

.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.

returns {number}
The length of the vector, squared.

.subtract(b)

Subtracts another vector from this vector in-place.

b {goog.math.Vec3}
The vector to subtract.
returns {!goog.math.Vec3}
This vector with {@code b} subtracted.

.sum(a, b)

Returns the sum of two vectors as a new Vec3.

a {goog.math.Vec3}
The first vector.
b {goog.math.Vec3}
The second vector.
returns {!goog.math.Vec3}
The sum vector.

.toArray()

Inherited from goog.math.Coordinate3 .

Returns the contents of this coordinate as a 3 value Array.

returns {!Array.<number>}
A new array.

.toString()

Inherited from goog.math.Coordinate3 .

Returns a nice string representing the coordinate.

returns {string}
In the form (50, 73, 31).

.x {number}

X-value

.y {number}

Y-value

.z {number}

Z-value