List of usage examples for java.lang Math sqrt
@HotSpotIntrinsicCandidate public static double sqrt(double a)
From source file:Main.java
/** * Rotate a set of coordinates by a given angle * @param c_x/* w ww . j av a 2 s. c o m*/ * @param c_y * @param thetab * @param x * @param y * @return */ public static double[] rotateCoord(double c_x, double c_y, double thetab, double x, double y) { double prc_x = x - c_x; double prc_y = y - c_y; double r = Math.sqrt(prc_x * prc_x + prc_y * prc_y); double theta = Math.atan2(prc_y, prc_x); theta = theta + thetab * Math.PI / 180.0; double pc_x = r * Math.cos(theta); double pc_y = r * Math.sin(theta); double p[] = new double[2]; p[0] = pc_x + c_x; p[1] = pc_y + c_y; return p; }
From source file:Main.java
public static double getDistance(double longitude1, double latitude1, double longitude2, double latitude2) { double Lat1 = rad(latitude1); double Lat2 = rad(latitude2); double a = Lat1 - Lat2; double b = rad(longitude1) - rad(longitude2); double s = 2 * Math.asin(Math.sqrt( Math.pow(Math.sin(a / 2), 2) + Math.cos(Lat1) * Math.cos(Lat2) * Math.pow(Math.sin(b / 2), 2))); s = s * EARTH_RADIUS;/*from ww w . j av a 2 s .c o m*/ s = Math.round(s * 10000) / 10000; return s; }
From source file:Main.java
public static List<String> calculateResolutions(double dpi, double screenSize, boolean standard) { List<String> ret = new ArrayList<>(); double bothSquaredSum = Math.pow(dpi * screenSize, 2); for (int i = 0; i < 10000; i++) { double other = Math.sqrt(bothSquaredSum - Math.pow(i, 2)); double higher = Math.max(i, other), lower = Math.min(i, other); if (Double.isNaN(lower)) { continue; }/*from w w w . j a v a 2s .c o m*/ if (standard) { double ratio = higher / lower; if (ratio == 4.0 / 3.0 || ratio == 16.0 / 9.0 || ratio == 16.0 / 10.0) { ret.add(String.format("%.0fx%.0f", higher, lower)); } } else { ret.add(String.format("%.0fx%.0f", higher, lower)); } } return ret; }
From source file:Main.java
public static double diffHsb(int hsb1[], final int hsb2[]) { if (hsb1 == null || hsb2 == null) { return 0.0; }/*from www . j a va2s. c o m*/ if (hsb1.length < 3 || hsb2.length < 3) { return 0.0; } double h = Math.pow(hsb1[0] - hsb2[0], 2); double s = Math.pow(hsb1[1] - hsb2[1], 2); double b = Math.pow(hsb1[2] - hsb2[2], 2); return Math.sqrt(h + s + b); }
From source file:Main.java
/** * Get the vectors magnitude.//from ww w. j a v a 2 s . co m * v {1, 2, 3} * |v| 3.74... * * @param v values of vector as arraylist. * @return magnitude */ public static double magnitudeVector(ArrayList<Double> v) { double vectorContent = 0; for (Double d : v) { vectorContent += Math.pow(d, 2); } return Math.sqrt(vectorContent); }
From source file:Main.java
public static double gps2m(double lat_a, double lng_a, double lat_b, double lng_b) { double radLat1 = (lat_a * Math.PI / 180.0); double radLat2 = (lat_b * Math.PI / 180.0); double a = radLat1 - radLat2; double b = (lng_a - lng_b) * Math.PI / 180.0; double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))); s = s * EARTH_RADIUS;// w w w.j a v a 2s . c o m s = Math.round(s * 10000) / 10000; return s; }
From source file:Main.java
/** * Find the distance between two points. * //from w w w.ja v a 2s . c om * @param one * @param two * @return the distance between point one and two */ private static float getDistanceBetweenTwoPoints(PointF one, PointF two) { float dx = one.x - two.x; // horizontal difference float dy = one.y - two.y; // vertical difference float dist = (float) Math.sqrt(dx * dx + dy * dy); return dist; }
From source file:Main.java
public static float distanceBetween2Points(float vectorX0, float vectorY0, float vectorXP, float vectorYP) { float x = Math.abs(vectorXP - vectorX0); float y = Math.abs(vectorYP - vectorY0); return (float) Math.sqrt((x * x) + (y * y)); }
From source file:Main.java
public static void untransformBaidu(double wgLat, double wgLon, double[] latlng) { double x = wgLon - 0.0065, y = wgLat - 0.006; double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi); double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi); double gg_lon = z * Math.cos(theta); double gg_lat = z * Math.sin(theta); untransform(gg_lat, gg_lon, latlng); }
From source file:Main.java
private static int computeInitialSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) { double w = options.outWidth; double h = options.outHeight; int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels)); int upperBound = (minSideLength == -1) ? 128 : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength)); if (upperBound < lowerBound) { // return the larger one when there is no overlapping zone. return lowerBound; }/* w w w .ja v a2 s . c om*/ if ((maxNumOfPixels == -1) && (minSideLength == -1)) { return 1; } else if (minSideLength == -1) { return lowerBound; } else { return upperBound; } }