List of usage examples for java.lang Math abs
@HotSpotIntrinsicCandidate public static double abs(double a)
From source file:Main.java
public static boolean realEqual(double a, double b, double tolerance) { return Math.abs(b - a) <= tolerance; }
From source file:Main.java
public static int absHash(Object obj) { return Math.abs(hash(obj)); }
From source file:Main.java
/** * Checks if the point lies between two circles. * @param x The x coordinate of the point. * @param y The y coordinate of the point. * @param centerX The x coordinate of the center. * @param centerY The y coordinate of the center. * @param radiusInnerCircle Radius of the smaller circle. * @param radiusOuterCircle Radius of the larger circle. * @return true if the point is in between the two circles, false otherwise. */// w ww . j a v a2 s . c o m public static boolean pointLiesBetweenCircles(float x, float y, float centerX, float centerY, float radiusInnerCircle, float radiusOuterCircle) { float deltaX = Math.abs(centerX - x); if (deltaX > radiusOuterCircle && deltaX < radiusInnerCircle) { return false; } float deltaY = Math.abs(centerY - y); if (deltaY > radiusOuterCircle && deltaY < radiusInnerCircle) { return false; } float deltaXSquared = deltaX * deltaX; float deltaYSquared = deltaY * deltaY; return (deltaXSquared + deltaYSquared <= radiusOuterCircle * radiusOuterCircle) && (deltaXSquared + deltaYSquared >= radiusInnerCircle * radiusInnerCircle); }
From source file:Main.java
public static float functionNormalize(int max, int min, int value) { int intermediateValue = max - min; value -= intermediateValue;//from ww w . ja v a 2 s.co m float var = Math.abs((float) value / (float) intermediateValue); return Math.abs((float) value / (float) intermediateValue); }
From source file:Main.java
/** * Calculate the azimuth to the target location from local. *//*from w w w . j av a2 s. c om*/ private static int getPosDirection(final double startlat, final double startlong, final double endlat, final double endlon) { double slat = Math.toRadians(startlat); double elat = Math.toRadians(endlat); double slng = Math.toRadians(startlong); double elng = Math.toRadians(endlon); double Y = Math.sin(elng - slng) * Math.cos(elat); double X = Math.cos(slat) * Math.sin(elat) - Math.sin(slat) * Math.cos(elat) * Math.cos(elng - slng); double deg = Math.toDegrees(Math.atan2(Y, X)); double angle = (deg + 360) % 360; return (int) (Math.abs(angle) + (1 / 7200)); }
From source file:Main.java
public static int getNearestResColor(int color, String[] resColors) { int[] colors = new int[resColors.length]; for (int i = 0; i < resColors.length; i++) colors[i] = Color.parseColor(resColors[i]); int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); int nearest = colors[0]; int minDistance = 3 * 255; int distance; for (int col : colors) { int r2 = Color.red(col); int g2 = Color.green(col); int b2 = Color.blue(col); distance = Math.abs(r - r2) + Math.abs(g - g2) + Math.abs(b - b2); if (distance < minDistance) { minDistance = distance;//from w w w. j a va 2 s . c om nearest = col; } } return nearest; }
From source file:Main.java
static float circularInterpolate(float a, float b, float f) { if (Math.abs(b - a) > 180) { if (b > a) { a += 360;// w w w.j a v a 2 s . co m } else { b += 360; } } return (a + ((b - a) * f)) % 360; }
From source file:Main.java
public static boolean isResultPassed(float reportedFOV, float measuredFOV) { if (Math.abs(reportedFOV - measuredFOV) < 2f) return true; return false; }
From source file:Main.java
/** * <p>Compare two double arrays and return true if both not null, and are of equal length and contain equal values.</p> * * @param a1//from w w w.j a v a2 s .c om * @param a2 * @return true if equal */ static public boolean arraysAreEqual(double[] a1, double[] a2) { //System.err.println("ArrayCopyUtilities.arraysAreEqual(): a1 = "+a1); //System.err.println("ArrayCopyUtilities.arraysAreEqual(): a2 = "+a2); boolean result = true; if (a1 == null || a2 == null || a1.length != a2.length) { result = false; } else { for (int i = 0; i < a1.length; ++i) { //if (a1[i] != a2[i]) { if (Math.abs(a1[i] - a2[i]) > 0.000001) { result = false; break; } } } //System.err.println("ArrayCopyUtilities.arraysAreEqual(): "+result); return result; }
From source file:Main.java
/** * The security value is the sum of deviations between the distance * of one specific place and all the other ones in the placeDistanceMap. * * @param distanceAtOnePlace the distance for one specific place * @param placeDistanceMap the place distance map that the single gets compared to * @return the double value of the sum of deviation, also called "security value" *///from w ww. j ava 2s .com public static double securityValue(double distanceAtOnePlace, HashMap<String, Double> placeDistanceMap) { double sumDeviation = 0; for (String key : placeDistanceMap.keySet()) { sumDeviation += Math.abs(distanceAtOnePlace - placeDistanceMap.get(key)); } return sumDeviation; }