Package toxi.geom

Class Vec2D

java.lang.Object
toxi.geom.Vec2D
All Implemented Interfaces:
Comparable<ReadonlyVec2D>, ReadonlyVec2D
Direct Known Subclasses:
Ellipse, Ray2D, VerletParticle2D

public class Vec2D extends Object implements Comparable<ReadonlyVec2D>, ReadonlyVec2D
Comprehensive 2D vector class with additional basic intersection and collision detection features.
  • Field Details

    • X_AXIS

      public static final ReadonlyVec2D X_AXIS
      Defines positive X axis
    • Y_AXIS

      public static final ReadonlyVec2D Y_AXIS
      Defines positive Y axis
    • ZERO

      public static final ReadonlyVec2D ZERO
      Defines the zero vector.
    • MIN_VALUE

      public static final ReadonlyVec2D MIN_VALUE
      Defines vector with both coords set to Float.MIN_VALUE. Useful for bounding box operations.
    • MAX_VALUE

      public static final ReadonlyVec2D MAX_VALUE
      Defines vector with both coords set to Float.MAX_VALUE. Useful for bounding box operations.
    • NEG_MAX_VALUE

      public static final ReadonlyVec2D NEG_MAX_VALUE
    • x

      public float x
      X coordinate
    • y

      public float y
      Y coordinate
  • Constructor Details

    • Vec2D

      public Vec2D()
      Creates a new zero vector
    • Vec2D

      public Vec2D(float x, float y)
      Creates a new vector with the given coordinates
      Parameters:
      x -
      y -
    • Vec2D

      public Vec2D(float[] v)
    • Vec2D

      public Vec2D(ReadonlyVec2D v)
      Creates a new vector with the coordinates of the given vector
      Parameters:
      v - vector to be copied
  • Method Details

    • fromTheta

      public static final Vec2D fromTheta(float theta)
      Creates a new vector from the given angle in the XY plane. The resulting vector for theta=0 is equal to the positive X axis.
      Parameters:
      theta -
      Returns:
      new vector pointing into the direction of the passed in angle
    • max

      public static final Vec2D max(ReadonlyVec2D a, ReadonlyVec2D b)
      Constructs a new vector consisting of the largest components of both vectors.
      Parameters:
      b - the b
      a - the a
      Returns:
      result as new vector
    • min

      public static final Vec2D min(ReadonlyVec2D a, ReadonlyVec2D b)
      Constructs a new vector consisting of the smallest components of both vectors.
      Parameters:
      b - comparing vector
      a - the a
      Returns:
      result as new vector
    • randomVector

      public static final Vec2D randomVector()
      Static factory method. Creates a new random unit vector using the Random implementation set as default for the MathUtils class.
      Returns:
      a new random normalized unit vector.
    • randomVector

      public static final Vec2D randomVector(Random rnd)
      Static factory method. Creates a new random unit vector using the given Random generator instance. I recommend to have a look at the https://uncommons-maths.dev.java.net library for a good choice of reliable and high quality random number generators.
      Returns:
      a new random normalized unit vector.
    • abs

      public final Vec2D abs()
    • add

      public final Vec2D add(float a, float b)
      Description copied from interface: ReadonlyVec2D
      Adds vector {a,b,c} and returns result as new vector.
      Specified by:
      add in interface ReadonlyVec2D
      Parameters:
      a - X coordinate
      b - Y coordinate
      Returns:
      result as new vector
    • add

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

      public final Vec2D add(Vec2D v)
    • addSelf

      public final Vec2D addSelf(float a, float b)
      Adds vector {a,b,c} and overrides coordinates with result.
      Parameters:
      a - X coordinate
      b - Y coordinate
      Returns:
      itself
    • addSelf

      public final Vec2D addSelf(Vec2D v)
      Adds vector v and overrides coordinates with result.
      Parameters:
      v - vector to add
      Returns:
      itself
    • angleBetween

      public final float angleBetween(ReadonlyVec2D v)
      Description copied from interface: ReadonlyVec2D
      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 ReadonlyVec2D.angleBetween(ReadonlyVec2D, boolean)
      Specified by:
      angleBetween in interface ReadonlyVec2D
      Parameters:
      v - vector
      Returns:
      angle in radians, or NaN if vectors are parallel
    • angleBetween

      public final float angleBetween(ReadonlyVec2D v, boolean forceNormalize)
      Description copied from interface: ReadonlyVec2D
      Computes the angle between this vector and vector V
      Specified by:
      angleBetween in interface ReadonlyVec2D
      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

      public Vec3D bisect(Vec2D b)
      Description copied from interface: ReadonlyVec2D
      Computes the perpendicular bisector of two points.
      Specified by:
      bisect in interface ReadonlyVec2D
      Parameters:
      b - other point
      Returns:
      bisector coefficients as Vec3D
    • clear

      public final Vec2D clear()
      Sets all vector components to 0.
      Returns:
      itself
    • compareTo

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

      public Vec2D constrain(Polygon2D poly)
      Constraints this vector to the perimeter of the given polygon. Unlike the constrain(Rect) version of this method, this version DOES NOT check containment automatically. If you want to only constrain a point if its (for example) outside the polygon, then check containment with Polygon2D.containsPoint(ReadonlyVec2D) first before calling this method.
      Parameters:
      poly -
      Returns:
      itself
    • constrain

      public Vec2D constrain(Rect r)
      Forcefully fits the vector in the given rectangle.
      Parameters:
      r -
      Returns:
      itself
    • constrain

      public Vec2D constrain(Vec2D min, Vec2D max)
      Forcefully fits the vector in the given rectangle defined by the points.
      Parameters:
      min -
      max -
      Returns:
      itself
    • copy

      public final Vec2D copy()
      Specified by:
      copy in interface ReadonlyVec2D
      Returns:
      a new independent instance/copy of a given vector
    • cross

      public float cross(ReadonlyVec2D v)
      Description copied from interface: ReadonlyVec2D
      Calculates the cross-product with the given vector.
      Specified by:
      cross in interface ReadonlyVec2D
      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

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

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

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

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

      public boolean equals(ReadonlyVec2D v)
      Returns true if all of the data members of ReadonlyVec2D 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(ReadonlyVec2D v, float tolerance)
      Description copied from interface: ReadonlyVec2D
      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 ReadonlyVec2D
      Parameters:
      v - the v
      tolerance - the tolerance
      Returns:
      true, if equal
    • floor

      public final Vec2D floor()
      Replaces the vector components with integer values of their current values
      Returns:
      itself
    • frac

      public final Vec2D frac()
      Replaces the vector components with the fractional part of their current values
      Returns:
      itself
    • getAbs

      public final Vec2D getAbs()
      Specified by:
      getAbs in interface ReadonlyVec2D
    • getCartesian

      public Vec2D getCartesian()
      Description copied from interface: ReadonlyVec2D
      Converts the vector from polar to Cartesian space. Assumes this order: x=radius, y=theta
      Specified by:
      getCartesian in interface ReadonlyVec2D
      Returns:
      new vector
    • getComponent

      public float getComponent(Vec2D.Axis id)
      Specified by:
      getComponent in interface ReadonlyVec2D
    • getComponent

      public final float getComponent(int id)
      Specified by:
      getComponent in interface ReadonlyVec2D
    • getConstrained

      public final Vec2D getConstrained(Polygon2D poly)
    • getConstrained

      public final Vec2D getConstrained(Rect r)
      Description copied from interface: ReadonlyVec2D
      Creates a copy of the vector which forcefully fits in the given rectangle.
      Specified by:
      getConstrained in interface ReadonlyVec2D
      Returns:
      fitted vector
    • getFloored

      public final Vec2D getFloored()
      Description copied from interface: ReadonlyVec2D
      Creates a new vector whose components are the integer value of their current values
      Specified by:
      getFloored in interface ReadonlyVec2D
      Returns:
      result as new vector
    • getFrac

      public final Vec2D getFrac()
      Description copied from interface: ReadonlyVec2D
      Creates a new vector whose components are the fractional part of their current values
      Specified by:
      getFrac in interface ReadonlyVec2D
      Returns:
      result as new vector
    • getInverted

      public final Vec2D getInverted()
      Description copied from interface: ReadonlyVec2D
      Scales vector uniformly by factor -1 ( v = -v )
      Specified by:
      getInverted in interface ReadonlyVec2D
      Returns:
      result as new vector
    • getLimited

      public final Vec2D getLimited(float lim)
      Description copied from interface: ReadonlyVec2D
      Creates a copy of the vector with its magnitude limited to the length given
      Specified by:
      getLimited in interface ReadonlyVec2D
      Parameters:
      lim - new maximum magnitude
      Returns:
      result as new vector
    • getMapped

      public Vec2D getMapped(ScaleMap map)
      Description copied from interface: ReadonlyVec2D
      Produces a new vector with its coordinates passed through the given ScaleMap.
      Specified by:
      getMapped in interface ReadonlyVec2D
      Returns:
      mapped vector
    • getNormalized

      public final Vec2D getNormalized()
      Description copied from interface: ReadonlyVec2D
      Produces the normalized version as a new vector
      Specified by:
      getNormalized in interface ReadonlyVec2D
      Returns:
      new vector
    • getNormalizedTo

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

      public final Vec2D getPerpendicular()
      Specified by:
      getPerpendicular in interface ReadonlyVec2D
    • getPolar

      public Vec2D getPolar()
      Description copied from interface: ReadonlyVec2D
      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.
      Specified by:
      getPolar in interface ReadonlyVec2D
      Returns:
      new vector
    • getReciprocal

      public final Vec2D getReciprocal()
      Specified by:
      getReciprocal in interface ReadonlyVec2D
    • getReflected

      public final Vec2D getReflected(ReadonlyVec2D normal)
      Specified by:
      getReflected in interface ReadonlyVec2D
    • getRotated

      public final Vec2D getRotated(float theta)
      Description copied from interface: ReadonlyVec2D
      Creates a new vector rotated by the given angle around the Z axis.
      Specified by:
      getRotated in interface ReadonlyVec2D
      Returns:
      rotated vector
    • getRoundedTo

      public Vec2D getRoundedTo(float prec)
      Description copied from interface: ReadonlyVec2D
      Creates a new vector with its coordinates rounded to the given precision (grid alignment).
      Specified by:
      getRoundedTo in interface ReadonlyVec2D
      Returns:
      grid aligned vector
    • getSignum

      public Vec2D getSignum()
      Description copied from interface: ReadonlyVec2D
      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
      Specified by:
      getSignum in interface ReadonlyVec2D
      Returns:
      result vector
    • hashCode

      public int hashCode()
      Returns a hash code value based on the data values in this object. Two different Vec2D objects with identical data values (i.e., Vec2D.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 hash code value of this vector.
    • heading

      public final float heading()
      Description copied from interface: ReadonlyVec2D
      Computes the vector's direction in the XY plane (for example for 2D points). The positive X axis equals 0 degrees.
      Specified by:
      heading in interface ReadonlyVec2D
      Returns:
      rotation angle
    • interpolateTo

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

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

      public final Vec2D interpolateTo(Vec2D v, float f)
    • interpolateTo

      public Vec2D interpolateTo(Vec2D v, float f, InterpolateStrategy s)
    • interpolateToSelf

      public final Vec2D interpolateToSelf(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:
      itself, result overrides current vector
    • interpolateToSelf

      public Vec2D interpolateToSelf(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:
      itself, result overrides current vector
    • invert

      public final Vec2D invert()
      Scales vector uniformly by factor -1 ( v = -v ), overrides coordinates with result
      Returns:
      itself
    • isInCircle

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

      public boolean isInRectangle(Rect r)
      Description copied from interface: ReadonlyVec2D
      Checks if the point is inside the given rectangle.
      Specified by:
      isInRectangle in interface ReadonlyVec2D
      Parameters:
      r - bounding rectangle
      Returns:
      true, if point is inside
    • isInTriangle

      public boolean isInTriangle(Vec2D a, Vec2D b, Vec2D c)
      Description copied from interface: ReadonlyVec2D
      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
      Specified by:
      isInTriangle in interface ReadonlyVec2D
      Returns:
      true, if point is in triangle.
    • isMajorAxis

      public final boolean isMajorAxis(float tol)
      Description copied from interface: ReadonlyVec2D
      Checks if the vector is parallel with either the X or Y axis (any direction).
      Specified by:
      isMajorAxis in interface ReadonlyVec2D
      Returns:
      true, if parallel within the given tolerance
    • isZeroVector

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

      public final Vec2D jitter(float j)
    • jitter

      public final Vec2D jitter(float jx, float jy)
      Adds random jitter to the vector in the range -j ... +j using the default Random generator of MathUtils.
      Parameters:
      jx - maximum x jitter
      jy - maximum y jitter
      Returns:
      itself
    • jitter

      public final Vec2D jitter(Random rnd, float j)
    • jitter

      public final Vec2D jitter(Random rnd, float jx, float jy)
    • jitter

      public final Vec2D jitter(Random rnd, Vec2D jv)
    • jitter

      public final Vec2D jitter(Vec2D jv)
    • limit

      public final Vec2D limit(float lim)
      Limits the vector's magnitude to the length given
      Parameters:
      lim - new maximum magnitude
      Returns:
      itself
    • magnitude

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

      public final float magSquared()
      Description copied from interface: ReadonlyVec2D
      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.
      Specified by:
      magSquared in interface ReadonlyVec2D
      Returns:
      squared magnitude (x^2 + y^2)
    • max

      public final Vec2D max(ReadonlyVec2D v)
      Description copied from interface: ReadonlyVec2D
      Constructs a new vector consisting of the largest components of both vectors.
      Specified by:
      max in interface ReadonlyVec2D
      Returns:
      result as new vector
    • maxSelf

      public final Vec2D maxSelf(ReadonlyVec2D v)
      Adjusts the vector components to the maximum values of both vectors
      Parameters:
      v -
      Returns:
      itself
    • min

      public final Vec2D min(ReadonlyVec2D v)
      Description copied from interface: ReadonlyVec2D
      Constructs a new vector consisting of the smallest components of both vectors.
      Specified by:
      min in interface ReadonlyVec2D
      Parameters:
      v - comparing vector
      Returns:
      result as new vector
    • minSelf

      public final Vec2D minSelf(ReadonlyVec2D v)
      Adjusts the vector components to the minimum values of both vectors
      Parameters:
      v -
      Returns:
      itself
    • normalize

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

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

      public final Vec2D perpendicular()
    • positiveHeading

      public final float positiveHeading()
    • reciprocal

      public final Vec2D reciprocal()
    • reflect

      public final Vec2D reflect(ReadonlyVec2D normal)
    • rotate

      public final Vec2D rotate(float theta)
      Rotates the vector by the given angle around the Z axis.
      Parameters:
      theta -
      Returns:
      itself
    • roundTo

      public Vec2D roundTo(float prec)
    • scale

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

      public final Vec2D scale(float a, float b)
      Description copied from interface: ReadonlyVec2D
      Scales vector non-uniformly and returns result as new vector.
      Specified by:
      scale in interface ReadonlyVec2D
      Parameters:
      a - scale factor for X coordinate
      b - scale factor for Y coordinate
      Returns:
      new vector
    • scale

      public final Vec2D scale(ReadonlyVec2D s)
      Specified by:
      scale in interface ReadonlyVec2D
    • scale

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

      public final Vec2D scaleSelf(float s)
      Scales vector uniformly and overrides coordinates with result
      Parameters:
      s - scale factor
      Returns:
      itself
    • scaleSelf

      public final Vec2D scaleSelf(float a, float b)
      Scales vector non-uniformly by vector {a,b,c} and overrides coordinates with result
      Parameters:
      a - scale factor for X coordinate
      b - scale factor for Y coordinate
      Returns:
      itself
    • scaleSelf

      public final Vec2D scaleSelf(Vec2D s)
      Scales vector non-uniformly by vector v and overrides coordinates with result
      Parameters:
      s - scale vector
      Returns:
      itself
    • set

      public final Vec2D set(float x, float y)
      Overrides coordinates with the given values
      Parameters:
      x -
      y -
      Returns:
      itself
    • set

      public final Vec2D set(ReadonlyVec2D v)
    • set

      public final Vec2D set(Vec2D v)
      Overrides coordinates with the ones of the given vector
      Parameters:
      v - vector to be copied
      Returns:
      itself
    • setComponent

      public final Vec2D setComponent(Vec2D.Axis id, float val)
    • setComponent

      public final Vec2D setComponent(int id, float val)
    • setX

      public Vec2D setX(float x)
    • setY

      public Vec2D setY(float y)
    • signum

      public final Vec2D signum()
      Replaces all vector components 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:
      itself
    • snapToAxis

      public final Vec2D snapToAxis()
      Rounds the vector to the closest major axis. Assumes the vector is normalized.
      Returns:
      itself
    • sub

      public final Vec2D sub(float a, float b)
      Description copied from interface: ReadonlyVec2D
      Subtracts vector {a,b,c} and returns result as new vector.
      Specified by:
      sub in interface ReadonlyVec2D
      Parameters:
      a - X coordinate
      b - Y coordinate
      Returns:
      result as new vector
    • sub

      public final Vec2D sub(ReadonlyVec2D v)
      Specified by:
      sub in interface ReadonlyVec2D
    • sub

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

      public final Vec2D subSelf(float a, float b)
      Subtracts vector {a,b,c} and overrides coordinates with result.
      Parameters:
      a - X coordinate
      b - Y coordinate
      Returns:
      itself
    • subSelf

      public final Vec2D subSelf(Vec2D v)
      Subtracts vector v and overrides coordinates with result.
      Parameters:
      v - vector to be subtracted
      Returns:
      itself
    • tangentNormalOfEllipse

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

      public final Vec3D to3DXY()
      Description copied from interface: ReadonlyVec2D
      Creates a 3D version of this vector in the XY plane.
      Specified by:
      to3DXY in interface ReadonlyVec2D
      Returns:
      3D vector
    • to3DXZ

      public final Vec3D to3DXZ()
      Description copied from interface: ReadonlyVec2D
      Creates a 3D version of this vector in the XZ plane. (The 2D Y coordinate interpreted as Z)
      Specified by:
      to3DXZ in interface ReadonlyVec2D
      Returns:
      3D vector
    • to3DYZ

      public final Vec3D to3DYZ()
      Description copied from interface: ReadonlyVec2D
      Creates a 3D version of this vector in the YZ plane. (The 2D X coordinate interpreted as Y & 2D Y as Z)
      Specified by:
      to3DYZ in interface ReadonlyVec2D
      Returns:
      3D vector
    • toArray

      public float[] toArray()
      Specified by:
      toArray in interface ReadonlyVec2D
    • toCartesian

      public final Vec2D toCartesian()
    • toPolar

      public final Vec2D toPolar()
    • toString

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

      public final float x()
      Specified by:
      x in interface ReadonlyVec2D
    • y

      public final float y()
      Specified by:
      y in interface ReadonlyVec2D