Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## toxi.geom
Class Vec2D

    java.lang.Object
      toxi.geom.Vec2D

All Implemented Interfaces:
  java.lang.Comparable<ReadonlyVec2D>, ReadonlyVec2D

Direct Known Subclasses:
  Ellipse, Ray2D

    public class Vec2D

extends java.lang.Object
implements java.lang.Comparable<ReadonlyVec2D>, ReadonlyVec2D

Comprehensive 2D vector class with additional basic intersection and collision detection features.

Nested Class Summary
`static class` | `Vec2D.Axis`

Field Summary
`static ReadonlyVec2D` | `MAX_VALUE` Defines vector with both coords set to Float.MAX_VALUE.
`static ReadonlyVec2D` | `MIN_VALUE` Defines vector with both coords set to Float.MIN_VALUE.
`float` | `x` X coordinate
`static ReadonlyVec2D` | `X_AXIS` Defines positive X axis
`float` | `y` Y coordinate
`static ReadonlyVec2D` | `Y_AXIS` Defines positive Y axis
`static ReadonlyVec2D` | `ZERO` Defines the zero vector.

Constructor Summary
`Vec2D()` Creates a new zero vector
`Vec2D(float x, float y)` Creates a new vector with the given coordinates
`Vec2D(ReadonlyVec2D v)` Creates a new vector with the coordinates of the given vector

