java.lang.Object
com.io7m.jtensors.core.unparameterized.vectors.Vectors2D

public final class Vectors2D
extends java.lang.Object

Functions over Vector2D values.

See "Mathematics for 3D Game Programming and Computer Graphics" 2nd Ed for the derivations of most of the code in this class (ISBN: 1-58450-277-0).

Since:
8.0.0
  • Method Details

    • absolute

      public static Vector2D absolute​(Vector2D v0)
      Calculate the absolute of v0.
      Returns:
      (abs v0.x, abs v0.y) * @param v0 The vector
    • add

      public static Vector2D add​(Vector2D v0, Vector2D v1)
      Add v0 to v1.
      Parameters:
      v1 - The right vector
      Returns:
      (v0.x + v1.x, v0.y + v1.y) * @param v0 The left vector
    • multiply

      public static Vector2D multiply​(Vector2D v0, Vector2D v1)
      Multiply v0 by v1.
      Parameters:
      v1 - The right vector
      Returns:
      (v0.x * v1.x, v0.y * v1.y) * @param v0 The left vector
      Since:
      10.0.0
    • addScaled

      public static Vector2D addScaled​(Vector2D v0, Vector2D v1, double r)
      Add v0 to v1 * r.
      Parameters:
      v1 - The right vector
      r - The scaling value
      Returns:
      (v0.x + (v1.x * r), v0.y + (v1.y * r)) * @param v0 The left vector
    • angle

      public static double angle​(Vector2D v0, Vector2D v1)
      Calculate the angle between the vectors v0 and v1 in radians.
      Parameters:
      v0 - The left input vector
      v1 - The right input vector * @return The angle between the two vectors, in radians.
    • clamp

      public static Vector2D clamp​(Vector2D v, Vector2D v_min, Vector2D v_max)
      Clamp the values in v by v_min and v_max.
      Parameters:
      v_min - The minimum vector
      v_max - The maximum vector
      Returns:
      (max(min(v.x, v_max.x()), v_min.x()), max(min(v.y, v_max.y()), v_min.y())) * @param v The source vector
    • distance

      public static double distance​(Vector2D v0, Vector2D v1)
      Calculate the distance between v0 and v1.
      Parameters:
      v1 - The right vector
      Returns:
      The distance between v0 and v1. * @param v0 The left vector
    • dotProduct

      public static double dotProduct​(Vector2D v0, Vector2D v1)
      Calculate the scalar product of the vectors v0 and v1. * @param v0 The left vector
      Parameters:
      v1 - The right vector
      Returns:
      The scalar product of the two vectors
    • interpolateLinear

      public static Vector2D interpolateLinear​(Vector2D v0, Vector2D v1, double alpha)

      Linearly interpolate between v0 and v1 by the amount alpha.

      The alpha parameter controls the degree of interpolation, such that:

      • interpolateLinear(v0, v1, 0.0) = v0
      • interpolateLinear(v0, v1, 1.0) = v1
      Parameters:
      v0 - The left input vector
      v1 - The right input vector
      alpha - The interpolation value in the range [0, 1] * @return ((1 - alpha) * v0) + (alpha * v1)
    • interpolateBilinear

      public static Vector2D interpolateBilinear​(Vector2D x0y0, Vector2D x1y0, Vector2D x0y1, Vector2D x1y1, double px, double py)

      Bilinearly interpolate between x0y0, x1y0, x0y1, x1y1.

      The px and py parameters control the degree of interpolation, such that:

      • interpolateBilinear(x0y0, x1y0, x0y1, x1y1, 0.0, 0.0) = x0y0
      • interpolateBilinear(x0y0, x1y0, x0y1, x1y1, 1.0, 0.0) = x1y0
      • interpolateBilinear(x0y0, x1y0, x0y1, x1y1, 0.0, 1.0) = x0y1
      • interpolateBilinear(x0y0, x1y0, x0y1, x1y1, 1.0, 1.0) = x1y1
      Parameters:
      x0y0 - The top left input vector
      x1y0 - The top right input vector
      x0y1 - The bottom left input vector
      x1y1 - The bottom right input vector
      px - The X interpolation value in the range [0, 1]
      py - The Y interpolation value in the range [0, 1] * @return The bilinearly interpolated value
    • magnitudeSquared

      public static double magnitudeSquared​(Vector2D v0)
      Calculate the squared magnitude of the vector v0. * @param v0 The vector
      Returns:
      The squared magnitude of the vector
    • magnitude

      public static double magnitude​(Vector2D v0)
      Calculate the magnitude of the vector v0. * @param v0 The vector
      Returns:
      The magnitude of the vector
    • negate

      public static Vector2D negate​(Vector2D v)
      Calculate the negation of v.
      Returns:
      (-v.x, -v.y) * @param v The vector
    • normalize

      public static Vector2D normalize​(Vector2D v0)

      Normalize the vector v0.

      If the magnitude of the vector is zero, the function returns v0.

      * @param v0 The vector
      Returns:
      A normalized copy of v0
    • scale

      public static Vector2D scale​(Vector2D v0, double r)
      Scale v0 by r.
      Parameters:
      r - The scaling value
      Returns:
      (v0.x * r, v0.y * r) * @param v0 The left vector
    • subtract

      public static Vector2D subtract​(Vector2D v0, Vector2D v1)
      Subtract v1 from v0.
      Parameters:
      v1 - The right vector
      Returns:
      (v0.x - v1.x, v0.y - v1.y) * @param v0 The left vector
    • zero

      public static Vector2D zero()
      The zero vector.
      Returns:
      (0, 0)