Package gov.nih.mipav.util
Class MipavMath
- java.lang.Object
-
- gov.nih.mipav.util.MipavMath
-
public class MipavMath extends java.lang.ObjectMath 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 doubleangle(float[] x, float[] y, float[] res)Calculates the angle between two lines.static intdimPowerOfTwo(int dim)Calculate the dimension value to power of 2.static doubledistance(double x1, double x2, double y1, double y2)Finds the distance between two 2D points.static doubledistance(float x1, float x2, float y1, float y2)Finds the distance between two points.static doubledistance(float x0, float y0, float z0, float x1, float y1, float z1)Calculates the actual distance between two 3D points.static doubledistance(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 doubledistance(int x1, int x2, int y1, int y2)Calculates the 2D euclidian distance between two points.static doubledistance(WildMagic.LibFoundation.Mathematics.Vector3f pt1, WildMagic.LibFoundation.Mathematics.Vector3f pt2)Calculates the 3D euclidian distance between two points.static doubledistance(WildMagic.LibFoundation.Mathematics.Vector3f pt1, WildMagic.LibFoundation.Mathematics.Vector3f pt2, float[] res)Calculates the 3D euclidian distance between two points.static doubledistance(WildMagic.LibFoundation.Mathematics.Vector3f pt1, WildMagic.LibFoundation.Mathematics.Vector3f pt2, float[][] res)Calculates the 3D euclidian distance between two points.static intfindMinimumPowerOfTwo(int num)Calculate the minimum power of two which is greater or equal to the number.static doublehypot(double a, double b)Calculates the hypotenuse equal to the sqrt(a^2 + b^2) without under/overflowstatic booleanisPowerOfTwo(int value)Determines if the input is an exact power of two.static doublelength(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 doublelength(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 doublelength(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 doublelength(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 floatmagnitude(float real, float imaginary)Calculates magnitude from real and imaginary parts magnitude = ( (real)^2 + (imaginary)^2 )^(1/2);static doublemax(double[] data)Returns the maximum value found in a double array.static floatmax(float[] data)Returns the maximum value found in a float array.static shortmax(short[] data)Returns the maximum value found in a short array.static doublemin(double[] data)Returns the minimum value found in a double array.static floatmin(float[] data)Returns the minimum value found in a float array.static shortmin(short[] data)Returns the minimum value found in a short array.static intnextPowerOfTwo(int value)Calculates and returns the integer >= input value that is an exact power of two.static floatphase(float real, float imaginary)Calculates phase from real and imaginary parts.static intround(double a)Round the value of type double to the closest integer.static intround(float a)Round the value of type float to the closest integer.
-
-
-
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 pointx2- x coordinate of the second pointy1- y coordinate of the first pointy2- 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 pointx2- x coordinate of the second pointy1- y coordinate of the first pointy2- 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 pointy0- y coordinate of the first pointz0- z coordinate of the first pointx1- x coordinate of the second pointy1- y coordinate of the second pointz1- 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 pointy0- y coordinate of the first pointz0- z coordinate of the first pointx1- x coordinate of the second pointy1- y coordinate of the second pointz1- z coordinate of the second pointres- 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 coordinatex2- second x coordinatey1- first y coordinatey2- 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 pointpt2- 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 pointpt2- 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 pointpt2- 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 pointy0- y coordinate of the first pointx1- x coordinate of the second pointy1- y coordinate of the second pointres- 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 coordinatesy- array of the y coordinatesres- 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 pointy0- y coordinate of the first pointx1- x coordinate of the second pointy1- y coordinate of the second pointres- 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 coordinatesy- array of the y coordinatesres- 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.
-
-