Class Vector4d

java.lang.Object
gaiasky.util.math.Vector4d
All Implemented Interfaces:
VectorDouble<Vector4d>, Serializable

public class Vector4d extends Object implements Serializable, VectorDouble<Vector4d>
See Also:
  • Field Details

    • x

      public double x
    • y

      public double y
    • z

      public double z
    • w

      public double w
    • X

      public static final Vector4d X
    • Y

      public static final Vector4d Y
    • Z

      public static final Vector4d Z
    • W

      public static final Vector4d W
    • Zero

      public static final Vector4d Zero
  • Constructor Details

    • Vector4d

      public Vector4d()
    • Vector4d

      public Vector4d(double x, double y, double z, double w)
    • Vector4d

      public Vector4d(Vector4d vector)
    • 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

      public Vector4d set(double x, double y, double z, double w)
    • set

      public Vector4d set(Vector4d vector)
      Description copied from interface: VectorDouble
      Sets this vector from the given vector
      Specified by:
      set in interface VectorDouble<Vector4d>
      Parameters:
      vector - The vector
      Returns:
      This vector for chaining
    • set

      public Vector4d set(double[] values)
    • set

      public Vector4d set(com.badlogic.gdx.math.Vector2 vector, double z, double w)
    • set

      public Vector4d set(com.badlogic.gdx.math.Vector3 vector, double w)
    • setToRandomDirection

      public Vector4d setToRandomDirection()
      Description copied from interface: VectorDouble
      Sets this vector to the unit vector with a random direction
      Specified by:
      setToRandomDirection in interface VectorDouble<Vector4d>
      Returns:
      This vector for chaining
    • cpy

      public Vector4d cpy()
      Specified by:
      cpy in interface VectorDouble<Vector4d>
      Returns:
      a copy of this vector
    • add

      public Vector4d add(Vector4d vector)
      Description copied from interface: VectorDouble
      Adds the given vector to this vector
      Specified by:
      add in interface VectorDouble<Vector4d>
      Parameters:
      vector - The vector
      Returns:
      This vector for chaining
    • add

      public Vector4d add(double x, double y, double z, double w)
    • add

      public Vector4d add(double values)
    • sub

      public Vector4d sub(Vector4d a_vec)
      Description copied from interface: VectorDouble
      Subtracts the given vector from this vector.
      Specified by:
      sub in interface VectorDouble<Vector4d>
      Parameters:
      a_vec - The vector
      Returns:
      This vector for chaining
    • sub

      public Vector4d sub(double x, double y, double z, double w)
    • sub

      public Vector4d sub(double value)
    • scl

      public Vector4d scl(double scalar)
      Description copied from interface: VectorDouble
      Scales this vector by a scalar
      Specified by:
      scl in interface VectorDouble<Vector4d>
      Parameters:
      scalar - The scalar
      Returns:
      This vector for chaining
    • scl

      public Vector4d scl(Vector4d other)
      Description copied from interface: VectorDouble
      Scales this vector by another vector
      Specified by:
      scl in interface VectorDouble<Vector4d>
      Returns:
      This vector for chaining
    • scl

      public Vector4d scl(double vx, double vy, double vz, double vw)
    • mulAdd

      public Vector4d mulAdd(Vector4d vec, double scalar)
      Description copied from interface: VectorDouble
      First scale a supplied vector, then add it to this vector.
      Specified by:
      mulAdd in interface VectorDouble<Vector4d>
      Parameters:
      vec - addition vector.
      scalar - for scaling the addition vector.
    • mulAdd

      public Vector4d mulAdd(Vector4d vec, Vector4d mulVec)
      Description copied from interface: VectorDouble
      First scale a supplied vector, then add it to this vector.
      Specified by:
      mulAdd in interface VectorDouble<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 interface VectorDouble<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 than VectorDouble.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 interface VectorDouble<Vector4d>
      Returns:
      The squared euclidean length
    • idt

      public boolean idt(Vector4d vector)
    • dst

      public static double dst(double x1, double y1, double z1, double w1, double x2, double y2, double z2, double w2)
    • dst

      public double dst(Vector4d vector)
      Specified by:
      dst in interface VectorDouble<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

      public double dst2(Vector4d point)
      Description copied from interface: VectorDouble
      This method is faster than VectorDouble.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 interface VectorDouble<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

      public Vector4d nor()
      Description copied from interface: VectorDouble
      Normalizes this vector. Does nothing if it is zero.
      Specified by:
      nor in interface VectorDouble<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

      public double dot(Vector4d vector)
      Specified by:
      dot in interface VectorDouble<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 interface VectorDouble<Vector4d>
      Returns:
      Whether this vector is a unit length vector
    • isUnit

      public boolean isUnit(double margin)
      Specified by:
      isUnit in interface VectorDouble<Vector4d>
      Returns:
      Whether this vector is a unit length vector within the given margin.
    • isZero

      public boolean isZero()
      Specified by:
      isZero in interface VectorDouble<Vector4d>
      Returns:
      Whether this vector is a zero vector
    • isZero

      public boolean isZero(double margin)
      Specified by:
      isZero in interface VectorDouble<Vector4d>
      Returns:
      Whether the length of this vector is smaller than the given margin
    • isOnLine

      public boolean isOnLine(Vector4d other, double epsilon)
      Specified by:
      isOnLine in interface VectorDouble<Vector4d>
      Returns:
      true if this vector is in line with the other vector (either in the same or the opposite direction)
    • isOnLine

      public boolean isOnLine(Vector4d other)
      Specified by:
      isOnLine in interface VectorDouble<Vector4d>
      Returns:
      true if this vector is in line with the other vector (either in the same or the opposite direction)
    • isCollinear

      public boolean isCollinear(Vector4d other, double epsilon)
      Specified by:
      isCollinear in interface VectorDouble<Vector4d>
      Returns:
      true if this vector is collinear with the other vector (VectorDouble.isOnLine(VectorDouble, double) and VectorDouble.hasSameDirection(VectorDouble)).
    • isCollinear

      public boolean isCollinear(Vector4d other)
      Specified by:
      isCollinear in interface VectorDouble<Vector4d>
      Returns:
      true if this vector is collinear with the other vector (VectorDouble.isOnLine(VectorDouble) and VectorDouble.hasSameDirection(VectorDouble)).
    • isCollinearOpposite

      public boolean isCollinearOpposite(Vector4d other, double epsilon)
      Specified by:
      isCollinearOpposite in interface VectorDouble<Vector4d>
      Returns:
      true if this vector is opposite collinear with the other vector (VectorDouble.isOnLine(VectorDouble, double) and VectorDouble.hasOppositeDirection(VectorDouble)).
    • isCollinearOpposite

      public boolean isCollinearOpposite(Vector4d other)
      Specified by:
      isCollinearOpposite in interface VectorDouble<Vector4d>
      Returns:
      true if this vector is opposite collinear with the other vector (VectorDouble.isOnLine(VectorDouble) and VectorDouble.hasOppositeDirection(VectorDouble)).
    • isPerpendicular

      public boolean isPerpendicular(Vector4d vector)
      Specified by:
      isPerpendicular in interface VectorDouble<Vector4d>
      Returns:
      Whether this vector is perpendicular with the other vector. True if the dot product is 0.
    • isPerpendicular

      public boolean isPerpendicular(Vector4d vector, double epsilon)
      Specified by:
      isPerpendicular in interface VectorDouble<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

      public boolean hasSameDirection(Vector4d vector)
      Specified by:
      hasSameDirection in interface VectorDouble<Vector4d>
      Returns:
      Whether this vector has similar direction compared to the other vector. True if the normalized dot product is >0.
    • hasOppositeDirection

      public boolean hasOppositeDirection(Vector4d vector)
      Specified by:
      hasOppositeDirection in interface VectorDouble<Vector4d>
      Returns:
      Whether this vector has opposite direction compared to the other vector. True if the normalized dot product is <0.
    • lerp

      public Vector4d lerp(Vector4d target, double alpha)
      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 interface VectorDouble<Vector4d>
      Parameters:
      target - The target vector
      alpha - The interpolation coefficient
      Returns:
      This vector for chaining.
    • interpolate

      public Vector4d interpolate(Vector4d target, double alpha, InterpolationDouble interpolator)
      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 interface VectorDouble<Vector4d>
      Parameters:
      target - The target vector
      alpha - The interpolation coefficient
      interpolator - An Interpolation object describing the used interpolation method
      Returns:
      This vector for chaining.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • fromString

      public Vector4d fromString(String v)
    • limit

      public Vector4d limit(double limit)
      Description copied from interface: VectorDouble
      Limits the length of this vector, based on the desired maximum length.
      Specified by:
      limit in interface VectorDouble<Vector4d>
      Parameters:
      limit - desired maximum length for this vector
      Returns:
      this vector for chaining
    • limit2

      public Vector4d limit2(double 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 interface VectorDouble<Vector4d>
      Parameters:
      limit2 - squared desired maximum length for this vector
      Returns:
      this vector for chaining
      See Also:
    • setLength

      public Vector4d setLength(double len)
      Description copied from interface: VectorDouble
      Sets the length of this vector. Does nothing is this vector is zero.
      Specified by:
      setLength in interface VectorDouble<Vector4d>
      Parameters:
      len - desired length for this vector
      Returns:
      this vector for chaining
    • setLength2

      public Vector4d setLength2(double len2)
      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 interface VectorDouble<Vector4d>
      Parameters:
      len2 - desired square of the length for this vector.
      Returns:
      this vector for chaining.
      See Also:
    • clamp

      public Vector4d clamp(double min, double max)
      Description copied from interface: VectorDouble
      Clamps this vector's length to given min and max values
      Specified by:
      clamp in interface VectorDouble<Vector4d>
      Parameters:
      min - Min length
      max - Max length
      Returns:
      This vector for chaining
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • epsilonEquals

      public boolean epsilonEquals(Vector4d other, double epsilon)
      Description copied from interface: VectorDouble
      Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.
      Specified by:
      epsilonEquals in interface VectorDouble<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

      public boolean epsilonEquals(Vector4d other)
    • epsilonEquals

      public boolean epsilonEquals(double x, double y, double z, double w)
    • setZero

      public Vector4d setZero()
      Description copied from interface: VectorDouble
      Sets the components of this vector to 0.
      Specified by:
      setZero in interface VectorDouble<Vector4d>
      Returns:
      This vector for chaining.