List of usage examples for java.lang Math sqrt
@HotSpotIntrinsicCandidate public static double sqrt(double a)
From source file:Main.java
public static double getGeoDistance(double longitude1, double latitude1, double longitude2, double latitude2) { double EARTH_RADIUS = 6378137; double radLat1 = rad(latitude1); double radLat2 = rad(latitude2); double a = radLat1 - radLat2; double b = rad(longitude1) - rad(longitude2); 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;//from w ww. j a va 2 s .co m s = Math.round(s * 10000) / 10000; return s; }
From source file:MainClass.java
static int[] createCircle(int xOffset, int yOffset, int radius) { int[] circlePoints = new int[10 * radius]; for (int loopIndex = 0; loopIndex < 2 * radius + 1; loopIndex++) { int xCurrent = loopIndex - radius; int yCurrent = (int) Math.sqrt(radius * radius - xCurrent * xCurrent); int doubleLoopIndex = 2 * loopIndex; circlePoints[doubleLoopIndex] = xCurrent + xOffset; circlePoints[doubleLoopIndex + 1] = yCurrent + yOffset; circlePoints[10 * radius - doubleLoopIndex - 2] = xCurrent + xOffset; circlePoints[10 * radius - doubleLoopIndex - 1] = -yCurrent + yOffset; }/*ww w.j ava2s. c o m*/ return circlePoints; }
From source file:MainClass.java
public static boolean isPrime(int n) { if (n < 2) return false; double max = Math.sqrt(n); for (int j = 2; j <= max; j += 1) if (n % j == 0) return false; // j is a factor return true;/*from w w w. j a v a 2s.c o m*/ }
From source file:Main.java
public static float dist(float x1, float y1, float z1, float x2, float y2, float z2) { final float x = (x2 - x1); final float y = (y2 - y1); final float z = (z2 - z1); return (float) Math.sqrt(x * x + y * y + z * z); }
From source file:Main.java
private static double getDistance(int color, int tempColor) { double red, green, blue; red = Math.pow(Color.red(tempColor) - Color.red(color), 2.0); green = Math.pow(Color.green(tempColor) - Color.green(color), 2.0); blue = Math.pow(Color.blue(tempColor) - Color.blue(color), 2.0); return Math.sqrt(blue + green + red); }
From source file:Main.java
public static float getMatrixScale(Matrix matrix) { synchronized (MATRIX_VALUES) { matrix.getValues(MATRIX_VALUES); final float scaleX = MATRIX_VALUES[Matrix.MSCALE_X]; final float skewY = MATRIX_VALUES[Matrix.MSKEW_Y]; //noinspection SuspiciousNameCombination return (float) Math.sqrt((float) Math.pow(scaleX, 2) + (float) Math.pow(skewY, 2)); }/*from w w w . j ava2 s.c o m*/ }
From source file:com.anhth12.util.WeightInitUtil.java
public static INDArray initWeight(int[] shape, WeightInit initScheme, ActivationFunction act, RealDistribution dist) {/*from ww w. ja v a 2 s .c o m*/ INDArray ret; switch (initScheme) { case VI: //Rand .* 2 .*r - r ret = Nd4j.rand(shape); int len = 0; for (int i = 0; i < shape.length; i++) { len += shape[i]; } double r = Math.sqrt(6) / Math.sqrt(len + 1); ret.muli(2).muli(r).subi(r); return ret; case ZERO: return Nd4j.create(shape); case SIZE: return uniformBasedOnInAndOut(shape, shape[0], shape[1]); case DISTRIBUTION: ret = Nd4j.rand(shape); for (int i = 0; i < ret.slices(); i++) { ret.putSlice(i, Nd4j.create(dist.sample(ret.columns()))); } case NORMALIZED: ret = Nd4j.rand(shape); return ret.subi(0.5).divi(shape[0]); case UNIFORM: double a = 1 / shape[0]; return Nd4j.rand(shape, -a, a, new MersenneTwister(123)); default: throw new AssertionError(initScheme.name()); } }
From source file:Main.java
private static void arcQuadTo(Path pathForTurn, double angle0, float radius0, double angle, float radius, double angle2, float radius2, float dl, float cx, float cy) { float X0 = getProjX(angle0, cx, cy, radius0); float Y0 = getProjY(angle0, cx, cy, radius0); float X = getProjX(angle, cx, cy, radius); float Y = getProjY(angle, cx, cy, radius); float X2 = getProjX(angle2, cx, cy, radius2); float Y2 = getProjY(angle2, cx, cy, radius2); float l2 = (float) Math.sqrt((X - X2) * (X - X2) + (Y - Y2) * (Y - Y2)); float l0 = (float) Math.sqrt((X - X0) * (X - X0) + (Y - Y0) * (Y - Y0)); float proc2 = (float) (dl / l2); float proc = (float) (dl / l0); pathForTurn.lineTo(X0 * proc + X * (1 - proc), Y0 * proc + Y * (1 - proc)); pathForTurn.quadTo(X, Y, X2 * proc2 + X * (1 - proc2), Y2 * proc2 + Y * (1 - proc2)); }
From source file:Main.java
public static double rootMeanSquared(short[] nums) { double ms = 0; for (int i = 0; i < nums.length; i++) { ms += nums[i] * nums[i];/*from w w w. ja va 2 s. co m*/ } ms /= nums.length; return Math.sqrt(ms); }
From source file:org.eclipse.swt.snippets.Snippet134.java
static int[] circle(int r, int offsetX, int offsetY) { int[] polygon = new int[8 * r + 4]; //x^2 + y^2 = r^2 for (int i = 0; i < 2 * r + 1; i++) { int x = i - r; int y = (int) Math.sqrt(r * r - x * x); polygon[2 * i] = offsetX + x;//from www . java 2 s . co m polygon[2 * i + 1] = offsetY + y; polygon[8 * r - 2 * i - 2] = offsetX + x; polygon[8 * r - 2 * i - 1] = offsetY - y; } return polygon; }