Package toxi.geom

Interface ReadonlyVec2D

All Known Implementing Classes:
Circle, Ellipse, Ray2D, Vec2D, VerletParticle2D

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

    • add

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

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

      float angleBetween(ReadonlyVec2D 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(ReadonlyVec2D, boolean)
      Parameters:
      v - vector
      Returns:
      angle in radians, or NaN if vectors are parallel
    • angleBetween

      float angleBetween(ReadonlyVec2D 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
    • bisect

      Vec3D bisect(Vec2D p)
      Computes the perpendicular bisector of two points.
      Parameters:
      p - other point
      Returns:
      bisector coefficients as Vec3D
    • compareTo

      int compareTo(ReadonlyVec2D 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

      Vec2D copy()
      Returns:
      a new independent instance/copy of a given vector
    • cross

      float cross(ReadonlyVec2D v)
      Calculates the cross-product with the given vector.
      Parameters:
      v - vector
      Returns:
      the magnitude of the vector that would result from a regular 3D cross product of the input vectors, taking their Z values implicitly as 0 (i.e. treating the 2D space as a plane in the 3D space). The 3D cross product will be perpendicular to that plane, and thus have 0 X & Y components (thus the scalar returned is the Z value of the 3D cross product vector).
      See Also:
    • distanceTo

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

      float distanceToSquared(ReadonlyVec2D 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(ReadonlyVec2D v)
      Computes the scalar product (dot product) with the given vector.
      Parameters:
      v -
      Returns:
      dot product
      See Also:
    • equals

      Overrides:
      equals in class Object
    • equalsWithTolerance

      boolean equalsWithTolerance(ReadonlyVec2D 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

      Vec2D getAbs()
    • getCartesian

      Vec2D getCartesian()
      Converts the vector from polar to Cartesian space. Assumes this order: x=radius, y=theta
      Returns:
      new vector
    • getComponent

      float getComponent(Vec2D.Axis id)
    • getComponent

      float getComponent(int id)
    • getConstrained

      Vec2D getConstrained(Rect r)
      Creates a copy of the vector which forcefully fits in the given rectangle.
      Parameters:
      r -
      Returns:
      fitted vector
    • getFloored

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

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

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

      Vec2D 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

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

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

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

      Vec2D getPerpendicular()
    • getPolar

      Vec2D getPolar()
      Converts the current vector into polar coordinates. After the conversion the x component of the vector contains the radius (magnitude) and y the rotation angle.
      Returns:
      new vector
    • getReciprocal

      Vec2D getReciprocal()
    • getReflected

      Vec2D getReflected(ReadonlyVec2D normal)
    • getRotated

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

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

      Vec2D 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
    • heading

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

      Vec2D interpolateTo(ReadonlyVec2D 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

      Vec2D interpolateTo(ReadonlyVec2D 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
    • isInCircle

      boolean isInCircle(ReadonlyVec2D sO, float sR)
      Checks if the point is inside the given sphere.
      Parameters:
      sO - circle origin/centre
      sR - circle radius
      Returns:
      true, if point is in sphere
    • isInRectangle

      boolean isInRectangle(Rect r)
      Checks if the point is inside the given rectangle.
      Parameters:
      r - bounding rectangle
      Returns:
      true, if point is inside
    • isInTriangle

      boolean isInTriangle(Vec2D a, Vec2D b, Vec2D c)
      Checks if point vector is inside the triangle created by the points a, b and c. These points will create a plane and the point checked will have to be on this plane in the region between a,b,c. Note: The triangle must be defined in clockwise order a,b,c
      Returns:
      true, if point is in triangle.
    • 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). Please note the vector should contain cartesian (not polar) coordinates in order for this function to work. The magnitude of polar vectors is stored in the x component.
      Returns:
      squared magnitude (x^2 + y^2)
    • max

      Constructs a new vector consisting of the largest components of both vectors.
      Parameters:
      v -
      Returns:
      result as new vector
    • min

      Constructs a new vector consisting of the smallest components of both vectors.
      Parameters:
      v - comparing vector
      Returns:
      result as new vector
    • scale

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

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

      Vec2D scale(ReadonlyVec2D s)
    • scale

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

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

    • sub

      Vec2D sub(Vec2D v)
      Subtracts vector v and returns result as new vector.
      Parameters:
      v - vector to be subtracted
      Returns:
      result as new vector
    • tangentNormalOfEllipse

      Vec2D tangentNormalOfEllipse(Vec2D eO, Vec2D eR)
      Calculates the normal vector on the given ellipse in the direction of the current point.
      Parameters:
      eO - ellipse origin/centre
      eR - ellipse radii
      Returns:
      a unit normal vector to the tangent plane of the ellipsoid in the point.
    • to3DXY

      Vec3D to3DXY()
      Creates a 3D version of this vector in the XY plane.
      Returns:
      3D vector
    • to3DXZ

      Vec3D to3DXZ()
      Creates a 3D version of this vector in the XZ plane. (The 2D Y coordinate interpreted as Z)
      Returns:
      3D vector
    • to3DYZ

      Vec3D to3DYZ()
      Creates a 3D version of this vector in the YZ plane. (The 2D X coordinate interpreted as Y & 2D Y as Z)
      Returns:
      3D vector
    • toArray

      float[] toArray()
    • x

      float x()
    • y

      float y()