public class Vec3
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
double |
x
The vector's X component.
|
double |
y
The vector's Y component.
|
double |
z
The vector's Z component.
|
Constructor and Description |
---|
Vec3()
Constructs a three-component vector with X, Y and Z all 0.
|
Vec3(double x,
double y,
double z)
Constructs a three-component vector with a specified X, Y and Z.
|
Vec3(Vec3 vector)
Constructs a three-component vector with the X, Y and Z of a specified vector.
|
Modifier and Type | Method and Description |
---|---|
Vec3 |
add(Vec3 vector)
Adds a specified vector to this vector.
|
Vec3 |
cross(Vec3 vector)
Computes the cross product of this vector and a specified vector, modifying this vector.
|
Vec3 |
cross(Vec3 a,
Vec3 b)
Computes the cross product of two vectors, setting this vector to the result.
|
double |
distanceTo(Vec3 vector)
Computes the distance from this vector to another vector.
|
double |
distanceToSquared(Vec3 vector)
Computes the squared distance from this vector to a specified vector.
|
Vec3 |
divide(double divisor)
Divides this vector by a scalar.
|
double |
dot(Vec3 vector)
Computes the scalar dot product of this vector and a specified vector.
|
boolean |
equals(java.lang.Object o) |
int |
hashCode() |
double |
magnitude()
Computes the magnitude of this vector.
|
double |
magnitudeSquared()
Computes the squared magnitude of this vector.
|
Vec3 |
mix(Vec3 vector,
double weight)
Mixes (interpolates) a specified vector with this vector, modifying this vector.
|
Vec3 |
multiply(double scalar)
Multiplies this vector by a scalar.
|
Vec3 |
multiplyByMatrix(Matrix4 matrix)
Multiplies this vector by a 4x4 matrix.
|
Vec3 |
negate()
Negates the components of this vector.
|
Vec3 |
normalize()
Normalizes this vector to a unit vector.
|
Vec3 |
set(double x,
double y,
double z)
Sets this vector to the specified X, Y and Z.
|
Vec3 |
set(Vec3 vector)
Sets this vector to the X, Y and Z of a specified vector.
|
Vec3 |
subtract(Vec3 vector)
Subtracts a specified vector from this vector.
|
Vec3 |
swap(Vec3 vector)
Swaps this vector with the specified vector.
|
float[] |
toArray(float[] result,
int offset)
Copies this vector's components to the specified single precision array.
|
java.lang.String |
toString() |
public double x
public double y
public double z
public Vec3()
public Vec3(double x, double y, double z)
x
- the vector's X componenty
- the vector's Y componentz
- the vector's Z componentpublic Vec3(Vec3 vector)
vector
- the vector specifying the componentsjava.lang.IllegalArgumentException
- If the vector is nullpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public float[] toArray(float[] result, int offset)
result
- a pre-allocated array of length 3 in which to return the componentspublic double magnitude()
public double magnitudeSquared()
magnitude
but is potentially much more efficient.public double distanceTo(Vec3 vector)
vector
- The vector to compute the distance tojava.lang.IllegalArgumentException
- If the vector is nullpublic double distanceToSquared(Vec3 vector)
distanceTo
but is potentially much more efficient.vector
- the vector to compute the distance tojava.lang.IllegalArgumentException
- If the vector is nullpublic Vec3 set(double x, double y, double z)
x
- the new X componenty
- the new Y componentz
- the new Z componentpublic Vec3 set(Vec3 vector)
vector
- the vector specifying the new componentsjava.lang.IllegalArgumentException
- If the vector is nullpublic Vec3 swap(Vec3 vector)
vector
- the vector to swap with this vectorjava.lang.IllegalArgumentException
- If the vector is nullpublic Vec3 add(Vec3 vector)
vector
- the vector to addjava.lang.IllegalArgumentException
- If the vector is nullpublic Vec3 subtract(Vec3 vector)
vector
- the vector to subtractjava.lang.IllegalArgumentException
- If the vector is nullpublic Vec3 multiply(double scalar)
scalar
- the scalar to multiply this vector bypublic Vec3 multiplyByMatrix(Matrix4 matrix)
matrix
- the matrix to multiply this vector byjava.lang.IllegalArgumentException
- If the matrix is nullpublic Vec3 divide(double divisor)
divisor
- the scalar to divide this vector bypublic Vec3 negate()
public Vec3 normalize()
public double dot(Vec3 vector)
vector
- the vector to multiplyjava.lang.IllegalArgumentException
- If the vector is nullpublic Vec3 cross(Vec3 vector)
vector
- the vector to cross with this vectorjava.lang.IllegalArgumentException
- If the vector is nullpublic Vec3 cross(Vec3 a, Vec3 b)
a
- the first vectorb
- the second vectorjava.lang.IllegalArgumentException
- If either vector is nullpublic Vec3 mix(Vec3 vector, double weight)
vector
- The vector to mix with this oneweight
- The relative weight of this vector, typically in the range [0,1]java.lang.IllegalArgumentException
- If the vector is null