Package gaiasky.util.math
Class Vector4d
java.lang.Object
gaiasky.util.math.Vector4d
- All Implemented Interfaces:
VectorDouble<Vector4d>,Serializable
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
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()doubledot(double x, double y, double z, double w) static doubledot(double x1, double y1, double z1, double w1, double x2, double y2, double z2, double w2) doubledoubledst(double x, double y, double z, double w) static doubledst(double x1, double y1, double z1, double w1, double x2, double y2, double z2, double w2) doubledoubledst2(double x, double y, double z, double w) static doubledst2(double x1, double y1, double z1, double w1, double x2, double y2, double z2, double w2) doubleThis method is faster thanVectorDouble.dst(VectorDouble)because it avoids calculating a square root.booleanepsilonEquals(double x, double y, double z, double w) booleanepsilonEquals(double x, double y, double z, double w, double epsilon) booleanepsilonEquals(Vector4d other) booleanepsilonEquals(Vector4d other, double epsilon) Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.booleanfromString(String v) inthashCode()booleanhasOppositeDirection(Vector4d vector) booleanhasSameDirection(Vector4d vector) booleaninterpolate(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.booleanisCollinear(Vector4d other) booleanisCollinear(Vector4d other, double epsilon) booleanisCollinearOpposite(Vector4d other) booleanisCollinearOpposite(Vector4d other, double epsilon) booleanbooleanbooleanisPerpendicular(Vector4d vector) booleanisPerpendicular(Vector4d vector, double epsilon) booleanisUnit()booleanisUnit(double margin) booleanisZero()booleanisZero(double margin) doublelen()static doublelen(double x, double y, double z, double w) doublelen2()This method is faster thanVectorDouble.len()because it avoids calculating a square root.static doublelen2(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:VectorDoubleSets this vector from the given vector- Specified by:
setin interfaceVectorDouble<Vector4d>- Parameters:
vector- The vector- Returns:
- This vector for chaining
-
set
-
set
-
set
-
setToRandomDirection
Description copied from interface:VectorDoubleSets this vector to the unit vector with a random direction- Specified by:
setToRandomDirectionin interfaceVectorDouble<Vector4d>- Returns:
- This vector for chaining
-
cpy
- Specified by:
cpyin interfaceVectorDouble<Vector4d>- Returns:
- a copy of this vector
-
add
Description copied from interface:VectorDoubleAdds the given vector to this vector- Specified by:
addin interfaceVectorDouble<Vector4d>- Parameters:
vector- The vector- Returns:
- This vector for chaining
-
add
-
add
-
sub
Description copied from interface:VectorDoubleSubtracts the given vector from this vector.- Specified by:
subin interfaceVectorDouble<Vector4d>- Parameters:
a_vec- The vector- Returns:
- This vector for chaining
-
sub
-
sub
-
scl
Description copied from interface:VectorDoubleScales this vector by a scalar- Specified by:
sclin interfaceVectorDouble<Vector4d>- Parameters:
scalar- The scalar- Returns:
- This vector for chaining
-
scl
Description copied from interface:VectorDoubleScales this vector by another vector- Specified by:
sclin interfaceVectorDouble<Vector4d>- Returns:
- This vector for chaining
-
scl
-
mulAdd
Description copied from interface:VectorDoubleFirst scale a supplied vector, then add it to this vector.- Specified by:
mulAddin interfaceVectorDouble<Vector4d>- 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<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:
lenin 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: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<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:
dstin 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: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<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:VectorDoubleNormalizes this vector. Does nothing if it is zero.- Specified by:
norin 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:
dotin 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:
isUnitin interfaceVectorDouble<Vector4d>- Returns:
- Whether this vector is a unit length vector
-
isUnit
public boolean isUnit(double margin) - Specified by:
isUnitin interfaceVectorDouble<Vector4d>- Returns:
- Whether this vector is a unit length vector within the given margin.
-
isZero
public boolean isZero()- Specified by:
isZeroin interfaceVectorDouble<Vector4d>- Returns:
- Whether this vector is a zero vector
-
isZero
public boolean isZero(double margin) - Specified by:
isZeroin interfaceVectorDouble<Vector4d>- Returns:
- Whether the length of this vector is smaller than the given margin
-
isOnLine
- Specified by:
isOnLinein 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:
isOnLinein 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:
isCollinearin interfaceVectorDouble<Vector4d>- Returns:
- true if this vector is collinear with the other vector (
VectorDouble.isOnLine(VectorDouble, double)andVectorDouble.hasSameDirection(VectorDouble)).
-
isCollinear
- Specified by:
isCollinearin interfaceVectorDouble<Vector4d>- Returns:
- true if this vector is collinear with the other vector (
VectorDouble.isOnLine(VectorDouble)andVectorDouble.hasSameDirection(VectorDouble)).
-
isCollinearOpposite
- Specified by:
isCollinearOppositein interfaceVectorDouble<Vector4d>- Returns:
- true if this vector is opposite collinear with the other vector (
VectorDouble.isOnLine(VectorDouble, double)andVectorDouble.hasOppositeDirection(VectorDouble)).
-
isCollinearOpposite
- Specified by:
isCollinearOppositein interfaceVectorDouble<Vector4d>- Returns:
- true if this vector is opposite collinear with the other vector (
VectorDouble.isOnLine(VectorDouble)andVectorDouble.hasOppositeDirection(VectorDouble)).
-
isPerpendicular
- Specified by:
isPerpendicularin interfaceVectorDouble<Vector4d>- Returns:
- Whether this vector is perpendicular with the other vector. True if the dot product is 0.
-
isPerpendicular
- Specified by:
isPerpendicularin interfaceVectorDouble<Vector4d>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<Vector4d>- 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<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: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<Vector4d>- Parameters:
target- 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<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:VectorDoubleLimits the length of this vector, based on the desired maximum length.- Specified by:
limitin interfaceVectorDouble<Vector4d>- 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<Vector4d>- 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<Vector4d>- 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<Vector4d>- 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<Vector4d>- Parameters:
min- Min lengthmax- Max length- Returns:
- This vector for chaining
-
hashCode
public int 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<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:VectorDoubleSets the components of this vector to 0.- Specified by:
setZeroin interfaceVectorDouble<Vector4d>- Returns:
- This vector for chaining.
-