Package toxi.geom

Class Vec4D

java.lang.Object
toxi.geom.Vec4D
All Implemented Interfaces:
Cloneable, ReadonlyVec4D

public class Vec4D extends Object implements ReadonlyVec4D, Cloneable
  • Field Details

    • x

      public float x
      X coordinate
    • y

      public float y
      Y coordinate
    • z

      public float z
      Z coordinate
    • w

      public float w
      W coordinate (weight)
  • Constructor Details

    • Vec4D

      public Vec4D()
    • Vec4D

      public Vec4D(float x, float y, float z, float w)
    • Vec4D

      public Vec4D(ReadonlyVec3D v, float w)
    • Vec4D

      public Vec4D(ReadonlyVec4D v)
  • Method Details

    • abs

      public Vec4D abs()
    • add

      public final Vec4D add(ReadonlyVec4D v)
      Description copied from interface: ReadonlyVec4D
      Add vector v and returns result as new vector.
      Specified by:
      add in interface ReadonlyVec4D
      Parameters:
      v - vector to add
      Returns:
      result as new vector
    • addScaled

      public final Vec4D addScaled(ReadonlyVec4D t, float s)
      Specified by:
      addScaled in interface ReadonlyVec4D
    • addScaledSelf

      public final Vec4D addScaledSelf(ReadonlyVec4D t, float s)
    • addSelf

      public final Vec4D addSelf(ReadonlyVec4D v)
    • addXYZ

      public final Vec4D addXYZ(float xx, float yy, float zz)
      Description copied from interface: ReadonlyVec4D
      Adds vector {a,b,c} and returns result as new vector.
      Specified by:
      addXYZ in interface ReadonlyVec4D
      Parameters:
      xx - X coordinate
      yy - Y coordinate
      zz - Z coordinate
      Returns:
      result as new vector
    • addXYZ

      public final Vec4D addXYZ(ReadonlyVec3D v)
    • addXYZSelf

      public final Vec4D addXYZSelf(float xx, float yy, float zz)
    • addXYZSelf

      public final Vec4D addXYZSelf(ReadonlyVec3D v)
    • angleBetween

      public final float angleBetween(ReadonlyVec4D v)
      Returns the (4-space) angle in radians between this vector and the vector parameter; the return value is constrained to the range [0,PI].
      Specified by:
      angleBetween in interface ReadonlyVec4D
      Parameters:
      v - the other vector
      Returns:
      the angle in radians in the range [0,PI]
    • clone

      public Object clone()
    • compareTo

      public int compareTo(ReadonlyVec4D v)
      Description copied from interface: ReadonlyVec4D
      Compares the length of the vector with another one.
      Specified by:
      compareTo in interface ReadonlyVec4D
      Parameters:
      v - vector to compare with
      Returns:
      -1 if other vector is longer, 0 if both are equal or else +1
    • copy

      public final Vec4D copy()
      Description copied from interface: ReadonlyVec4D
      Copy.
      Specified by:
      copy in interface ReadonlyVec4D
      Returns:
      a new independent instance/copy of a given vector
    • distanceTo

      public final float distanceTo(ReadonlyVec4D v)
      Description copied from interface: ReadonlyVec4D
      Calculates distance to another vector.
      Specified by:
      distanceTo in interface ReadonlyVec4D
      Parameters:
      v - non-null vector
      Returns:
      distance or Float.NaN if v=null
    • distanceToSquared

      public final float distanceToSquared(ReadonlyVec4D v)
      Description copied from interface: ReadonlyVec4D
      Calculates the squared distance to another vector.
      Specified by:
      distanceToSquared in interface ReadonlyVec4D
      Parameters:
      v - non-null vector
      Returns:
      distance or NaN if v=null
      See Also:
    • dot

      public final float dot(ReadonlyVec4D v)
      Description copied from interface: ReadonlyVec4D
      Computes the scalar product (dot product) with the given vector.
      Specified by:
      dot in interface ReadonlyVec4D
      Parameters:
      v - the v
      Returns:
      dot product
      See Also:
    • equals

      public boolean equals(Object v)
      Returns true if the Object v is of type ReadonlyVec4D and all of the data members of v are equal to the corresponding data members in this vector.
      Specified by:
      equals in interface ReadonlyVec4D
      Overrides:
      equals in class Object
      Parameters:
      v - the Object with which the comparison is made
      Returns:
      true or false
    • equals

      public boolean equals(ReadonlyVec4D v)
      Returns true if the Object v is of type Vec4D and all of the data members of v are equal to the corresponding data members in this vector.
      Parameters:
      v - the vector with which the comparison is made
      Returns:
      true or false
    • equalsWithTolerance

      public boolean equalsWithTolerance(ReadonlyVec4D v, float tolerance)
      Description copied from interface: ReadonlyVec4D
      Compares this vector with the one given. The vectors are deemed equal if the individual differences of all component values are within the given tolerance.
      Specified by:
      equalsWithTolerance in interface ReadonlyVec4D
      Parameters:
      v - the v
      tolerance - the tolerance
      Returns:
      true, if equal
    • getAbs

      public Vec4D getAbs()
      Description copied from interface: ReadonlyVec4D
      Gets the abs.
      Specified by:
      getAbs in interface ReadonlyVec4D
      Returns:
      the abs
    • getInvertedXYZ

      public final Vec4D getInvertedXYZ()
      Description copied from interface: ReadonlyVec4D
      Scales vector uniformly by factor -1 ( v = -v ).
      Specified by:
      getInvertedXYZ in interface ReadonlyVec4D
      Returns:
      result as new vector
    • getMapped

      public Vec4D getMapped(ScaleMap map)
      Description copied from interface: ReadonlyVec4D
      Produces a new vector with all of its coordinates passed through the given ScaleMap. This version also maps the w coordinate. For mapping only XYZ use the ReadonlyVec4D.getMappedXYZ(ScaleMap) version.
      Specified by:
      getMapped in interface ReadonlyVec4D
      Returns:
      mapped vector
    • getMappedXYZ

      public Vec4D getMappedXYZ(ScaleMap map)
      Description copied from interface: ReadonlyVec4D
      Produces a new vector with only its XYZ coordinates passed through the given ScaleMap. This version keeps the original w coordinate. For mapping all XYZW, use the ReadonlyVec4D.getMapped(ScaleMap) version.
      Specified by:
      getMappedXYZ in interface ReadonlyVec4D
      Returns:
      mapped vector
    • getNormalized

      public Vec4D getNormalized()
      Description copied from interface: ReadonlyVec4D
      Produces the normalized version as a new vector.
      Specified by:
      getNormalized in interface ReadonlyVec4D
      Returns:
      new vector
    • getNormalizedTo

      public Vec4D getNormalizedTo(float len)
      Description copied from interface: ReadonlyVec4D
      Produces a new vector normalized to the given length.
      Specified by:
      getNormalizedTo in interface ReadonlyVec4D
      Parameters:
      len - new desired length
      Returns:
      new vector
    • getRotatedAroundAxis

      public Vec4D getRotatedAroundAxis(ReadonlyVec3D axis, float theta)
      Description copied from interface: ReadonlyVec4D
      Gets the rotated around axis.
      Specified by:
      getRotatedAroundAxis in interface ReadonlyVec4D
      Parameters:
      axis - the axis
      theta - the theta
      Returns:
      new result vector
    • getRotatedX

      public Vec4D getRotatedX(float theta)
      Description copied from interface: ReadonlyVec4D
      Creates a new vector rotated by the given angle around the X axis.
      Specified by:
      getRotatedX in interface ReadonlyVec4D
      Parameters:
      theta - the theta
      Returns:
      rotated vector
    • getRotatedY

      public Vec4D getRotatedY(float theta)
      Description copied from interface: ReadonlyVec4D
      Creates a new vector rotated by the given angle around the Y axis.
      Specified by:
      getRotatedY in interface ReadonlyVec4D
      Parameters:
      theta - the theta
      Returns:
      rotated vector
    • getRotatedZ

      public Vec4D getRotatedZ(float theta)
      Description copied from interface: ReadonlyVec4D
      Creates a new vector rotated by the given angle around the Z axis.
      Specified by:
      getRotatedZ in interface ReadonlyVec4D
      Parameters:
      theta - the theta
      Returns:
      rotated vector
    • getRoundedXYZTo

      public Vec4D getRoundedXYZTo(float prec)
      Description copied from interface: ReadonlyVec4D
      Creates a new vector with its XYZ coordinates rounded to the given precision (grid alignment). The weight component remains unmodified.
      Specified by:
      getRoundedXYZTo in interface ReadonlyVec4D
      Returns:
      grid aligned vector
    • getUnweighted

      public Vec4D getUnweighted()
      Specified by:
      getUnweighted in interface ReadonlyVec4D
    • getWeighted

      public Vec4D getWeighted()
      Specified by:
      getWeighted in interface ReadonlyVec4D
    • hashCode

      public int hashCode()
      Returns a hash code value based on the data values in this object. Two different Vec4D objects with identical data values (i.e., Vec4D.equals returns true) will return the same hash code value. Two objects with different data members may return the same hash value, although this is not likely.
      Overrides:
      hashCode in class Object
      Returns:
      the integer hash code value
    • interpolateTo

      public final Vec4D interpolateTo(ReadonlyVec4D v, float t)
      Description copied from interface: ReadonlyVec4D
      Interpolates the vector towards the given target vector, using linear interpolation.
      Specified by:
      interpolateTo in interface ReadonlyVec4D
      Parameters:
      v - target vector
      t - interpolation factor (should be in the range 0..1)
      Returns:
      result as new vector
    • interpolateTo

      public final Vec4D interpolateTo(ReadonlyVec4D v, float f, InterpolateStrategy s)
      Description copied from interface: ReadonlyVec4D
      Interpolates the vector towards the given target vector, using the given InterpolateStrategy.
      Specified by:
      interpolateTo in interface ReadonlyVec4D
      Parameters:
      v - target vector
      f - interpolation factor (should be in the range 0..1)
      s - InterpolateStrategy instance
      Returns:
      result as new vector
    • interpolateToSelf

      public final Vec4D interpolateToSelf(ReadonlyVec4D v, float t)
    • interpolateToSelf

      public final Vec4D interpolateToSelf(ReadonlyVec4D v, float f, InterpolateStrategy s)
    • invertXYZ

      public final Vec4D invertXYZ()
    • isZeroVector

      public final boolean isZeroVector()
      Description copied from interface: ReadonlyVec4D
      Checks if vector has a magnitude equals or close to zero (tolerance used is MathUtils.EPS).
      Specified by:
      isZeroVector in interface ReadonlyVec4D
      Returns:
      true, if zero vector
    • magnitude

      public final float magnitude()
      Description copied from interface: ReadonlyVec4D
      Calculates the magnitude/eucledian length of the vector.
      Specified by:
      magnitude in interface ReadonlyVec4D
      Returns:
      vector length
    • magSquared

      public final float magSquared()
      Description copied from interface: ReadonlyVec4D
      Calculates only the squared magnitude/length of the vector. Useful for inverse square law applications and/or for speed reasons or if the real eucledian distance is not required (e.g. sorting).
      Specified by:
      magSquared in interface ReadonlyVec4D
      Returns:
      squared magnitude (x^2 + y^2 + z^2)
    • normalize

      public final Vec4D normalize()
      Normalizes the vector so that its magnitude = 1.
      Returns:
      itself
    • normalizeTo

      public final Vec4D normalizeTo(float len)
      Normalizes the vector to the given length.
      Parameters:
      len - desired length
      Returns:
      itself
    • rotateAroundAxis

      public final Vec4D rotateAroundAxis(ReadonlyVec3D axis, float theta)
      Rotates the vector around the giving axis.
      Parameters:
      axis - rotation axis vector
      theta - rotation angle (in radians)
      Returns:
      itself
    • rotateX

      public final Vec4D rotateX(float theta)
      Rotates the vector by the given angle around the X axis.
      Parameters:
      theta - the theta
      Returns:
      itself
    • rotateY

      public final Vec4D rotateY(float theta)
      Rotates the vector by the given angle around the Y axis.
      Parameters:
      theta - the theta
      Returns:
      itself
    • rotateZ

      public final Vec4D rotateZ(float theta)
      Rotates the vector by the given angle around the Z axis.
      Parameters:
      theta - the theta
      Returns:
      itself
    • roundXYZTo

      public Vec4D roundXYZTo(float prec)
    • scale

      public final Vec4D scale(float s)
      Description copied from interface: ReadonlyVec4D
      Scales vector uniformly and returns result as new vector.
      Specified by:
      scale in interface ReadonlyVec4D
      Parameters:
      s - scale factor
      Returns:
      new vector
    • scale

      public final Vec4D scale(float xx, float yy, float zz, float ww)
      Description copied from interface: ReadonlyVec4D
      Scales vector non-uniformly and returns result as new vector.
      Specified by:
      scale in interface ReadonlyVec4D
      Parameters:
      xx - scale factor for X coordinate
      yy - scale factor for Y coordinate
      zz - scale factor for Z coordinate
      Returns:
      new vector
    • scale

      public Vec4D scale(ReadonlyVec4D s)
      Description copied from interface: ReadonlyVec4D
      Scales vector non-uniformly by vector v and returns result as new vector.
      Specified by:
      scale in interface ReadonlyVec4D
      Parameters:
      s - scale vector
      Returns:
      new vector
    • scaleSelf

      public final Vec4D scaleSelf(float s)
    • scaleSelf

      public Vec4D scaleSelf(ReadonlyVec4D s)
    • scaleXYZSelf

      public final Vec4D scaleXYZSelf(float s)
    • scaleXYZSelf

      public final Vec4D scaleXYZSelf(float xscale, float yscale, float zscale)
    • set

      public Vec4D set(float x, float y, float z, float w)
      Overrides coordinates with the given values.
      Parameters:
      x - the x
      y - the y
      z - the z
      w - the w
      Returns:
      itself
    • set

      public final Vec4D set(ReadonlyVec4D v)
    • setW

      public Vec4D setW(float w)
    • setX

      public Vec4D setX(float x)
    • setXYZ

      public final Vec4D setXYZ(ReadonlyVec3D v)
    • setY

      public Vec4D setY(float y)
    • setZ

      public Vec4D setZ(float z)
    • sub

      public final Vec4D sub(ReadonlyVec4D v)
      Description copied from interface: ReadonlyVec4D
      Subtracts vector v and returns result as new vector.
      Specified by:
      sub in interface ReadonlyVec4D
      Parameters:
      v - vector to be subtracted
      Returns:
      result as new vector
    • subSelf

      public final Vec4D subSelf(ReadonlyVec4D v)
    • subXYZ

      public final Vec4D subXYZ(float xx, float yy, float zz)
      Description copied from interface: ReadonlyVec4D
      Subtracts vector {a,b,c} and returns result as new vector.
      Specified by:
      subXYZ in interface ReadonlyVec4D
      Parameters:
      xx - X coordinate
      yy - Y coordinate
      zz - Z coordinate
      Returns:
      result as new vector
    • subXYZ

      public final Vec4D subXYZ(ReadonlyVec3D v)
    • subXYZSelf

      public final Vec4D subXYZSelf(float xx, float yy, float zz)
    • subXYZSelf

      public final Vec4D subXYZSelf(ReadonlyVec3D v)
    • to3D

      public final Vec3D to3D()
    • toArray

      public float[] toArray()
      Specified by:
      toArray in interface ReadonlyVec4D
    • toString

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

      public final Vec4D translate(float xx, float yy, float zz)
    • unweight

      public final Vec4D unweight()
      Divides each coordinate bythe weight with and sets the coordinate to the newly calculatd ones.
    • unweightInto

      public final Vec3D unweightInto(Vec3D out)
      Specified by:
      unweightInto in interface ReadonlyVec4D
    • w

      public final float w()
      Specified by:
      w in interface ReadonlyVec4D
      Returns:
      the w
    • weight

      public final Vec4D weight()
      Multiplies the weight with each coordinate and sets the coordinate to the newly calculatd ones.
      Returns:
      itself
    • weightInto

      public final Vec3D weightInto(Vec3D out)
      Specified by:
      weightInto in interface ReadonlyVec4D
    • x

      public final float x()
      Specified by:
      x in interface ReadonlyVec4D
      Returns:
      the x
    • y

      public final float y()
      Specified by:
      y in interface ReadonlyVec4D
      Returns:
      the y
    • z

      public final float z()
      Specified by:
      z in interface ReadonlyVec4D
      Returns:
      the z