Class Vector3D
java.lang.Object
gaiasky.util.math.Vector3D
- All Implemented Interfaces:
VectorDouble<Vector3D>
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(double values) Adds the given value to all three components of the vector.add(double... vals) Adds the given vector to this componentadd(double x, double y, double z) Adds the given vector to this componentadd(com.badlogic.gdx.math.Vector3 vec) Adds the given vector to this vectordoubleGets the angle in degrees between the two vectorsdoubleGets the angle in degrees between the two vectorsdoubleGets the angle in degrees between the two vectorsclamp(double min, double max) Clamps this vector's length to given min and max valuescpy()static Vector3Dcrs(double x, double y, double z) Sets this vector to the cross product between it and the other vector.Sets this vector to the cross product between it and the other vector.static Vector3Ddoubledot(double x, double y, double z) Returns the dot product between this and the given vector.static doubledot(double x1, double y1, double z1, double x2, double y2, double z2) doubledoubledoubledst(double x, double y, double z) doubledoubledoubledst2(double x, double y, double z) Returns the squared distance between this point and the given pointdoubleThis method is faster thanVectorDouble.dst(VectorDouble)because it avoids calculating a square root.doublebooleanepsilonEquals(float x, float y, float z) Compares this vector with the other vector using MathUtils.FLOAT_ROUNDING_ERROR for fuzzy equality testingbooleanepsilonEquals(float x, float y, float z, float epsilon) Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.booleanepsilonEquals(Vector3D vec) Compares this vector with the other vector using MathUtils.FLOAT_ROUNDING_ERROR for fuzzy equality testingbooleanepsilonEquals(Vector3D vec, double epsilon) Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.booleandoubleReturns the latitude of this vector in the reference frame with theZaxis pointing toward the North pole and theXaxis pointing towards zero longitude.doubleReturns the longitude of this vector in the reference frame with theZaxis pointing towards the North pole and theXaxis pointing towards zero longitude.com.badlogic.gdx.math.Matrix4getMatrix(com.badlogic.gdx.math.Matrix4 aux) Sets the matrix aux to a translation matrix using this vectorSets the given matrix to a translation matrix using this vectorstatic Vector3DgetUnitX()static Vector3DgetUnitY()static Vector3DgetUnitZ()inthashCode()booleanhasNaN()booleanbooleanhasSameDirection(Vector3D vec) booleaninterpolate(Vector3D vec, double alpha, InterpolationDouble interpolator) Interpolates between this vector and the given target vector by alpha (within range [0,1]) using the given Interpolation method.booleanisCollinear(Vector3D vec) booleanisCollinear(Vector3D vec, double epsilon) booleanbooleanisCollinearOpposite(Vector3D vec, double epsilon) booleanbooleanbooleanisPerpendicular(Vector3D vec) booleanisPerpendicular(Vector3D vec, double epsilon) booleanisUnit()booleanisUnit(double margin) booleanisZero()booleanisZero(double margin) doublelen()static doublelen(double x, double y, double z) doublelen2()This method is faster thanVectorDouble.len()because it avoids calculating a square root.Linearly interpolates between this vector and the target vector by alpha which is in the range [0,1].limit(double limit) Limits the length of this vector, based on the desired maximum length.limit2(double limit2) Limits the length of this vector, based on the desired maximum length squared.Left-multiplies the vector by the given matrix.Left-multiplies the vector by the given matrix, assuming the fourth (w) component of the vector is 1.mul(QuaternionDouble quat) Multiplies the vector by the givenQuaternion.mul4x3(double[] matrix) Left-multiplies the vector by the given 4x3 column major matrix.First scale a supplied vector, then add it to this vector.First scale a supplied vector, then add it to this vector.mulLeft(com.badlogic.gdx.math.Matrix3 matrix) mulRight(com.badlogic.gdx.math.Matrix3 matrix) nor()Normalizes this vector.Multiplies this vector by the given matrix dividing by w, assuming the fourth (w) component of the vector is 1.com.badlogic.gdx.math.Vector3put(com.badlogic.gdx.math.Vector3 vec) Multiplies this vector by the first three columns of the matrix, essentially only applying rotation and scaling.rotate(double degrees, double axisX, double axisY, double axisZ) Rotates this vector by the given angle in degrees around the given axis.Rotates this vector by the given angle in degrees around the given axis.rotateRad(double radians, double axisX, double axisY, double axisZ) Rotates this vector by the given angle in radians around the given axis.Rotates this vector by the given angle in radians around the given axis.Rotates this vector by a quaternion, using "vector rotation" according to (60) in LL-072.static Vector3DScales a given vector with a scalar and add the result to this one, i.e.scl(double scalar) Scales this vector by a scalarscl(double vx, double vy, double vz) Scales this vector by the given valuesScales this vector by another vectorset(double[] values) Sets the components from the array.set(double x, double y, double z) Sets the vector to the given componentsset(float[] values) Sets the components from the array.set(com.badlogic.gdx.math.Vector3 vec) Sets this vector from the given vectorsetFromSpherical(double azimuthalAngle, double polarAngle) Sets the components from the given spherical coordinatesetLength(double len) Sets the length of this vector.setLength2(double len2) Sets the length of this vector, based on the square of the desired length.Sets this vector to the unit vector with a random directioncom.badlogic.gdx.math.Vector3setVector3(com.badlogic.gdx.math.Vector3 v) Returns set v to this vector by casting doubles to floats.setZero()Sets the components of this vector to 0.Spherically interpolates between this vector and the target vector by alpha which is in the range [0,1].sub(double value) Subtracts the given value from all components of this vectorsub(double x, double y, double z) Subtracts the other vector from this vector.sub(com.badlogic.gdx.math.Vector3 vec) Subtracts the given vector from this vector.Converts the current direction cosines to spherical coordinates.toString()com.badlogic.gdx.math.Vector3Returns a vector3 representation of this vector by casting the doubles to floats.Multiplies the vector by the transpose of the given matrix.Multiplies the vector by the transpose of the given matrix, assuming the fourth (w) component of the vector is 1.Multiplies this vector by the transpose of the first three columns of the matrix.untransform(Matrix4D matrix) Translates this vector in the direction opposite to the translation of the matrix and the multiplies this vector by the transpose of the first three columns of the matrix.double[]values()float[]valuesF()float[]valuesF(float[] vec) doublex()doubley()doublez()
-
Field Details
-
X
-
Y
-
Z
-
Zero
-
x
public double xthe x-component of this vector -
y
public double ythe y-component of this vector -
z
public double zthe z-component of this vector
-
-
Constructor Details
-
Vector3D
public Vector3D()Constructs a vector at (0,0,0) -
Vector3D
public Vector3D(double x, double y, double z) Creates a vector with the given components- Parameters:
x- The x-componenty- The y-componentz- The z-component
-
Vector3D
-
Vector3D
public Vector3D(double[] values) Creates a vector from the given array. The array must have at least 3 elements.- Parameters:
values- The array
-
-
Method Details
-
getUnitX
-
getUnitY
-
getUnitZ
-
len
public static double len(double x, double y, double z) - Returns:
- The euclidean length
-
dot
public static double dot(double x1, double y1, double z1, double x2, double y2, double z2) - Returns:
- The dot product between the two vectors
-
crs
-
cross
-
x
public double x() -
y
public double y() -
z
public double z() -
set
Sets the vector to the given components- Parameters:
x- The x-componenty- The y-componentz- The z-component- Returns:
- this vector for chaining
-
set
Description copied from interface:VectorDoubleSets this vector from the given vector- Specified by:
setin interfaceVectorDouble<Vector3D>- Parameters:
vec- The vector- Returns:
- This vector for chaining
-
set
-
set
-
put
public com.badlogic.gdx.math.Vector3 put(com.badlogic.gdx.math.Vector3 vec) -
put
-
set
Sets the components from the array. The array must have at least 3 elements- Parameters:
values- The array- Returns:
- this vector for chaining
-
set
Sets the components from the array. The array must have at least 3 elements- Parameters:
values- The array- Returns:
- this vector for chaining
-
setFromSpherical
Sets the components from the given spherical coordinate- Parameters:
azimuthalAngle- The angle between x-axis in radians [0, 2pi]polarAngle- The angle between z-axis in radians [0, pi]- Returns:
- This vector for chaining
-
setToRandomDirection
Description copied from interface:VectorDoubleSets this vector to the unit vector with a random direction- Specified by:
setToRandomDirectionin interfaceVectorDouble<Vector3D>- Returns:
- This vector for chaining
-
cpy
- Specified by:
cpyin interfaceVectorDouble<Vector3D>- Returns:
- a copy of this vector
-
add
Description copied from interface:VectorDoubleAdds the given vector to this vector- Specified by:
addin interfaceVectorDouble<Vector3D>- Parameters:
vec- The vector- Returns:
- This vector for chaining
-
add
-
add
-
add
Adds the given vector to this component- Parameters:
x- The x-component of the other vectory- The y-component of the other vectorz- The z-component of the other vector- Returns:
- This vector for chaining.
-
add
Adds the given vector to this component- Parameters:
vals- The 3-value double vector.- Returns:
- This vector for chaining.
-
add
Adds the given value to all three components of the vector.- Parameters:
values- The value- Returns:
- This vector for chaining
-
sub
Description copied from interface:VectorDoubleSubtracts the given vector from this vector.- Specified by:
subin interfaceVectorDouble<Vector3D>- Parameters:
vec- The vector- Returns:
- This vector for chaining
-
sub
-
sub
-
sub
Subtracts the other vector from this vector.- Parameters:
x- The x-component of the other vectory- The y-component of the other vectorz- The z-component of the other vector- Returns:
- This vector for chaining
-
sub
Subtracts the given value from all components of this vector- Parameters:
value- The value- Returns:
- This vector for chaining
-
scl
Description copied from interface:VectorDoubleScales this vector by a scalar- Specified by:
sclin interfaceVectorDouble<Vector3D>- Parameters:
scalar- The scalar- Returns:
- This vector for chaining
-
scale
-
scl
Description copied from interface:VectorDoubleScales this vector by another vector- Specified by:
sclin interfaceVectorDouble<Vector3D>- Returns:
- This vector for chaining
-
scl
Scales this vector by the given values- Parameters:
vx- X valuevy- Y valuevz- Z value- Returns:
- This vector for chaining
-
mulAdd
Description copied from interface:VectorDoubleFirst scale a supplied vector, then add it to this vector.- Specified by:
mulAddin interfaceVectorDouble<Vector3D>- Parameters:
vec- addition vector.scalar- for scaling the addition vector.
-
mulAdd
Description copied from interface:VectorDoubleFirst scale a supplied vector, then add it to this vector.- Specified by:
mulAddin interfaceVectorDouble<Vector3D>- Parameters:
vec- addition vector.mulVec- vector by whose values the addition vector will be scaled.
-
mul
-
div
-
len
public double len()- Specified by:
lenin interfaceVectorDouble<Vector3D>- Returns:
- The euclidean length
-
len2
public double len2()Description copied from interface:VectorDoubleThis method is faster thanVectorDouble.len()because it avoids calculating a square root. It is useful for comparisons, but not for getting exact lengths, as the return value is the square of the actual length.- Specified by:
len2in interfaceVectorDouble<Vector3D>- Returns:
- The squared euclidean length
-
idt
- Parameters:
vec- The other vector- Returns:
- Whether this and the other vector are equal
-
dst
- Specified by:
dstin interfaceVectorDouble<Vector3D>- Parameters:
vec- The other vector- Returns:
- the distance between this and the other vector
-
dst
-
dst
public double dst(double x, double y, double z) - Returns:
- the distance between this point and the given point
-
dst2
-
dst2
Description copied from interface:VectorDoubleThis method is faster thanVectorDouble.dst(VectorDouble)because it avoids calculating a square root. It is useful for comparisons, but not for getting accurate distances, as the return value is the square of the actual distance.- Specified by:
dst2in interfaceVectorDouble<Vector3D>- Parameters:
vec- The other vector- Returns:
- the squared distance between this and the other vector
-
dst2
public double dst2(double x, double y, double z) Returns the squared distance between this point and the given point- Parameters:
x- The x-component of the other pointy- The y-component of the other pointz- The z-component of the other point- Returns:
- The squared distance
-
nor
Description copied from interface:VectorDoubleNormalizes this vector. Does nothing if it is zero.- Specified by:
norin interfaceVectorDouble<Vector3D>- Returns:
- This vector for chaining
-
dot
- Specified by:
dotin interfaceVectorDouble<Vector3D>- Parameters:
vector- The other vector- Returns:
- The dot product between this and the other vector
-
dot
-
dot
public double dot(double x, double y, double z) Returns the dot product between this and the given vector.- Parameters:
x- The x-component of the other vectory- The y-component of the other vectorz- The z-component of the other vector- Returns:
- The dot product
-
crs
-
crs
Sets this vector to the cross product between it and the other vector.- Parameters:
x- The x-component of the other vectory- The y-component of the other vectorz- The z-component of the other vector- Returns:
- This vector for chaining
-
mul4x3
Left-multiplies the vector by the given 4x3 column major matrix. The matrix should be composed by a 3x3 matrix representing rotation and scale plus a 1x3 matrix representing the translation.- Parameters:
matrix- The matrix- Returns:
- This vector for chaining
-
mul
-
mulLeft
-
mulRight
-
traMul
-
mul
-
traMul
-
mul
Multiplies the vector by the givenQuaternion.- Returns:
- This vector for chaining
-
prj
Multiplies this vector by the given matrix dividing by w, assuming the fourth (w) component of the vector is 1. This is mostly used to project/unproject vectors via a perspective projection matrix.- Parameters:
matrix- The matrix.- Returns:
- This vector for chaining
-
rot
-
unrotate
Multiplies this vector by the transpose of the first three columns of the matrix. Note: only works for translation and rotation, does not work for scaling. For those, userot(Matrix4D)withMatrix4D.inv().- Parameters:
matrix- The transformation matrix- Returns:
- The vector for chaining
-
untransform
Translates this vector in the direction opposite to the translation of the matrix and the multiplies this vector by the transpose of the first three columns of the matrix. Note: only works for translation and rotation, does not work for scaling. For those, usemul(Matrix4D)withMatrix4D.inv().- Parameters:
matrix- The transformation matrix- Returns:
- The vector for chaining
-
rotate
Rotates this vector by the given angle in degrees around the given axis.- Parameters:
degrees- the angle in degreesaxisX- the x-component of the axisaxisY- the y-component of the axisaxisZ- the z-component of the axis- Returns:
- This vector for chaining
-
rotateRad
Rotates this vector by the given angle in radians around the given axis.- Parameters:
radians- the angle in radiansaxisX- the x-component of the axisaxisY- the y-component of the axisaxisZ- the z-component of the axis- Returns:
- This vector for chaining
-
rotate
-
rotateRad
-
getMatrix
public com.badlogic.gdx.math.Matrix4 getMatrix(com.badlogic.gdx.math.Matrix4 aux) Sets the matrix aux to a translation matrix using this vector- Parameters:
aux- The matrix.- Returns:
- The matrix aux.
-
getMatrix
-
isUnit
public boolean isUnit()- Specified by:
isUnitin interfaceVectorDouble<Vector3D>- Returns:
- Whether this vector is a unit length vector
-
isUnit
public boolean isUnit(double margin) - Specified by:
isUnitin interfaceVectorDouble<Vector3D>- Returns:
- Whether this vector is a unit length vector within the given margin.
-
isZero
public boolean isZero()- Specified by:
isZeroin interfaceVectorDouble<Vector3D>- Returns:
- Whether this vector is a zero vector
-
isZero
public boolean isZero(double margin) - Specified by:
isZeroin interfaceVectorDouble<Vector3D>- Returns:
- Whether the length of this vector is smaller than the given margin
-
isOnLine
- Specified by:
isOnLinein interfaceVectorDouble<Vector3D>- Returns:
- true if this vector is in line with the other vector (either in the same or the opposite direction)
-
isOnLine
- Specified by:
isOnLinein interfaceVectorDouble<Vector3D>- Returns:
- true if this vector is in line with the other vector (either in the same or the opposite direction)
-
isCollinear
- Specified by:
isCollinearin interfaceVectorDouble<Vector3D>- Returns:
- true if this vector is collinear with the other vector (
VectorDouble.isOnLine(VectorDouble, double)andVectorDouble.hasSameDirection(VectorDouble)).
-
isCollinear
- Specified by:
isCollinearin interfaceVectorDouble<Vector3D>- Returns:
- true if this vector is collinear with the other vector (
VectorDouble.isOnLine(VectorDouble)andVectorDouble.hasSameDirection(VectorDouble)).
-
isCollinearOpposite
- Specified by:
isCollinearOppositein interfaceVectorDouble<Vector3D>- Returns:
- true if this vector is opposite collinear with the other vector (
VectorDouble.isOnLine(VectorDouble, double)andVectorDouble.hasOppositeDirection(VectorDouble)).
-
isCollinearOpposite
- Specified by:
isCollinearOppositein interfaceVectorDouble<Vector3D>- Returns:
- true if this vector is opposite collinear with the other vector (
VectorDouble.isOnLine(VectorDouble)andVectorDouble.hasOppositeDirection(VectorDouble)).
-
isPerpendicular
- Specified by:
isPerpendicularin interfaceVectorDouble<Vector3D>- Returns:
- Whether this vector is perpendicular with the other vector. True if the dot product is 0.
-
isPerpendicular
- Specified by:
isPerpendicularin interfaceVectorDouble<Vector3D>- Parameters:
epsilon- a positive small number close to zero- Returns:
- Whether this vector is perpendicular with the other vector. True if the dot product is 0.
-
hasSameDirection
- Specified by:
hasSameDirectionin interfaceVectorDouble<Vector3D>- Returns:
- Whether this vector has similar direction compared to the other vector. True if the normalized dot product is >0.
-
hasOppositeDirection
- Specified by:
hasOppositeDirectionin interfaceVectorDouble<Vector3D>- Returns:
- Whether this vector has opposite direction compared to the other vector. True if the normalized dot product is <0.
-
lerp
Description copied from interface:VectorDoubleLinearly interpolates between this vector and the target vector by alpha which is in the range [0,1]. The result is stored in this vector.- Specified by:
lerpin interfaceVectorDouble<Vector3D>- Parameters:
vec- The target vectoralpha- The interpolation coefficient- Returns:
- This vector for chaining.
-
interpolate
Description copied from interface:VectorDoubleInterpolates between this vector and the given target vector by alpha (within range [0,1]) using the given Interpolation method. the result is stored in this vector.- Specified by:
interpolatein interfaceVectorDouble<Vector3D>- Parameters:
vec- The target vectoralpha- The interpolation coefficientinterpolator- An Interpolation object describing the used interpolation method- Returns:
- This vector for chaining.
-
slerp
Spherically interpolates between this vector and the target vector by alpha which is in the range [0,1]. The result is stored in this vector.- Parameters:
vec- The target vectoralpha- The interpolation coefficient- Returns:
- This vector for chaining.
-
toString
-
limit
Description copied from interface:VectorDoubleLimits the length of this vector, based on the desired maximum length.- Specified by:
limitin interfaceVectorDouble<Vector3D>- Parameters:
limit- desired maximum length for this vector- Returns:
- this vector for chaining
-
limit2
Description copied from interface:VectorDoubleLimits the length of this vector, based on the desired maximum length squared.
This method is slightly faster than limit().- Specified by:
limit2in interfaceVectorDouble<Vector3D>- Parameters:
limit2- squared desired maximum length for this vector- Returns:
- this vector for chaining
- See Also:
-
setLength
Description copied from interface:VectorDoubleSets the length of this vector. Does nothing is this vector is zero.- Specified by:
setLengthin interfaceVectorDouble<Vector3D>- Parameters:
len- desired length for this vector- Returns:
- this vector for chaining
-
setLength2
Description copied from interface:VectorDoubleSets the length of this vector, based on the square of the desired length. Does nothing is this vector is zero.
This method is slightly faster than setLength().- Specified by:
setLength2in interfaceVectorDouble<Vector3D>- Parameters:
len2- desired square of the length for this vector.- Returns:
- this vector for chaining.
- See Also:
-
clamp
Description copied from interface:VectorDoubleClamps this vector's length to given min and max values- Specified by:
clampin interfaceVectorDouble<Vector3D>- Parameters:
min- Min lengthmax- Max length- Returns:
- This vector for chaining
-
values
public double[] values() -
valuesF
public float[] valuesF() -
valuesF
public float[] valuesF(float[] vec) -
scaleAdd
-
toVector3
public com.badlogic.gdx.math.Vector3 toVector3()Returns a vector3 representation of this vector by casting the doubles to floats. This creates a new object- Returns:
- The vector3 representation of this vector3d
-
setVector3
public com.badlogic.gdx.math.Vector3 setVector3(com.badlogic.gdx.math.Vector3 v) Returns set v to this vector by casting doubles to floats.- Returns:
- The float vector v.
-
rotateVectorByQuaternion
Rotates this vector by a quaternion, using "vector rotation" according to (60) in LL-072. Both the original and the returned vectors are expressed in the same reference frame as the quaternion.- Parameters:
q- Quaternion defining the vector rotation.- Returns:
- the rotated vector.
-
angle
Gets the angle in degrees between the two vectors -
angle
Gets the angle in degrees between the two vectors -
anglePrecise
Gets the angle in degrees between the two vectors -
hasNaN
public boolean hasNaN() -
hashCode
-
equals
-
epsilonEquals
Description copied from interface:VectorDoubleCompares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.- Specified by:
epsilonEqualsin interfaceVectorDouble<Vector3D>- Parameters:
vec- The other vector.epsilon- The maximum deviation.- Returns:
- whether the vectors have fuzzy equality.
-
epsilonEquals
public boolean epsilonEquals(float x, float y, float z, float epsilon) Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.- Returns:
- whether the vectors are the same.
-
epsilonEquals
Compares this vector with the other vector using MathUtils.FLOAT_ROUNDING_ERROR for fuzzy equality testing- Parameters:
vec- other vector to compare- Returns:
- true if vector are equal, otherwise false
-
epsilonEquals
public boolean epsilonEquals(float x, float y, float z) Compares this vector with the other vector using MathUtils.FLOAT_ROUNDING_ERROR for fuzzy equality testing- Parameters:
x- x component of the other vector to comparey- y component of the other vector to comparez- z component of the other vector to compare- Returns:
- true if vector are equal, otherwise false
-
setZero
Description copied from interface:VectorDoubleSets the components of this vector to 0.- Specified by:
setZeroin interfaceVectorDouble<Vector3D>- Returns:
- This vector for chaining.
-
getLatitude
public double getLatitude()Returns the latitude of this vector in the reference frame with theZaxis pointing toward the North pole and theXaxis pointing towards zero longitude.- Returns:
- latitude [rad] of the vector in the range [-Pi/2, +Pi]
-
getLongitude
public double getLongitude()Returns the longitude of this vector in the reference frame with theZaxis pointing towards the North pole and theXaxis pointing towards zero longitude.- Returns:
- longitude [rad] of the vector in the range [0, 2Pi)
-
toSphericalCoordinates
-