Package gov.nasa.worldwind.geom
Class Vec3
- java.lang.Object
-
- gov.nasa.worldwind.geom.Vec3
-
public class Vec3 extends java.lang.Object
Three-component vector with X, Y and Z coordinates.
-
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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()
-
-
-
Constructor Detail
-
Vec3
public Vec3()
Constructs a three-component vector with X, Y and Z all 0.
-
Vec3
public Vec3(double x, double y, double z)
Constructs a three-component vector with a specified X, Y and Z.- Parameters:
x
- the vector's X componenty
- the vector's Y componentz
- the vector's Z component
-
Vec3
public Vec3(Vec3 vector)
Constructs a three-component vector with the X, Y and Z of a specified vector.- Parameters:
vector
- the vector specifying the components- Throws:
java.lang.IllegalArgumentException
- If the vector is null
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
@NonNull public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toArray
public float[] toArray(float[] result, int offset)
Copies this vector's components to the specified single precision array. The result is compatible with GLSL uniform vectors, and can be passed to the function glUniform3fv.- Parameters:
result
- a pre-allocated array of length 3 in which to return the components- Returns:
- the result argument set to this vector's components
-
magnitude
public double magnitude()
Computes the magnitude of this vector.- Returns:
- the magnitude of this vector
-
magnitudeSquared
public double magnitudeSquared()
Computes the squared magnitude of this vector. This is equivalent to squaring the result ofmagnitude
but is potentially much more efficient.- Returns:
- the squared magnitude of this vector
-
distanceTo
public double distanceTo(Vec3 vector)
Computes the distance from this vector to another vector.- Parameters:
vector
- The vector to compute the distance to- Returns:
- the distance between the vectors
- Throws:
java.lang.IllegalArgumentException
- If the vector is null
-
distanceToSquared
public double distanceToSquared(Vec3 vector)
Computes the squared distance from this vector to a specified vector. This is equivalent to squaring the result ofdistanceTo
but is potentially much more efficient.- Parameters:
vector
- the vector to compute the distance to- Returns:
- the squared distance between the vectors
- Throws:
java.lang.IllegalArgumentException
- If the vector is null
-
set
public Vec3 set(double x, double y, double z)
Sets this vector to the specified X, Y and Z.- Parameters:
x
- the new X componenty
- the new Y componentz
- the new Z component- Returns:
- this vector set to the specified values
-
set
public Vec3 set(Vec3 vector)
Sets this vector to the X, Y and Z of a specified vector.- Parameters:
vector
- the vector specifying the new components- Returns:
- this vector with its X, Y and Z set to that of the specified vector
- Throws:
java.lang.IllegalArgumentException
- If the vector is null
-
swap
public Vec3 swap(Vec3 vector)
Swaps this vector with the specified vector. This vector's components are set to the values of the specified vector's components, and the specified vector's components are set to the values of this vector's components.- Parameters:
vector
- the vector to swap with this vector- Returns:
- this vector set to the values of the specified vector
- Throws:
java.lang.IllegalArgumentException
- If the vector is null
-
add
public Vec3 add(Vec3 vector)
Adds a specified vector to this vector.- Parameters:
vector
- the vector to add- Returns:
- this vector after adding the specified vector to it
- Throws:
java.lang.IllegalArgumentException
- If the vector is null
-
subtract
public Vec3 subtract(Vec3 vector)
Subtracts a specified vector from this vector.- Parameters:
vector
- the vector to subtract- Returns:
- this vector after subtracting the specified vector from it
- Throws:
java.lang.IllegalArgumentException
- If the vector is null
-
multiply
public Vec3 multiply(double scalar)
Multiplies this vector by a scalar.- Parameters:
scalar
- the scalar to multiply this vector by- Returns:
- this vector multiplied by the specified scalar
-
multiplyByMatrix
public Vec3 multiplyByMatrix(Matrix4 matrix)
Multiplies this vector by a 4x4 matrix. The multiplication is performed with an implicit W component of 1. The resultant W component of the product is then divided through the X, Y, and Z components.- Parameters:
matrix
- the matrix to multiply this vector by- Returns:
- this vector multiplied by the specified matrix
- Throws:
java.lang.IllegalArgumentException
- If the matrix is null
-
divide
public Vec3 divide(double divisor)
Divides this vector by a scalar.- Parameters:
divisor
- the scalar to divide this vector by- Returns:
- this vector divided by the specified scalar
-
negate
public Vec3 negate()
Negates the components of this vector.- Returns:
- this vector, negated
-
normalize
public Vec3 normalize()
Normalizes this vector to a unit vector.- Returns:
- this vector, normalized
-
dot
public double dot(Vec3 vector)
Computes the scalar dot product of this vector and a specified vector.- Parameters:
vector
- the vector to multiply- Returns:
- the dot product of the two vectors
- Throws:
java.lang.IllegalArgumentException
- If the vector is null
-
cross
public Vec3 cross(Vec3 vector)
Computes the cross product of this vector and a specified vector, modifying this vector.- Parameters:
vector
- the vector to cross with this vector- Returns:
- this vector set to the cross product of itself and the specified vector
- Throws:
java.lang.IllegalArgumentException
- If the vector is null
-
cross
public Vec3 cross(Vec3 a, Vec3 b)
Computes the cross product of two vectors, setting this vector to the result.- Parameters:
a
- the first vectorb
- the second vector- Returns:
- this vector set to the cross product of the two specified vectors
- Throws:
java.lang.IllegalArgumentException
- If either vector is null
-
mix
public Vec3 mix(Vec3 vector, double weight)
Mixes (interpolates) a specified vector with this vector, modifying this vector.- Parameters:
vector
- The vector to mix with this oneweight
- The relative weight of this vector, typically in the range [0,1]- Returns:
- this vector modified to the mix of itself and the specified vector
- Throws:
java.lang.IllegalArgumentException
- If the vector is null
-
-