Class MipavMath


  • public class MipavMath
    extends java.lang.Object
    Math functions not found in Java's Math class or they are slow. All methods should be static.
    • Constructor Summary

      Constructors 
      Constructor Description
      MipavMath()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double angle​(float[] x, float[] y, float[] res)
      Calculates the angle between two lines.
      static int dimPowerOfTwo​(int dim)
      Calculate the dimension value to power of 2.
      static double distance​(double x1, double x2, double y1, double y2)
      Finds the distance between two 2D points.
      static double distance​(float x1, float x2, float y1, float y2)
      Finds the distance between two points.
      static double distance​(float x0, float y0, float z0, float x1, float y1, float z1)
      Calculates the actual distance between two 3D points.
      static double distance​(float x0, float y0, float z0, float x1, float y1, float z1, float[] res)
      Calculates the actual distance between two 3D points using voxel resolutions.
      static double distance​(int x1, int x2, int y1, int y2)
      Calculates the 2D euclidian distance between two points.
      static double distance​(WildMagic.LibFoundation.Mathematics.Vector3f pt1, WildMagic.LibFoundation.Mathematics.Vector3f pt2)
      Calculates the 3D euclidian distance between two points.
      static double distance​(WildMagic.LibFoundation.Mathematics.Vector3f pt1, WildMagic.LibFoundation.Mathematics.Vector3f pt2, float[] res)
      Calculates the 3D euclidian distance between two points.
      static double distance​(WildMagic.LibFoundation.Mathematics.Vector3f pt1, WildMagic.LibFoundation.Mathematics.Vector3f pt2, float[][] res)
      Calculates the 3D euclidian distance between two points.
      static int findMinimumPowerOfTwo​(int num)
      Calculate the minimum power of two which is greater or equal to the number.
      static double hypot​(double a, double b)
      Calculates the hypotenuse equal to the sqrt(a^2 + b^2) without under/overflow
      static boolean isPowerOfTwo​(int value)
      Determines if the input is an exact power of two.
      static double length​(double[] x, double[] y, float[] res)
      Returns the real length (adjusted by the image resolution) of the line between (x[0], y[0]) and (x[1], y[1]).
      static double length​(double x0, double y0, double x1, double y1, float[] res)
      Returns the real length (adjusted by the image resolution) of the line between (x0, y0) and (x1, y1).
      static double length​(float[] x, float[] y, float[] res)
      Returns the real length (adjusted by the image resolution) of the line between (x[0], y[0]) and (x[1], y[1]).
      static double length​(float x0, float y0, float x1, float y1, float[] res)
      Returns the real length (adjusted by the image resolution) of the line between (x0, y0) and (x1, y1).
      static float magnitude​(float real, float imaginary)
      Calculates magnitude from real and imaginary parts magnitude = ( (real)^2 + (imaginary)^2 )^(1/2);
      static double max​(double[] data)
      Returns the maximum value found in a double array.
      static float max​(float[] data)
      Returns the maximum value found in a float array.
      static short max​(short[] data)
      Returns the maximum value found in a short array.
      static double min​(double[] data)
      Returns the minimum value found in a double array.
      static float min​(float[] data)
      Returns the minimum value found in a float array.
      static short min​(short[] data)
      Returns the minimum value found in a short array.
      static int nextPowerOfTwo​(int value)
      Calculates and returns the integer >= input value that is an exact power of two.
      static float phase​(float real, float imaginary)
      Calculates phase from real and imaginary parts.
      static int round​(double a)
      Round the value of type double to the closest integer.
      static int round​(float a)
      Round the value of type float to the closest integer.
      • Methods inherited from class java.lang.Object

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

      • MipavMath

        public MipavMath()
    • Method Detail

      • angle

        public static final double angle​(float[] x,
                                         float[] y,
                                         float[] res)
        Calculates the angle between two lines.
        Parameters:
        x - X values.
        y - Y values.
        res - Voxel resolutions.
        Returns:
        the angle between two lines.
      • dimPowerOfTwo

        public static int dimPowerOfTwo​(int dim)
        Calculate the dimension value to power of 2.
        Parameters:
        dim - dimension value.
        Returns:
        value dimension value in power of 2
      • distance

        public static final double distance​(double x1,
                                            double x2,
                                            double y1,
                                            double y2)
        Finds the distance between two 2D points.
        Parameters:
        x1 - x coordinate of the first point
        x2 - x coordinate of the second point
        y1 - y coordinate of the first point
        y2 - y coordinate of the second point
        Returns:
        the distance as a double
      • distance

        public static final double distance​(float x1,
                                            float x2,
                                            float y1,
                                            float y2)
        Finds the distance between two points.
        Parameters:
        x1 - x coordinate of the first point
        x2 - x coordinate of the second point
        y1 - y coordinate of the first point
        y2 - y coordinate of the second point
        Returns:
        the distance as a double
      • distance

        public static final double distance​(float x0,
                                            float y0,
                                            float z0,
                                            float x1,
                                            float y1,
                                            float z1)
        Calculates the actual distance between two 3D points.
        Parameters:
        x0 - x coordinate of the first point
        y0 - y coordinate of the first point
        z0 - z coordinate of the first point
        x1 - x coordinate of the second point
        y1 - y coordinate of the second point
        z1 - z coordinate of the second point
        Returns:
        DOCUMENT ME!
      • distance

        public static final double distance​(float x0,
                                            float y0,
                                            float z0,
                                            float x1,
                                            float y1,
                                            float z1,
                                            float[] res)
        Calculates the actual distance between two 3D points using voxel resolutions.
        Parameters:
        x0 - x coordinate of the first point
        y0 - y coordinate of the first point
        z0 - z coordinate of the first point
        x1 - x coordinate of the second point
        y1 - y coordinate of the second point
        z1 - z coordinate of the second point
        res - Voxel resolutions.
        Returns:
        DOCUMENT ME!
      • distance

        public static final double distance​(int x1,
                                            int x2,
                                            int y1,
                                            int y2)
        Calculates the 2D euclidian distance between two points.
        Parameters:
        x1 - first x coordinate
        x2 - second x coordinate
        y1 - first y coordinate
        y2 - second y coordinate
        Returns:
        returns the distance
      • distance

        public static final double distance​(WildMagic.LibFoundation.Mathematics.Vector3f pt1,
                                            WildMagic.LibFoundation.Mathematics.Vector3f pt2)
        Calculates the 3D euclidian distance between two points.
        Parameters:
        pt1 - first point
        pt2 - second point
        Returns:
        returns the distance
      • distance

        public static final double distance​(WildMagic.LibFoundation.Mathematics.Vector3f pt1,
                                            WildMagic.LibFoundation.Mathematics.Vector3f pt2,
                                            float[] res)
        Calculates the 3D euclidian distance between two points.
        Parameters:
        pt1 - first point
        pt2 - second point
        Returns:
        returns the distance
      • distance

        public static final double distance​(WildMagic.LibFoundation.Mathematics.Vector3f pt1,
                                            WildMagic.LibFoundation.Mathematics.Vector3f pt2,
                                            float[][] res)
        Calculates the 3D euclidian distance between two points.
        Parameters:
        pt1 - first point
        pt2 - second point
        Returns:
        returns the distance
      • findMinimumPowerOfTwo

        public static int findMinimumPowerOfTwo​(int num)
        Calculate the minimum power of two which is greater or equal to the number.
        Returns:
        the minimum power of two which is greater or equal to the value
      • hypot

        public static double hypot​(double a,
                                   double b)
        Calculates the hypotenuse equal to the sqrt(a^2 + b^2) without under/overflow. *
        Returns:
        sqrt(a^2 + b^2)
      • isPowerOfTwo

        public static final boolean isPowerOfTwo​(int value)
        Determines if the input is an exact power of two.
        Parameters:
        value -
        Returns:
        true if the input is an exact power of two, false otherwise.
      • length

        public static final double length​(double x0,
                                          double y0,
                                          double x1,
                                          double y1,
                                          float[] res)
        Returns the real length (adjusted by the image resolution) of the line between (x0, y0) and (x1, y1).
        Parameters:
        x0 - x coordinate of the first point
        y0 - y coordinate of the first point
        x1 - x coordinate of the second point
        y1 - y coordinate of the second point
        res - resolutions in each dimension
        Returns:
        returns the length
      • length

        public static final double length​(double[] x,
                                          double[] y,
                                          float[] res)
        Returns the real length (adjusted by the image resolution) of the line between (x[0], y[0]) and (x[1], y[1]).
        Parameters:
        x - array of the x coordinates
        y - array of the y coordinates
        res - resolutions in each dimension
        Returns:
        returns the length
      • length

        public static final double length​(float x0,
                                          float y0,
                                          float x1,
                                          float y1,
                                          float[] res)
        Returns the real length (adjusted by the image resolution) of the line between (x0, y0) and (x1, y1).
        Parameters:
        x0 - x coordinate of the first point
        y0 - y coordinate of the first point
        x1 - x coordinate of the second point
        y1 - y coordinate of the second point
        res - resolutions in each dimension
        Returns:
        returns the length
      • length

        public static final double length​(float[] x,
                                          float[] y,
                                          float[] res)
        Returns the real length (adjusted by the image resolution) of the line between (x[0], y[0]) and (x[1], y[1]).
        Parameters:
        x - array of the x coordinates
        y - array of the y coordinates
        res - resolutions in each dimension
        Returns:
        returns the length
      • magnitude

        public static final float magnitude​(float real,
                                            float imaginary)
        Calculates magnitude from real and imaginary parts magnitude = ( (real)^2 + (imaginary)^2 )^(1/2);
      • max

        public static float max​(float[] data)
        Returns the maximum value found in a float array.
        Parameters:
        data - the data array
        Returns:
        minimum value in the array.
      • max

        public static double max​(double[] data)
        Returns the maximum value found in a double array.
        Parameters:
        data - the data array
        Returns:
        minimum value in the array.
      • max

        public static short max​(short[] data)
        Returns the maximum value found in a short array.
        Parameters:
        data - the data array
        Returns:
        minimum value in the array.
      • min

        public static float min​(float[] data)
        Returns the minimum value found in a float array.
        Parameters:
        data - the data array
        Returns:
        minimum value in the array.
      • min

        public static double min​(double[] data)
        Returns the minimum value found in a double array.
        Parameters:
        data - the data array
        Returns:
        minimum value in the array.
      • min

        public static short min​(short[] data)
        Returns the minimum value found in a short array.
        Parameters:
        data - the data array
        Returns:
        minimum value in the array.
      • nextPowerOfTwo

        public static int nextPowerOfTwo​(int value)
        Calculates and returns the integer >= input value that is an exact power of two.
        Parameters:
        value - number to calculate next power of two for.
        Returns:
        integer >= value that is an exact power of two.
      • phase

        public static final float phase​(float real,
                                        float imaginary)
        Calculates phase from real and imaginary parts.
        Returns:
        phase = arctan(imagData/realData);
      • round

        public static final int round​(double a)
        Round the value of type double to the closest integer. Java's Math.round is incredibly slow.
        Parameters:
        a - float the value to be rounded.
        Returns:
        int Returns the closest integer.
      • round

        public static final int round​(float a)
        Round the value of type float to the closest integer. Java's Math.round is incredibly slow. Note that this function does not work correctly for a = -0.49999997f, the closest floating point number to -0.5f, and returns -1, while the slower Java Math.round at least returns the correct value of 0.
        Parameters:
        a - float the value to be rounded.
        Returns:
        int Returns the closest integer.