Package toxi.geom

Interface ReadonlyVec3D

All Known Implementing Classes:
AABB, AudioSource, Cone, DLAParticle, Plane, PointOctree, Ray3D, SoundListener, Sphere, Vec3D, VerletParticle3D, Vertex, WEVertex

public interface ReadonlyVec3D
Readonly, immutable interface wrapper for Vec3D instances. Used throughout the library for safety purposes.
  • Method Details

    • add

      Vec3D add(float a, float b, float c)
      Adds vector {a,b,c} and returns result as new vector.
      Parameters:
      a - X coordinate
      b - Y coordinate
      c - Z coordinate
      Returns:
      result as new vector
    • add

    • add

      Vec3D add(Vec3D v)
      Add vector v and returns result as new vector.
      Parameters:
      v - vector to add
      Returns:
      result as new vector
    • angleBetween

      float angleBetween(ReadonlyVec3D v)
      Computes the angle between this vector and vector V. This function assumes both vectors are normalized, if this can't be guaranteed, use the alternative implementation angleBetween(ReadonlyVec3D, boolean)
      Parameters:
      v - vector
      Returns:
      angle in radians, or NaN if vectors are parallel
    • angleBetween

      float angleBetween(ReadonlyVec3D v, boolean forceNormalize)
      Computes the angle between this vector and vector V.
      Parameters:
      v - vector
      forceNormalize - true, if normalized versions of the vectors are to be used (Note: only copies will be used, original vectors will not be altered by this method)
      Returns:
      angle in radians, or NaN if vectors are parallel
    • compareTo

      int compareTo(ReadonlyVec3D v)
      Compares the length of the vector with another one.
      Parameters:
      v - vector to compare with
      Returns:
      -1 if other vector is longer, 0 if both are equal or else +1
    • copy

      Vec3D copy()
      Copy.
      Returns:
      a new independent instance/copy of a given vector
    • cross

      Vec3D cross(ReadonlyVec3D v)
      Calculates cross-product with vector v. The resulting vector is perpendicular to both the current and supplied vector.
      Parameters:
      v - vector to cross
      Returns:
      cross-product as new vector
    • crossInto

      Vec3D crossInto(ReadonlyVec3D v, Vec3D result)
      Calculates cross-product with vector v. The resulting vector is perpendicular to both the current and supplied vector and stored in the supplied result vector.
      Parameters:
      v - vector to cross
      result - result vector
      Returns:
      result vector
    • distanceTo

      float distanceTo(ReadonlyVec3D v)
      Calculates distance to another vector.
      Parameters:
      v - non-null vector
      Returns:
      distance or Float.NaN if v=null
    • distanceToSquared

      float distanceToSquared(ReadonlyVec3D v)
      Calculates the squared distance to another vector.
      Parameters:
      v - non-null vector
      Returns:
      distance or NaN if v=null
      See Also:
    • dot

      float dot(ReadonlyVec3D v)
      Computes the scalar product (dot product) with the given vector.
      Parameters:
      v - the v
      Returns:
      dot product
      See Also:
    • equals

      boolean equals(Object obj)
      Overrides:
      equals in class Object
    • equalsWithTolerance

      boolean equalsWithTolerance(ReadonlyVec3D v, float tolerance)
      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.
      Parameters:
      v - the v
      tolerance - the tolerance
      Returns:
      true, if equal
    • getAbs

      Vec3D getAbs()
      Gets the abs.
      Returns:
      the abs
    • getCartesian

      Vec3D getCartesian()
      Converts the spherical vector back into cartesian coordinates.
      Returns:
      new vector
    • getClosestAxis

      Vec3D.Axis getClosestAxis()
    • getComponent

      float getComponent(Vec3D.Axis id)
    • getComponent

      float getComponent(int id)
    • getConstrained

      Vec3D getConstrained(AABB box)
      Creates a copy of the vector which forcefully fits in the given AABB.
      Parameters:
      box - the box
      Returns:
      fitted vector
    • getFloored

      Vec3D getFloored()
      Creates a new vector whose components are the integer value of their current values.
      Returns:
      result as new vector
    • getFrac

      Vec3D getFrac()
      Creates a new vector whose components are the fractional part of their current values.
      Returns:
      result as new vector
    • getInverted

      Vec3D getInverted()
      Scales vector uniformly by factor -1 ( v = -v ).
      Returns:
      result as new vector
    • getLimited

      Vec3D getLimited(float lim)
      Creates a copy of the vector with its magnitude limited to the length given.
      Parameters:
      lim - new maximum magnitude
      Returns:
      result as new vector
    • getMapped

      Vec3D getMapped(ScaleMap map)
      Produces a new vector with its coordinates passed through the given ScaleMap.
      Parameters:
      map -
      Returns:
      mapped vector
    • getNormalized

      Vec3D getNormalized()
      Produces the normalized version as a new vector.
      Returns:
      new vector
    • getNormalizedTo

      Vec3D getNormalizedTo(float len)
      Produces a new vector normalized to the given length.
      Parameters:
      len - new desired length
      Returns:
      new vector
    • getReciprocal

      Vec3D getReciprocal()
      Returns a multiplicative inverse copy of the vector.
      Returns:
      new vector
    • getReflected

      Vec3D getReflected(ReadonlyVec3D normal)
    • getRotatedAroundAxis

      Vec3D getRotatedAroundAxis(ReadonlyVec3D axis, float theta)
      Gets the rotated around axis.
      Parameters:
      axis - the axis
      theta - the theta
      Returns:
      new result vector
    • getRotatedX

      Vec3D getRotatedX(float theta)
      Creates a new vector rotated by the given angle around the X axis.
      Parameters:
      theta - the theta
      Returns:
      rotated vector
    • getRotatedY

      Vec3D getRotatedY(float theta)
      Creates a new vector rotated by the given angle around the Y axis.
      Parameters:
      theta - the theta
      Returns:
      rotated vector
    • getRotatedZ

      Vec3D getRotatedZ(float theta)
      Creates a new vector rotated by the given angle around the Z axis.
      Parameters:
      theta - the theta
      Returns:
      rotated vector
    • getRoundedTo

      Vec3D getRoundedTo(float prec)
      Creates a new vector with its coordinates rounded to the given precision (grid alignment).
      Parameters:
      prec -
      Returns:
      grid aligned vector
    • getSignum

      Vec3D getSignum()
      Creates a new vector in which all components are replaced with the signum of their original values. In other words if a components value was negative its new value will be -1, if zero => 0, if positive => +1
      Returns:
      result vector
    • getSpherical

      Vec3D getSpherical()
      Converts the vector into spherical coordinates. After the conversion the vector components are to be interpreted as:
      • x = radius
      • y = azimuth
      • z = theta
      Returns:
      new vector
    • headingXY

      float headingXY()
      Computes the vector's direction in the XY plane (for example for 2D points). The positive X axis equals 0 degrees.
      Returns:
      rotation angle
    • headingXZ

      float headingXZ()
      Computes the vector's direction in the XZ plane. The positive X axis equals 0 degrees.
      Returns:
      rotation angle
    • headingYZ

      float headingYZ()
      Computes the vector's direction in the YZ plane. The positive Z axis equals 0 degrees.
      Returns:
      rotation angle
    • interpolateTo

      Vec3D interpolateTo(ReadonlyVec3D v, float f)
      Interpolates the vector towards the given target vector, using linear interpolation.
      Parameters:
      v - target vector
      f - interpolation factor (should be in the range 0..1)
      Returns:
      result as new vector
    • interpolateTo

      Vec3D interpolateTo(ReadonlyVec3D v, float f, InterpolateStrategy s)
      Interpolates the vector towards the given target vector, using the given InterpolateStrategy.
      Parameters:
      v - target vector
      f - interpolation factor (should be in the range 0..1)
      s - InterpolateStrategy instance
      Returns:
      result as new vector
    • isInAABB

      boolean isInAABB(AABB box)
      Checks if the point is inside the given AABB.
      Parameters:
      box - bounding box to check
      Returns:
      true, if point is inside
    • isInAABB

      boolean isInAABB(Vec3D boxOrigin, Vec3D boxExtent)
      Checks if the point is inside the given axis-aligned bounding box.
      Parameters:
      boxOrigin - bounding box origin/center
      boxExtent - bounding box extends (half measure)
      Returns:
      true, if point is inside the box
    • isMajorAxis

      boolean isMajorAxis(float tolerance)
      Checks if the vector is parallel with either the X or Y axis (any direction).
      Parameters:
      tolerance -
      Returns:
      true, if parallel within the given tolerance
    • isZeroVector

      boolean isZeroVector()
      Checks if vector has a magnitude equals or close to zero (tolerance used is MathUtils.EPS).
      Returns:
      true, if zero vector
    • magnitude

      float magnitude()
      Calculates the magnitude/eucledian length of the vector.
      Returns:
      vector length
    • magSquared

      float magSquared()
      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).
      Returns:
      squared magnitude (x^2 + y^2 + z^2)
    • scale

      Vec3D scale(float s)
      Scales vector uniformly and returns result as new vector.
      Parameters:
      s - scale factor
      Returns:
      new vector
    • scale

      Vec3D scale(float a, float b, float c)
      Scales vector non-uniformly and returns result as new vector.
      Parameters:
      a - scale factor for X coordinate
      b - scale factor for Y coordinate
      c - scale factor for Z coordinate
      Returns:
      new vector
    • scale

      Vec3D scale(ReadonlyVec3D s)
      Scales vector non-uniformly by vector v and returns result as new vector.
      Parameters:
      s - scale vector
      Returns:
      new vector
    • sub

      Vec3D sub(float a, float b, float c)
      Subtracts vector {a,b,c} and returns result as new vector.
      Parameters:
      a - X coordinate
      b - Y coordinate
      c - Z coordinate
      Returns:
      result as new vector
    • sub

      Subtracts vector v and returns result as new vector.
      Parameters:
      v - vector to be subtracted
      Returns:
      result as new vector
    • to2DXY

      Vec2D to2DXY()
      Creates a new 2D vector of the XY components.
      Returns:
      new vector
    • to2DXZ

      Vec2D to2DXZ()
      Creates a new 2D vector of the XZ components.
      Returns:
      new vector
    • to2DYZ

      Vec2D to2DYZ()
      Creates a new 2D vector of the YZ components.
      Returns:
      new vector
    • to4D

      Vec4D to4D()
      Creates a Vec4D instance of this vector with the w component set to 1.0
      Returns:
      4d vector
    • to4D

      Vec4D to4D(float w)
      Creates a Vec4D instance of this vector with it w component set to the given value.
      Parameters:
      w -
      Returns:
      weighted 4d vector
    • toArray

      float[] toArray()
    • toArray4

      float[] toArray4(float w)
    • x

      float x()
    • y

      float y()
    • z

      float z()