Method Summary
`Vec2D` | `abs()`
`Vec2D` | `add(float a, float b)` Adds vector {a,b,c} and returns result as new vector.
`Vec2D` | `add(ReadonlyVec2D v)` Add vector v and returns result as new vector.
`Vec2D` | `add(Vec2D v)`
`Vec2D` | `addSelf(float a, float b)` Adds vector {a,b,c} and overrides coordinates with result.
`Vec2D` | `addSelf(Vec2D v)` Adds vector v and overrides coordinates with result.
`float` | `angleBetween(ReadonlyVec2D v)` Computes the angle between this vector and vector V.
`float` | `angleBetween(ReadonlyVec2D v, boolean forceNormalize)` Computes the angle between this vector and vector V
`Vec3D` | `bisect(Vec2D b)` Computes the perpendicular bisector of two points.
`Vec2D` | `clear()` Sets all vector components to 0.
`int` | `compareTo(ReadonlyVec2D v)` Compares the length of the vector with another one.
`Vec2D` | `constrain(Rect r)` Forcefully fits the vector in the given rectangle.
`Vec2D` | `constrain(Vec2D min, Vec2D max)` Forcefully fits the vector in the given rectangle defined by the points.
`Vec2D` | `copy()`
`float` | `cross(ReadonlyVec2D v)` Calculates the cross-product with the given vector.
`float` | `distanceTo(ReadonlyVec2D v)` Calculates distance to another vector
`float` | `distanceToSquared(ReadonlyVec2D v)` Calculates the squared distance to another vector
`float` | `dot(ReadonlyVec2D v)` Computes the scalar product (dot product) with the given vector.
`boolean` | `equals(java.lang.Object obj)`
`boolean` | `equalsWithTolerance(ReadonlyVec2D v, float tolerance)` Compares this vector with the one given.
`Vec2D` | `floor()` Replaces the vector components with integer values of their current values
`Vec2D` | `frac()` Replaces the vector components with the fractional part of their current values
`static Vec2D` | `fromTheta(float theta)` Creates a new vector from the given angle in the XY plane.
`Vec2D` | `getAbs()`
`float` | `getComponent(int id)`
`float` | `getComponent(Vec2D.Axis id)`
`Vec2D` | `getConstrained(Rect r)` Creates a copy of the vector which forcefully fits in the given rectangle.
`Vec2D` | `getFloored()` Creates a new vector whose components are the integer value of their current values
`Vec2D` | `getFrac()` Creates a new vector whose components are the fractional part of their current values
`Vec2D` | `getInverted()` Scales vector uniformly by factor -1 ( v = -v )
`Vec2D` | `getLimited(float lim)` Creates a copy of the vector with its magnitude limited to the length given
`Vec2D` | `getNormalized()` Produces the normalized version as a new vector
`Vec2D` | `getNormalizedTo(float len)` Produces a new vector normalized to the given length.
`Vec2D` | `getPerpendicular()`
`Vec2D` | `getReciprocal()`
`Vec2D` | `getReflected(ReadonlyVec2D normal)`
`Vec2D` | `getRotated(float theta)` Creates a new vector rotated by the given angle around the Z axis.
`Vec2D` | `getSignum()` Creates a new vector in which all components are replaced with the signum of their original values.
`int` | `hashCode()` Returns a unique code for this vector object based on it's values.
`float` | `heading()` Computes the vector's direction in the XY plane (for example for 2D points).
`Vec2D` | `interpolateTo(ReadonlyVec2D v, float f)` Interpolates the vector towards the given target vector, using linear interpolation
`Vec2D` | `interpolateTo(ReadonlyVec2D v, float f, InterpolateStrategy s)` Interpolates the vector towards the given target vector, using the given `InterpolateStrategy`
`Vec2D` | `interpolateTo(Vec2D v, float f)`
`Vec2D` | `interpolateTo(Vec2D v, float f, InterpolateStrategy s)`
`Vec2D` | `interpolateToSelf(ReadonlyVec2D v, float f)` Interpolates the vector towards the given target vector, using linear interpolation
`Vec2D` | `interpolateToSelf(ReadonlyVec2D v, float f, InterpolateStrategy s)` Interpolates the vector towards the given target vector, using the given `InterpolateStrategy`
`Vec2D` | `invert()` Scales vector uniformly by factor -1 ( v = -v ), overrides coordinates with result
`boolean` | `isInCircle(ReadonlyVec2D sO, float sR)` Checks if the point is inside the given sphere.
`boolean` | `isInRectangle(Rect r)` Checks if the point is inside the given rectangle.
`boolean` | `isInTriangle(Vec2D a, Vec2D b, Vec2D c)` Checks if point vector is inside the triangle created by the points a, b and c.
`boolean` | `isMajorAxis(float tol)` Checks if the vector is parallel with either the X or Y axis (any direction).
`boolean` | `isZeroVector()` Checks if vector has a magnitude equals or close to zero (tolerance used is `MathUtils.EPS`).
`Vec2D` | `jitter(float j)`
`Vec2D` | `jitter(float jx, float jy)` Adds random jitter to the vector in the range -j ...
`Vec2D` | `jitter(java.util.Random rnd, float j)`
`Vec2D` | `jitter(java.util.Random rnd, float jx, float jy)`
`Vec2D` | `jitter(java.util.Random rnd, Vec2D jv)`
`Vec2D` | `jitter(Vec2D jv)`
`Vec2D` | `limit(float lim)` Limits the vector's magnitude to the length given
`float` | `magnitude()` Calculates the magnitude/eucledian length of the vector
`float` | `magSquared()` Calculates only the squared magnitude/length of the vector.
`Vec2D` | `max(Vec2D v)` Constructs a new vector consisting of the largest components of both vectors.
`static Vec2D` | `max(Vec2D a, Vec2D b)` Constructs a new vector consisting of the largest components of both vectors.
`Vec2D` | `maxSelf(Vec2D v)` Adjusts the vector components to the maximum values of both vectors
`Vec2D` | `min(Vec2D v)` Constructs a new vector consisting of the smallest components of both vectors.
`static Vec2D` | `min(Vec2D a, Vec2D b)` Constructs a new vector consisting of the smallest components of both vectors.
`Vec2D` | `minSelf(Vec2D v)` Adjusts the vector components to the minimum values of both vectors
`Vec2D` | `normalize()` Normalizes the vector so that its magnitude = 1
`Vec2D` | `normalizeTo(float len)` Normalizes the vector to the given length.
`Vec2D` | `perpendicular()`
`static Vec2D` | `randomVector()` Static factory method.
`static Vec2D` | `randomVector(java.util.Random rnd)` Static factory method.
`Vec2D` | `reciprocal()`
`Vec2D` | `reflect(ReadonlyVec2D normal)`
`Vec2D` | `rotate(float theta)` Rotates the vector by the given angle around the Z axis.
`Vec2D` | `roundToAxis()` Rounds the vector to the closest major axis.
`Vec2D` | `scale(float s)` Scales vector uniformly and returns result as new vector.
`Vec2D` | `scale(float a, float b)` Scales vector non-uniformly and returns result as new vector.
`Vec2D` | `scale(ReadonlyVec2D s)`
`Vec2D` | `scale(Vec2D s)` Scales vector non-uniformly by vector v and returns result as new vector
`Vec2D` | `scaleSelf(float s)` Scales vector uniformly and overrides coordinates with result
`Vec2D` | `scaleSelf(float a, float b)` Scales vector non-uniformly by vector {a,b,c} and overrides coordinates with result
`Vec2D` | `scaleSelf(Vec2D s)` Scales vector non-uniformly by vector v and overrides coordinates with result
`Vec2D` | `set(float x, float y)` Overrides coordinates with the given values
`Vec2D` | `set(ReadonlyVec2D v)`
`Vec2D` | `set(Vec2D v)` Overrides coordinates with the ones of the given vector
`Vec2D` | `setComponent(int id, float val)`
`Vec2D` | `setComponent(Vec2D.Axis id, float val)`
`Vec2D` | `signum()` Replaces all vector components with the signum of their original values.
`Vec2D` | `sub(float a, float b)` Subtracts vector {a,b,c} and returns result as new vector.
`Vec2D` | `sub(ReadonlyVec2D v)`
`Vec2D` | `sub(Vec2D v)` Subtracts vector v and returns result as new vector.
`Vec2D` | `subSelf(float a, float b)` Subtracts vector {a,b,c} and overrides coordinates with result.
`Vec2D` | `subSelf(Vec2D v)` Subtracts vector v and overrides coordinates with result.
`Vec2D` | `tangentNormalOfEllipse(Vec2D eO, Vec2D eR)` Calculates the normal vector on the given ellipse in the direction of the current point.
`Vec3D` | `to3DXY()` Creates a 3D version of this vector in the XY plane.
`Vec3D` | `to3DXZ()` Creates a 3D version of this vector in the XZ plane.
`Vec3D` | `to3DYZ()` Creates a 3D version of this vector in the YZ plane.
`float[]` | `toArray()`
`Vec2D` | `toCartesian()` Converts the vector from polar to Cartesian space.
`Vec2D` | `toPolar()` Converts the current vector into polar coordinates.
`java.lang.String` | `toString()`
`float` | `x()`
`float` | `y()`

