Class DoubleMath

java.lang.Object
ffx.numerics.math.DoubleMath

public final class DoubleMath extends Object
The DoubleMath class is a simple math library that operates on 3-coordinate double arrays.

All methods are static and thread-safe.

Use instances of Double3 for convenience.

Since:
1.0
Author:
Michael J. Schnieders
  • Method Summary

    Modifier and Type
    Method
    Description
    static double[]
    add(double[] a, double[] b)
    sum
    static double[]
    add(double[] a, double[] b, double[] ret)
    sum
    static double
    angle(double[] i, double[] j)
    angle
    static double
    bondAngle(double[] i, double[] j, double[] k)
    Finds the angle formed by three atoms.
    static double
    dihedralAngle(double[] ab, double[] bc, double[] cd)
    Finds the dihedral angle formed between 4 atoms, a, b, c, d, via position vectors AB, BC, and CD.
    static double
    dihedralAngle(double[] a, double[] b, double[] c, double[] d)
    Finds the dihedral angle formed between 4 atoms.
    static double
    dist(double[] a, double[] b)
    Finds the distance between two vectors.
    static double
    dist2(double[] a, double[] b)
    Finds the squared distance between two vectors
    static double
    dot(double[] a, double[] b)
    Finds the dot product between two vectors.
    static double[]
    fma(double[] a, double b, double[] c)
    Compute a * b + c and return the result in a new array.
    static double[]
    fma(double[] a, double b, double[] c, double[] ret)
    Compute a * b + c.
    static double
    length(double[] d)
    Finds the length of a vector.
    static double
    length2(double[] d)
    Finds the length^2 of a vector.
    static void
    log(double[] v)
    logVector
    static void
    log(double[] v, String label)
    logVector.
    static double[]
    normalize(double[] n)
    Normalizes a vector.
    static double[]
    normalize(double[] n, double[] ret)
    Normalizes a vector.
    static double[]
    scale(double[] n, double a)
    Scales a vector.
    static double[]
    scale(double[] n, double a, double[] ret)
    Scales a vector.
    static double[]
    square(double[] n)
    Squares values of a vector.
    static double[]
    square(double[] n, double[] ret)
    Squares values of a vector.
    static double[]
    squareRoot(double[] n)
    Square root values of a vector.
    static double[]
    squareRoot(double[] n, double[] ret)
    Square root values of a vector.
    static double[]
    sub(double[] a, double[] b)
    Finds the difference between two vectors.
    static double[]
    sub(double[] a, double[] b, double[] ret)
    Finds the difference between two vectors.
    static String
    toString(double[] v)
    logVector.
    static String
    toString(double[] v, String label)
    vectorToString.
    static double[]
    X(double[] a, double[] b)
    Finds the cross-product between two vectors
    static double[]
    X(double[] a, double[] b, double[] ret)
    Finds the cross-product between two vectors

    Methods inherited from class java.lang.Object

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

    • fma

      public static double[] fma(double[] a, double b, double[] c)
      Compute a * b + c and return the result in a new array.
      Parameters:
      a - First vector.
      b - Scalar.
      c - Second vector.
      Returns:
      Returns a * b + c.
    • fma

      public static double[] fma(double[] a, double b, double[] c, double[] ret)
      Compute a * b + c.
      Parameters:
      a - First vector.
      b - Scalar.
      c - Second vector.
      ret - Result vector.
      Returns:
      Returns a * b + c.
    • X

      public static double[] X(double[] a, double[] b)
      Finds the cross-product between two vectors
      Parameters:
      a - First vector
      b - Second vector
      Returns:
      Returns the cross-product.
    • X

      public static double[] X(double[] a, double[] b, double[] ret)
      Finds the cross-product between two vectors
      Parameters:
      a - First vector
      b - Second vector
      ret - The cross-product of a x b.
      Returns:
      Returns the cross-product ret.
    • add

      public static double[] add(double[] a, double[] b)
      sum
      Parameters:
      a - an array of double.
      b - an array of double.
      Returns:
      Returns the sum array.
    • add

      public static double[] add(double[] a, double[] b, double[] ret)
      sum
      Parameters:
      a - an array of double.
      b - an array of double.
      ret - an array of double.
      Returns:
      Returns the array ret.
    • angle

      public static double angle(double[] i, double[] j)
      angle
      Parameters:
      i - an array of double.
      j - an array of double.
      Returns:
      Returns the angle.
    • bondAngle

      public static double bondAngle(double[] i, double[] j, double[] k)
      Finds the angle formed by three atoms.
      Parameters:
      i - Atom position vector.
      j - Atom position vector (central atom).
      k - Atom position vector.
      Returns:
      Return the angle in the range [ -pi, pi ].
    • dihedralAngle

      public static double dihedralAngle(double[] ab, double[] bc, double[] cd)
      Finds the dihedral angle formed between 4 atoms, a, b, c, d, via position vectors AB, BC, and CD.
      Parameters:
      ab - Position vector AB.
      bc - Position vector BC.
      cd - Position vector CD.
      Returns:
      The dihedral angle in the range [ -pi, pi ].
    • dihedralAngle

      public static double dihedralAngle(double[] a, double[] b, double[] c, double[] d)
      Finds the dihedral angle formed between 4 atoms.
      Parameters:
      a - Atom position vector.
      b - Atom position vector.
      c - Atom position vector.
      d - Atom position vector.
      Returns:
      The dihedral angle in the range [ -pi, pi ].
    • dist

      public static double dist(double[] a, double[] b)
      Finds the distance between two vectors.
      Parameters:
      a - First vector.
      b - Second vector.
      Returns:
      Returns the distance between vectors a and b.
    • dist2

      public static double dist2(double[] a, double[] b)
      Finds the squared distance between two vectors
      Parameters:
      a - First vector.
      b - Second vector.
      Returns:
      Returns the squared distance between vectors a and b.
    • dot

      public static double dot(double[] a, double[] b)
      Finds the dot product between two vectors.
      Parameters:
      a - First vector.
      b - Second vector.
      Returns:
      Returns the dot product of a and b.
    • length

      public static double length(double[] d)
      Finds the length of a vector.
      Parameters:
      d - A vector to find the length of.
      Returns:
      Length of vector d.
    • length2

      public static double length2(double[] d)
      Finds the length^2 of a vector.
      Parameters:
      d - A vector to find the length of.
      Returns:
      Returns the length^2 of vector d.
    • log

      public static void log(double[] v)
      logVector
      Parameters:
      v - an array of double.
    • log

      public static void log(double[] v, String label)
      logVector.
      Parameters:
      v - an array of
      invalid reference
      double
      objects.
      label - a String object.
    • normalize

      public static double[] normalize(double[] n)
      Normalizes a vector.
      Parameters:
      n - A vector to be normalized.
      Returns:
      Returns the normalized vector.
    • normalize

      public static double[] normalize(double[] n, double[] ret)
      Normalizes a vector.
      Parameters:
      n - A vector to be normalized.
      ret - The normalized vector.
      Returns:
      Returns the normalized vector.
    • scale

      public static double[] scale(double[] n, double a)
      Scales a vector.
      Parameters:
      n - A vector to be scaled.
      a - A scalar value.
      Returns:
      Returns the scaled vector.
    • scale

      public static double[] scale(double[] n, double a, double[] ret)
      Scales a vector.
      Parameters:
      n - A vector to be scaled.
      a - A scalar value.
      ret - The scaled vector.
      Returns:
      Returns the array ret.
    • square

      public static double[] square(double[] n)
      Squares values of a vector.
      Parameters:
      n - A vector to be squared.
      Returns:
      Returns the squared vector.
    • square

      public static double[] square(double[] n, double[] ret)
      Squares values of a vector.
      Parameters:
      n - A vector to be squared.
      ret - The squared vector.
      Returns:
      Returns the array ret.
    • squareRoot

      public static double[] squareRoot(double[] n)
      Square root values of a vector.
      Parameters:
      n - A vector to determine square root.
      Returns:
      Returns the rooted vector.
    • squareRoot

      public static double[] squareRoot(double[] n, double[] ret)
      Square root values of a vector.
      Parameters:
      n - A vector to determine square root.
      ret - The rooted vector.
      Returns:
      Returns the array ret.
    • sub

      public static double[] sub(double[] a, double[] b)
      Finds the difference between two vectors.
      Parameters:
      a - First vector
      b - Second vector
      Returns:
      Returns the difference.
    • sub

      public static double[] sub(double[] a, double[] b, double[] ret)
      Finds the difference between two vectors.
      Parameters:
      a - First vector
      b - Second vector
      ret - Return Values
      Returns:
      Returns the difference ret.
    • toString

      public static String toString(double[] v)
      logVector.
      Parameters:
      v - an array of double.
      Returns:
      Returns a String description of the vector.
    • toString

      public static String toString(@Nullable double[] v, @Nullable String label)
      vectorToString.
      Parameters:
      v - an array of
      invalid reference
      double
      objects.
      label - a String object.
      Returns:
      Returns a String description of the vector.