Package gaiasky.util.math
Class Vector4d
java.lang.Object
gaiasky.util.math.Vector4d
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionadd
(double values) add
(double x, double y, double z, double w) Adds the given vector to this vectorclamp
(double min, double max) Clamps this vector's length to given min and max valuescpy()
double
dot
(double x, double y, double z, double w) static double
dot
(double x1, double y1, double z1, double w1, double x2, double y2, double z2, double w2) double
double
dst
(double x, double y, double z, double w) static double
dst
(double x1, double y1, double z1, double w1, double x2, double y2, double z2, double w2) double
double
dst2
(double x, double y, double z, double w) static double
dst2
(double x1, double y1, double z1, double w1, double x2, double y2, double z2, double w2) double
This method is faster thanVectorDouble.dst(VectorDouble)
because it avoids calculating a square root.boolean
epsilonEquals
(double x, double y, double z, double w) boolean
epsilonEquals
(double x, double y, double z, double w, double epsilon) boolean
epsilonEquals
(Vector4d other) boolean
epsilonEquals
(Vector4d other, double epsilon) Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.boolean
fromString
(String v) int
hashCode()
boolean
hasOppositeDirection
(Vector4d vector) boolean
hasSameDirection
(Vector4d vector) boolean
interpolate
(Vector4d target, double alpha, InterpolationDouble interpolator) Interpolates between this vector and the given target vector by alpha (within range [0,1]) using the given Interpolation method.boolean
isCollinear
(Vector4d other) boolean
isCollinear
(Vector4d other, double epsilon) boolean
isCollinearOpposite
(Vector4d other) boolean
isCollinearOpposite
(Vector4d other, double epsilon) boolean
boolean
boolean
isPerpendicular
(Vector4d vector) boolean
isPerpendicular
(Vector4d vector, double epsilon) boolean
isUnit()
boolean
isUnit
(double margin) boolean
isZero()
boolean
isZero
(double margin) double
len()
static double
len
(double x, double y, double z, double w) double
len2()
This method is faster thanVectorDouble.len()
because it avoids calculating a square root.static double
len2
(double x, double y, double z, double w) 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.First scale a supplied vector, then add it to this vector.First scale a supplied vector, then add it to this vector.nor()
Normalizes this vector.scl
(double scalar) Scales this vector by a scalarscl
(double vx, double vy, double vz, double vw) Scales this vector by another vectorset
(double[] values) set
(double x, double y, double z, double w) set
(com.badlogic.gdx.math.Vector2 vector, double z, double w) set
(com.badlogic.gdx.math.Vector3 vector, double w) Sets this vector from the given vectorsetLength
(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 directionsetZero()
Sets the components of this vector to 0.sub
(double value) sub
(double x, double y, double z, double w) Subtracts the given vector from this vector.toString()
-
Field Details
-
x
public double x -
y
public double y -
z
public double z -
w
public double w -
X
-
Y
-
Z
-
W
-
Zero
-
-
Constructor Details
-
Vector4d
public Vector4d() -
Vector4d
public Vector4d(double x, double y, double z, double w) -
Vector4d
-
Vector4d
public Vector4d(double[] values) -
Vector4d
public Vector4d(com.badlogic.gdx.math.Vector2 vector, double z, double w) -
Vector4d
public Vector4d(com.badlogic.gdx.math.Vector3 vector, double w)
-
-
Method Details
-
set
-
set
Description copied from interface:VectorDouble
Sets this vector from the given vector- Specified by:
set
in interfaceVectorDouble<Vector4d>
- Parameters:
vector
- The vector- Returns:
- This vector for chaining
-
set
-
set
-
set
-
setToRandomDirection
Description copied from interface:VectorDouble
Sets this vector to the unit vector with a random direction- Specified by:
setToRandomDirection
in interfaceVectorDouble<Vector4d>
- Returns:
- This vector for chaining
-
cpy
- Specified by:
cpy
in interfaceVectorDouble<Vector4d>
- Returns:
- a copy of this vector
-
add
Description copied from interface:VectorDouble
Adds the given vector to this vector- Specified by:
add
in interfaceVectorDouble<Vector4d>
- Parameters:
vector
- The vector- Returns:
- This vector for chaining
-
add
-
add
-
sub
Description copied from interface:VectorDouble
Subtracts the given vector from this vector.- Specified by:
sub
in interfaceVectorDouble<Vector4d>
- Parameters:
a_vec
- The vector- Returns:
- This vector for chaining
-
sub
-
sub
-
scl
Description copied from interface:VectorDouble
Scales this vector by a scalar- Specified by:
scl
in interfaceVectorDouble<Vector4d>
- Parameters:
scalar
- The scalar- Returns:
- This vector for chaining
-
scl
Description copied from interface:VectorDouble
Scales this vector by another vector- Specified by:
scl
in interfaceVectorDouble<Vector4d>
- Returns:
- This vector for chaining
-
scl
-
mulAdd
Description copied from interface:VectorDouble
First scale a supplied vector, then add it to this vector.- Specified by:
mulAdd
in interfaceVectorDouble<Vector4d>
- Parameters:
vec
- addition vector.scalar
- for scaling the addition vector.
-
mulAdd
Description copied from interface:VectorDouble
First scale a supplied vector, then add it to this vector.- Specified by:
mulAdd
in interfaceVectorDouble<Vector4d>
- Parameters:
vec
- addition vector.mulVec
- vector by whose values the addition vector will be scaled.
-
len
public static double len(double x, double y, double z, double w) -
len
public double len()- Specified by:
len
in interfaceVectorDouble<Vector4d>
- Returns:
- The euclidean length
-
len2
public static double len2(double x, double y, double z, double w) -
len2
public double len2()Description copied from interface:VectorDouble
This 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:
len2
in interfaceVectorDouble<Vector4d>
- Returns:
- The squared euclidean length
-
idt
-
dst
public static double dst(double x1, double y1, double z1, double w1, double x2, double y2, double z2, double w2) -
dst
- Specified by:
dst
in interfaceVectorDouble<Vector4d>
- Parameters:
vector
- The other vector- Returns:
- the distance between this and the other vector
-
dst
public double dst(double x, double y, double z, double w) -
dst2
public static double dst2(double x1, double y1, double z1, double w1, double x2, double y2, double z2, double w2) -
dst2
Description copied from interface:VectorDouble
This 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:
dst2
in interfaceVectorDouble<Vector4d>
- Parameters:
point
- The other vector- Returns:
- the squared distance between this and the other vector
-
dst2
public double dst2(double x, double y, double z, double w) -
nor
Description copied from interface:VectorDouble
Normalizes this vector. Does nothing if it is zero.- Specified by:
nor
in interfaceVectorDouble<Vector4d>
- Returns:
- This vector for chaining
-
dot
public static double dot(double x1, double y1, double z1, double w1, double x2, double y2, double z2, double w2) -
dot
- Specified by:
dot
in interfaceVectorDouble<Vector4d>
- Parameters:
vector
- The other vector- Returns:
- The dot product between this and the other vector
-
dot
public double dot(double x, double y, double z, double w) -
isUnit
public boolean isUnit()- Specified by:
isUnit
in interfaceVectorDouble<Vector4d>
- Returns:
- Whether this vector is a unit length vector
-
isUnit
public boolean isUnit(double margin) - Specified by:
isUnit
in interfaceVectorDouble<Vector4d>
- Returns:
- Whether this vector is a unit length vector within the given margin.
-
isZero
public boolean isZero()- Specified by:
isZero
in interfaceVectorDouble<Vector4d>
- Returns:
- Whether this vector is a zero vector
-
isZero
public boolean isZero(double margin) - Specified by:
isZero
in interfaceVectorDouble<Vector4d>
- Returns:
- Whether the length of this vector is smaller than the given margin
-
isOnLine
- Specified by:
isOnLine
in interfaceVectorDouble<Vector4d>
- Returns:
- true if this vector is in line with the other vector (either in the same or the opposite direction)
-
isOnLine
- Specified by:
isOnLine
in interfaceVectorDouble<Vector4d>
- Returns:
- true if this vector is in line with the other vector (either in the same or the opposite direction)
-
isCollinear
- Specified by:
isCollinear
in interfaceVectorDouble<Vector4d>
- Returns:
- true if this vector is collinear with the other vector (
VectorDouble.isOnLine(VectorDouble, double)
andVectorDouble.hasSameDirection(VectorDouble)
).
-
isCollinear
- Specified by:
isCollinear
in interfaceVectorDouble<Vector4d>
- Returns:
- true if this vector is collinear with the other vector (
VectorDouble.isOnLine(VectorDouble)
andVectorDouble.hasSameDirection(VectorDouble)
).
-
isCollinearOpposite
- Specified by:
isCollinearOpposite
in interfaceVectorDouble<Vector4d>
- Returns:
- true if this vector is opposite collinear with the other vector (
VectorDouble.isOnLine(VectorDouble, double)
andVectorDouble.hasOppositeDirection(VectorDouble)
).
-
isCollinearOpposite
- Specified by:
isCollinearOpposite
in interfaceVectorDouble<Vector4d>
- Returns:
- true if this vector is opposite collinear with the other vector (
VectorDouble.isOnLine(VectorDouble)
andVectorDouble.hasOppositeDirection(VectorDouble)
).
-
isPerpendicular
- Specified by:
isPerpendicular
in interfaceVectorDouble<Vector4d>
- Returns:
- Whether this vector is perpendicular with the other vector. True if the dot product is 0.
-
isPerpendicular
- Specified by:
isPerpendicular
in interfaceVectorDouble<Vector4d>
- 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:
hasSameDirection
in interfaceVectorDouble<Vector4d>
- Returns:
- Whether this vector has similar direction compared to the other vector. True if the normalized dot product is >0.
-
hasOppositeDirection
- Specified by:
hasOppositeDirection
in interfaceVectorDouble<Vector4d>
- 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:VectorDouble
Linearly 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:
lerp
in interfaceVectorDouble<Vector4d>
- Parameters:
target
- The target vectoralpha
- The interpolation coefficient- Returns:
- This vector for chaining.
-
interpolate
Description copied from interface:VectorDouble
Interpolates 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:
interpolate
in interfaceVectorDouble<Vector4d>
- Parameters:
target
- The target vectoralpha
- The interpolation coefficientinterpolator
- An Interpolation object describing the used interpolation method- Returns:
- This vector for chaining.
-
toString
-
fromString
-
limit
Description copied from interface:VectorDouble
Limits the length of this vector, based on the desired maximum length.- Specified by:
limit
in interfaceVectorDouble<Vector4d>
- Parameters:
limit
- desired maximum length for this vector- Returns:
- this vector for chaining
-
limit2
Description copied from interface:VectorDouble
Limits the length of this vector, based on the desired maximum length squared.
This method is slightly faster than limit().- Specified by:
limit2
in interfaceVectorDouble<Vector4d>
- Parameters:
limit2
- squared desired maximum length for this vector- Returns:
- this vector for chaining
- See Also:
-
setLength
Description copied from interface:VectorDouble
Sets the length of this vector. Does nothing is this vector is zero.- Specified by:
setLength
in interfaceVectorDouble<Vector4d>
- Parameters:
len
- desired length for this vector- Returns:
- this vector for chaining
-
setLength2
Description copied from interface:VectorDouble
Sets 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:
setLength2
in interfaceVectorDouble<Vector4d>
- Parameters:
len2
- desired square of the length for this vector.- Returns:
- this vector for chaining.
- See Also:
-
clamp
Description copied from interface:VectorDouble
Clamps this vector's length to given min and max values- Specified by:
clamp
in interfaceVectorDouble<Vector4d>
- Parameters:
min
- Min lengthmax
- Max length- Returns:
- This vector for chaining
-
hashCode
-
equals
-
epsilonEquals
Description copied from interface:VectorDouble
Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.- Specified by:
epsilonEquals
in interfaceVectorDouble<Vector4d>
- Parameters:
other
- The other vector.epsilon
- The maximum deviation.- Returns:
- whether the vectors have fuzzy equality.
-
epsilonEquals
public boolean epsilonEquals(double x, double y, double z, double w, double epsilon) -
epsilonEquals
-
epsilonEquals
public boolean epsilonEquals(double x, double y, double z, double w) -
setZero
Description copied from interface:VectorDouble
Sets the components of this vector to 0.- Specified by:
setZero
in interfaceVectorDouble<Vector4d>
- Returns:
- This vector for chaining.
-