Methods inherited from class java.lang.Object
`getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### 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.

### x

    public float x

  X coordinate

### y

    public float y

  Y coordinate

Constructor Detail

### 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(ReadonlyVec2D v)

  Creates a new vector with the coordinates of the given vector

  Parameters:
    `v` - vector to be copied

Method Detail

### 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(Vec2D a,
                                  Vec2D 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(Vec2D a,
                                  Vec2D 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(java.util.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 `java.lang.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 final Vec2D constrain(Rect r)

  Forcefully fits the vector in the given rectangle.

  Parameters:
    `r` -
  Returns:
    itself

### constrain

    public final 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:
    Stackoverflow entry

### 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:
    `ReadonlyVec2D.magSquared()`

### 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:
    Wikipedia entry< /a>

### equals

    public boolean equals(java.lang.Object obj)

  Specified by:
    `equals` in interface `ReadonlyVec2D`
  Overrides:
    `equals` in class `java.lang.Object`

### 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`

### 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(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

### 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`

### 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

### 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 unique code for this vector object based on it's values. If two vectors are logically equivalent, they will return the same hash code value.

  Overrides:
    `hashCode` in class `java.lang.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(java.util.Random rnd,
                              float j)

### jitter

    public final Vec2D jitter(java.util.Random rnd,
                              float jx,
                              float jy)

### jitter

    public final Vec2D jitter(java.util.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(Vec2D 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(Vec2D v)

  Adjusts the vector components to the maximum values of both vectors

  Parameters:
    `v` -
  Returns:
    itself

### min

    public final Vec2D min(Vec2D 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(Vec2D 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()

### 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

### roundToAxis

    public final Vec2D roundToAxis()

  Rounds the vector to the closest major axis. Assumes the vector is normalized.

  Returns:
    itself

### 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)

### 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

### 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()

  Description copied from interface: `ReadonlyVec2D`
  Converts the vector from polar to Cartesian space. Assumes this order: x=radius, y=theta

  Specified by:
    `toCartesian` in interface `ReadonlyVec2D`
  Returns:
    itself as Cartesian vector

### toPolar

    public final Vec2D toPolar()

  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:
    `toPolar` in interface `ReadonlyVec2D`
  Returns:
    itself as polar vector

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

### x

    public final float x()

  Specified by:
    `x` in interface `ReadonlyVec2D`

### y

    public final float y()

  Specified by:
    `y` in interface `ReadonlyVec2D`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD