Module dxf

Class ArrayVector

java.lang.Object
org.jagatoo.util.arrays.ArrayVector

public final class ArrayVector extends Object
Utility class, that provides vector-arithmetic methods to be applied to float arrays.
Author:
Marvin Froehlich (aka Qudus)
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static final void
    absolute(float[] v1)
    Sets each compnent of the given vector v1 to its absolute.
    static final void
    add(float[] a, float[] b, float[] o)
    Adds the array a componentwise to the array b and puts the result into o.
    static final float
    angle(float[] v1, float[] v2)
    Returns the angle in radians between vector v1 and v2;
    The return value is constrained to the range [0, PI].
    static final void
    clamp(float min, float max, float[] v)
    Clamps the trg vector to the range [min, max].
    static final void
    clamp(float min, float max, float[] src, float[] trg)
    Clamps the src vector parameter to the range [min, max] and places the values into the trg vector.
    static final void
    clampMax(float max, float[] v)
    Clamps the maximum value of the given vector to the max parameter.
    static final void
    clampMax(float max, float[] src, float[] trg)
    Clamps the maximum value of the tuple parameter to the max parameter and places the values into the trg vector.
    static final void
    clampMin(float min, float[] v)
    Clamps the minimum value of the given vector to the min parameter.
    static final void
    clampMin(float min, float[] src, float[] trg)
    Clamps the minimum value of the tuple parameter to the min parameter and places the values into the trg vector.
    static final float[]
    clone(float[] v)
    Creates a new instance of this float array and copies all values.
    static final void
    cross(float[] v1, float[] v2, float[] o)
    Sets vector o to be the vector cross product of vectors v1 and v2.
    static final float
    distance(float[] p1, float[] p2)
    Returns the distance between points p1 and p2.
    static final float
    distanceSquared(float[] p1, float[] p2)
    Computes the square of the distance between points p1 and p2.
    static final float
    dot(float[] v1, float[] v2)
    Computes the dot product of the vectors v1 and v2.
    static final void
    interpolate(float[] v1, float[] v2, float alpha)
    Linearly interpolates between vector v1 and t2 and places the result into v1: v1 = (1 - alpha) * v1 + alpha * v2.
    static final void
    interpolate(float[] v1, float[] v2, float alpha, float[] o)
    Linearly interpolates between vectors v1 and v2 and places the result into vector o: o = (1 - alpha) * v1 + alpha * v2.
    static final float
    length(float[] vector)
    Returns the length of the given vector.
    static final float
    lengthSquared(float[] vector)
    Returns the squared length of the given vector.
    static final void
    negate(float[] v1)
    Negates the given vector v1.
    static final void
    normalize(float[] v1)
    Normalizes the given vector v1.
    static void
    round(float[] v, int decPlaces)
    Rounds the vector to the given number of decimal places.
    static final void
    scale(float factor, float[] vector)
    Sets the value of the given vector to the scalar multiplication of vector v1.
    static final void
    set(float[] src, float[] trg)
    Sets the elements of dst to src.
    static final void
    sub(float[] a, float[] b, float[] o)
    Subtracts the array b componentwise from the array a and puts the result into o.
    static final String
    toString(float[] vector)
    Creates a String representation of the given vector.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ArrayVector

      public ArrayVector()
  • Method Details

    • sub

      public static final void sub(float[] a, float[] b, float[] o)
      Subtracts the array b componentwise from the array a and puts the result into o.
      Parameters:
      a -
      b -
      o -
    • add

      public static final void add(float[] a, float[] b, float[] o)
      Adds the array a componentwise to the array b and puts the result into o.
      Parameters:
      a -
      b -
      o -
    • lengthSquared

      public static final float lengthSquared(float[] vector)
      Returns the squared length of the given vector.
      Returns:
      the squared length of the given vector
    • length

      public static final float length(float[] vector)
      Returns the length of the given vector.
      Returns:
      the length of the given vector
    • distanceSquared

      public static final float distanceSquared(float[] p1, float[] p2)
      Computes the square of the distance between points p1 and p2.
      Parameters:
      p1 - the first point
      p2 - the other point
      Returns:
      the square of distance between these two points as a float
    • distance

      public static final float distance(float[] p1, float[] p2)
      Returns the distance between points p1 and p2.
      Parameters:
      p1 - the first point
      p2 - the other point
      Returns:
      the distance between these two points
    • cross

      public static final void cross(float[] v1, float[] v2, float[] o)
      Sets vector o to be the vector cross product of vectors v1 and v2.
      Parameters:
      v1 - the first vector
      v2 - the second vector
      o - the output vector
    • dot

      public static final float dot(float[] v1, float[] v2)
      Computes the dot product of the vectors v1 and v2.
      Parameters:
      v1 - the first vector
      v2 - the other vector
    • set

      public static final void set(float[] src, float[] trg)
      Sets the elements of dst to src.
      Parameters:
      src - the source vector
      trg - the target vector
    • clone

      public static final float[] clone(float[] v)
      Creates a new instance of this float array and copies all values.
      Parameters:
      v - the source float array
      Returns:
      the new equal instance
    • normalize

      public static final void normalize(float[] v1)
      Normalizes the given vector v1.
      Parameters:
      v1 - the input vector
    • scale

      public static final void scale(float factor, float[] vector)
      Sets the value of the given vector to the scalar multiplication of vector v1.
      Parameters:
      factor - the scalar value
      vector - the vector to be scaled
    • negate

      public static final void negate(float[] v1)
      Negates the given vector v1.
      Parameters:
      v1 - the input vector
    • absolute

      public static final void absolute(float[] v1)
      Sets each compnent of the given vector v1 to its absolute.
      Parameters:
      v1 - the input vector
    • angle

      public static final float angle(float[] v1, float[] v2)
      Returns the angle in radians between vector v1 and v2;
      The return value is constrained to the range [0, PI].
      Parameters:
      v1 - the first vector
      v2 - the seconds vector
      Returns:
      the angle in radians in the range [0, PI]
    • clampMin

      public static final void clampMin(float min, float[] v)
      Clamps the minimum value of the given vector to the min parameter.
      Parameters:
      min - the lowest value in the vector after clamping
      v - teh vector to clamp (modify)
    • clampMin

      public static final void clampMin(float min, float[] src, float[] trg)
      Clamps the minimum value of the tuple parameter to the min parameter and places the values into the trg vector.
      Parameters:
      min - the lowest value in the tuple after clamping
    • clampMax

      public static final void clampMax(float max, float[] v)
      Clamps the maximum value of the given vector to the max parameter.
      Parameters:
      max - the largest value in the vector after clamping
      v - the vector to clamp (modify)
    • clampMax

      public static final void clampMax(float max, float[] src, float[] trg)
      Clamps the maximum value of the tuple parameter to the max parameter and places the values into the trg vector.
      Parameters:
      min - the lowest value in the tuple after clamping
    • clamp

      public static final void clamp(float min, float max, float[] v)
      Clamps the trg vector to the range [min, max].
      Parameters:
      min - the lowest value in the vector after clamping
      max - the highest value in the vector after clamping
    • clamp

      public static final void clamp(float min, float max, float[] src, float[] trg)
      Clamps the src vector parameter to the range [min, max] and places the values into the trg vector.
      Parameters:
      min - the lowest value in the vector after clamping
      max - the highest value in the vector after clamping
      src - the source vector, which will not be modified
      trg - the target vector, which will be modified
    • round

      public static void round(float[] v, int decPlaces)
      Rounds the vector to the given number of decimal places.
      Parameters:
      v -
      decPlaces -
    • interpolate

      public static final void interpolate(float[] v1, float[] v2, float alpha)
      Linearly interpolates between vector v1 and t2 and places the result into v1: v1 = (1 - alpha) * v1 + alpha * v2.
      Parameters:
      v1 - the first vector
      v2 - the second vector
      alpha - the alpha interpolation parameter
    • interpolate

      public static final void interpolate(float[] v1, float[] v2, float alpha, float[] o)
      Linearly interpolates between vectors v1 and v2 and places the result into vector o: o = (1 - alpha) * v1 + alpha * v2.
      Parameters:
      v1 - the first vector
      v2 - the second vector
      alpha - the alpha interpolation parameter
    • toString

      public static final String toString(float[] vector)
      Creates a String representation of the given vector.
      Parameters:
      vector -
      Returns:
      the String