List of usage examples for java.lang Math atan
public static double atan(double a)
From source file:net.nicoulaj.benchmarks.math.DoubleAtan.java
@GenerateMicroBenchmark public void math(BlackHole hole) { for (int i = 0; i < data.length - 1; i++) hole.consume(Math.atan(data[i])); }
From source file:org.netxilia.functions.MathFunctions.java
public double ATAN(double number) { return Math.atan(number); }
From source file:com.autodomum.daylight.algorithm.DaylightAlgorithm.java
/** * Calculate length of the day for a specific day * /* w w w. ja va 2s . c om*/ * @param latitude * the latitude * @param day * the day * @return time in hours */ public double length(double latitude, int day) { final double p = Math .asin(.39795 * Math.cos(.2163108 + 2 * Math.atan(.9671396 * Math.tan(.00860 * (day - 186))))); return (24.0d - (24.0d / Math.PI) * Math .acos((Math.sin(0.8333d * Math.PI / 180d) + Math.sin(latitude * Math.PI / 180.0d) * Math.sin(p)) / (Math.cos(latitude * Math.PI / 180.0d) * Math.cos(p)))); }
From source file:pl.edu.icm.coansys.commons.stringsimilarity.EditDistanceSimilarity.java
@Override protected float doCalculate(String s1, String s2) { int levenshteinDistance = StringUtils.getLevenshteinDistance(s1, s2); int maxLength = Math.max(s1.length(), s2.length()); int normalizedLength; if (maxNormalizedStringLength > 0) { double factor = 2.0 * maxNormalizedStringLength / Math.PI; normalizedLength = (int) Math.round(factor * Math.atan((double) maxLength / factor)); } else {//from w w w.j a v a 2s . c om normalizedLength = maxLength; } if (maxLength == 0) { return 1.0f; } else if (levenshteinDistance > disapproveLevel * normalizedLength) { return 0.0f; } else if (levenshteinDistance < approveLevel * normalizedLength) { return 1.0f; } else { return (disapproveLevel * normalizedLength - levenshteinDistance) / ((disapproveLevel - approveLevel) * normalizedLength); } }
From source file:org.elasticsoftware.elasticactors.geoevents.Coordinate.java
public double distance(final double latitude, final double longitude, LengthUnit unit) { double a = 6378137, b = 6356752.3142; // ellipsiod/* w w w.ja v a 2s .c o m*/ double L = (longitude - this.longitude) * degToRad; double U1 = Math.atan((1 - f) * Math.tan(this.latitude * degToRad)); double U2 = Math.atan((1 - f) * Math.tan(latitude * degToRad)); double sinU1 = Math.sin(U1), cosU1 = Math.cos(U1); double sinU2 = Math.sin(U2), cosU2 = Math.cos(U2); double cosSqAlpha, sinSigma, cos2SigmaM, cosSigma, sigma; double lambda = L, lambdaP, iterLimit = 20; do { double sinLambda = Math.sin(lambda), cosLambda = Math.cos(lambda); sinSigma = Math.sqrt((cosU2 * sinLambda) * (cosU2 * sinLambda) + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) * (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda)); if (sinSigma == 0) return 0; // co-incident points cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda; sigma = Math.atan2(sinSigma, cosSigma); double sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma; cosSqAlpha = 1 - sinAlpha * sinAlpha; cos2SigmaM = cosSigma - 2 * sinU1 * sinU2 / cosSqAlpha; if (cos2SigmaM == Double.NaN) cos2SigmaM = 0; // equatorial line: cosSqAlpha=0 (?6) double C = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha)); lambdaP = lambda; lambda = L + (1 - C) * f * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM))); } while (Math.abs(lambda - lambdaP) > EPSILON && --iterLimit > 0); if (iterLimit == 0) return Double.NaN; double uSquared = cosSqAlpha * (a * a - b * b) / (b * b); double A = 1 + uSquared / 16384 * (4096 + uSquared * (-768 + uSquared * (320 - 175 * uSquared))); double B = uSquared / 1024 * (256 + uSquared * (-128 + uSquared * (74 - 47 * uSquared))); double deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) - B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM))); double s = b * A * (sigma - deltaSigma); return unit.convert(s, LengthUnit.METRES); }
From source file:org.um.feri.ears.problems.moo.misc.Tanaka.java
@Override public void evaluateConstraints(MOSolutionBase<Double> solution) { double[] constraints = new double[numberOfConstraints]; double[] dv = ArrayUtils.toPrimitive(solution.getVariables()); double x1 = dv[0]; double x2 = dv[1]; constraints[0] = (x1 * x1 + x2 * x2 - 1.0 - 0.1 * Math.cos(16.0 * Math.atan(x1 / x2))); constraints[1] = -2.0 * ((x1 - 0.5) * (x1 - 0.5) + (x2 - 0.5) * (x2 - 0.5) - 0.5); solution.setConstraints(constraints); double total = 0.0; int number = 0; for (int i = 0; i < constraints.length; i++) { if (constraints[i] < 0.0) { total += constraints[i];/* ww w . j av a 2s . c o m*/ number++; } } solution.setOverallConstraintViolation(total); solution.setNumberOfViolatedConstraint(number); }
From source file:RLCcircuit.RLCcircuitJFrame.java
public void ValueCaculate(double time) { angularFrequency = 2 * pi * frequency; inputVoltage = voltage0 * Math.sin(angularFrequency * time); phaseAngle = Math.atan((Lreactance - Creactance) / R) * 180 / pi; Lreactance = angularFrequency * L;/* www . j a va 2s . co m*/ Creactance = 1 / angularFrequency / C; impedance = Math.sqrt(Math.pow(R, 2) + Math.pow(2 * pi * frequency * L - 1 / (2 * pi * frequency * C), 2)); current0 = voltage0 / impedance; current = current0 * Math.sin(angularFrequency * time + phaseAngle); Rvoltage = current0 * R * Math.sin(angularFrequency * time); Lvoltage = current0 * Lreactance * Math.sin(angularFrequency * time - pi / 2); Cvoltage = current0 * Creactance * Math.sin(angularFrequency * time + pi / 2); }
From source file:Main.java
/** * Creates a region surrounding a line segment by 'widening' the line * segment. A typical use for this method is the creation of a * 'clickable' region for a line that is displayed on-screen. * * @param line the line (<code>null</code> not permitted). * @param width the width of the region. * * @return A region that surrounds the line. *///from w w w . jav a2s .com public static Shape createLineRegion(final Line2D line, final float width) { final GeneralPath result = new GeneralPath(); final float x1 = (float) line.getX1(); final float x2 = (float) line.getX2(); final float y1 = (float) line.getY1(); final float y2 = (float) line.getY2(); if ((x2 - x1) != 0.0) { final double theta = Math.atan((y2 - y1) / (x2 - x1)); final float dx = (float) Math.sin(theta) * width; final float dy = (float) Math.cos(theta) * width; result.moveTo(x1 - dx, y1 + dy); result.lineTo(x1 + dx, y1 - dy); result.lineTo(x2 + dx, y2 - dy); result.lineTo(x2 - dx, y2 + dy); result.closePath(); } else { // special case, vertical line result.moveTo(x1 - width / 2.0f, y1); result.lineTo(x1 + width / 2.0f, y1); result.lineTo(x2 + width / 2.0f, y2); result.lineTo(x2 - width / 2.0f, y2); result.closePath(); } return result; }
From source file:uk.me.berndporr.iirj.BandPassTransform.java
public BandPassTransform(double fc, double fw, LayoutBase digital, LayoutBase analog) { digital.reset();//from w ww. ja v a2 s . c o m double ww = 2 * Math.PI * fw; // pre-calcs wc2 = 2 * Math.PI * fc - (ww / 2); wc = wc2 + ww; // what is this crap? if (wc2 < 1e-8) wc2 = 1e-8; if (wc > Math.PI - 1e-8) wc = Math.PI - 1e-8; a = Math.cos((wc + wc2) * 0.5) / Math.cos((wc - wc2) * 0.5); b = 1 / Math.tan((wc - wc2) * 0.5); a2 = a * a; b2 = b * b; ab = a * b; ab_2 = 2 * ab; int numPoles = analog.getNumPoles(); int pairs = numPoles / 2; for (int i = 0; i < pairs; ++i) { PoleZeroPair pair = analog.getPair(i); ComplexPair p1 = transform(pair.poles.first); ComplexPair z1 = transform(pair.zeros.first); digital.addPoleZeroConjugatePairs(p1.first, z1.first); digital.addPoleZeroConjugatePairs(p1.second, z1.second); } if ((numPoles & 1) == 1) { ComplexPair poles = transform(analog.getPair(pairs).poles.first); ComplexPair zeros = transform(analog.getPair(pairs).zeros.first); digital.add(poles, zeros); } double wn = analog.getNormalW(); digital.setNormal(2 * Math.atan(Math.sqrt(Math.tan((wc + wn) * 0.5) * Math.tan((wc2 + wn) * 0.5))), analog.getNormalGain()); }
From source file:dsp.unige.figures.ChannelHelper.java
/** * Returns the rain attenuation in dB given the state s, using procedure * from [1]. [1]. A prediction model that combines Rain Attenuation and * Other Propagation Impairments Along Earth- Satellinte Paths * /*from w w w. j a v a 2s . c o m*/ * @param s * @return rain attenuation in dB. */ public static double getRainAttenuation(Station s) { // ==================== step 1 =========================== // calculate freezing height (in km) from the absolute value of station // latitude double hFr; if (s.stationLatitude >= 0 && s.stationLatitude < 23) hFr = 5.0d; else hFr = 5.0 - 0.075 * (s.stationLatitude - 23); // ==================== step 2 =========================== // calculate slant-path length Ls below the freezing height double Ls = (hFr - s.stationAltitude) / Math.sin(s.elevationAngle * Math.PI / 180); // ==================== step 3 =========================== // calculate horizontal projection Lg of the slant path length double Lg = Ls * Math.cos(s.elevationAngle * Math.PI / 180); // ==================== step 4 =========================== // obtain rain attenuation double gamma = s.getRainK() * Math.pow(s.R001, s.getRainAlpha()); // ==================== step 5 =========================== // calculate horizontal path adjustment double rh001 = 1 / (1 + 0.78 * Math.sqrt(Lg * gamma / s.frequency) - 0.38 * (1 - Math.exp(-2 * Lg))); // ==================== step 6 =========================== // calculate the adjusted rainy path length double ZETA = Math.atan((hFr - s.stationAltitude) / (Lg * rh001)); double Lr; if (ZETA > s.elevationAngle) { Lr = (Lg * rh001) / (Math.cos(s.elevationAngle * Math.PI / 180)); } else { Lr = (hFr - s.stationAltitude) / (Math.sin(s.elevationAngle * Math.PI / 180)); } // ==================== step 7 =========================== // calculate vertical path adjustment double CHI; if (Math.abs(s.elevationAngle) < 36) { CHI = 36 - s.elevationAngle; } else { CHI = 0; } double rv001 = 1 / (1 + Math.sqrt(Math.sin(s.elevationAngle * Math.PI / 180)) * (31 * (1 - Math.exp(-s.elevationAngle / (1 + CHI))) * (Math.sqrt(Lr * gamma) / Math.pow(s.frequency, 2)) - 0.45)); // ==================== step 8 =========================== // effective path length through rain double Le = Lr * rv001; // ==================== step 9 =========================== // get the attenuation exceded in 0.01% of average year time double A001 = gamma * Le; return A001; }