List of usage examples for java.lang Math asin
public static double asin(double a)
From source file:ffx.potential.extended.ExtendedVariable.java
final void setLambda(double lambda) { this.lambda = lambda; this.lSwitch = switchingFunction.taper(lambda); this.dlSwitch = switchingFunction.dtaper(lambda); theta = Math.asin(Math.sqrt(lambda)); discrBias = discrBiasBeta - 4 * discrBiasBeta * (lambda - 0.5) * (lambda - 0.5); dDiscrBiasdL = -8 * discrBiasBeta * (lambda - 0.5); updateBondedLambdas();/* www . jav a 2s . c o m*/ }
From source file:elements.Vector3D.java
/** Compute the angular separation between two vectors. * <p>This method computes the angular separation between two * vectors using the dot product for well separated vectors and the * cross product for almost aligned vectors. This allow to have a * good accuracy in all cases, even for vectors very close to each * other.</p>//from w w w . j a v a 2s . c o m * @param v1 first vector * @param v2 second vector * @return angular separation between v1 and v2 * @exception ArithmeticException if either vector has a null norm */ public static double angle(Vector3D v1, Vector3D v2) { double normProduct = v1.getNorm() * v2.getNorm(); if (normProduct == 0) { // throw new ArithmeticException("null norm"); } double dot = dotProduct(v1, v2); double threshold = normProduct * 0.9999; if ((dot < -threshold) || (dot > threshold)) { // the vectors are almost aligned, compute using the sine Vector3D v3 = crossProduct(v1, v2); if (dot >= 0) { return Math.asin(v3.getNorm() / normProduct); } return Math.PI - Math.asin(v3.getNorm() / normProduct); } // the vectors are sufficiently separated to use the cosine return Math.acos(dot / normProduct); }
From source file:com.codetroopers.betterpickers.radialtimepicker.RadialSelectorView.java
public int getDegreesFromCoords(float pointX, float pointY, boolean forceLegal, final Boolean[] isInnerCircle) { if (!mDrawValuesReady) { return -1; }//from ww w .ja v a2 s. co m double hypotenuse = Math .sqrt((pointY - mYCenter) * (pointY - mYCenter) + (pointX - mXCenter) * (pointX - mXCenter)); // Check if we're outside the range if (mHasInnerCircle) { if (forceLegal) { // If we're told to force the coordinates to be legal, we'll set the isInnerCircle // boolean based based off whichever number the coordinates are closer to. int innerNumberRadius = (int) (mCircleRadius * mInnerNumbersRadiusMultiplier); int distanceToInnerNumber = (int) Math.abs(hypotenuse - innerNumberRadius); int outerNumberRadius = (int) (mCircleRadius * mOuterNumbersRadiusMultiplier); int distanceToOuterNumber = (int) Math.abs(hypotenuse - outerNumberRadius); isInnerCircle[0] = (distanceToInnerNumber <= distanceToOuterNumber); } else { // Otherwise, if we're close enough to either number (with the space between the // two allotted equally), set the isInnerCircle boolean as the closer one. // appropriately, but otherwise return -1. int minAllowedHypotenuseForInnerNumber = (int) (mCircleRadius * mInnerNumbersRadiusMultiplier) - mSelectionRadius; int maxAllowedHypotenuseForOuterNumber = (int) (mCircleRadius * mOuterNumbersRadiusMultiplier) + mSelectionRadius; int halfwayHypotenusePoint = (int) (mCircleRadius * ((mOuterNumbersRadiusMultiplier + mInnerNumbersRadiusMultiplier) / 2)); if (hypotenuse >= minAllowedHypotenuseForInnerNumber && hypotenuse <= halfwayHypotenusePoint) { isInnerCircle[0] = true; } else if (hypotenuse <= maxAllowedHypotenuseForOuterNumber && hypotenuse >= halfwayHypotenusePoint) { isInnerCircle[0] = false; } else { return -1; } } } else { // If there's just one circle, we'll need to return -1 if: // we're not told to force the coordinates to be legal, and // the coordinates' distance to the number is within the allowed distance. if (!forceLegal) { int distanceToNumber = (int) Math.abs(hypotenuse - mLineLength); // The max allowed distance will be defined as the distance from the center of the // number to the edge of the circle. int maxAllowedDistance = (int) (mCircleRadius * (1 - mNumbersRadiusMultiplier)); if (distanceToNumber > maxAllowedDistance) { return -1; } } } float opposite = Math.abs(pointY - mYCenter); double radians = Math.asin(opposite / hypotenuse); int degrees = (int) (radians * 180 / Math.PI); // Now we have to translate to the correct quadrant. boolean rightSide = (pointX > mXCenter); boolean topSide = (pointY < mYCenter); if (rightSide && topSide) { degrees = 90 - degrees; } else if (rightSide && !topSide) { degrees = 90 + degrees; } else if (!rightSide && !topSide) { degrees = 270 - degrees; } else if (!rightSide && topSide) { degrees = 270 + degrees; } return degrees; }
From source file:gov.wa.wsdot.android.wsdot.ui.amtrakcascades.AmtrakCascadesSchedulesActivity.java
/** * Haversine formula/*from www . j a v a 2s. c o m*/ * * Provides great-circle distances between two points on a sphere from their longitudes and latitudes * * http://en.wikipedia.org/wiki/Haversine_formula * * @param latitude * @param longitude */ protected void getDistanceFromStation(double latitude, double longitude) { for (AmtrakCascadesStationItem station : amtrakStationItems) { double earthRadius = 3958.75; // miles double dLat = Math.toRadians(station.getLatitude() - latitude); double dLng = Math.toRadians(station.getLongitude() - longitude); double sindLat = Math.sin(dLat / 2); double sindLng = Math.sin(dLng / 2); double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2) * Math.cos(Math.toRadians(latitude)) * Math.cos(Math.toRadians(station.getLatitude())); double c = 2 * Math.asin(Math.sqrt(a)); int distance = (int) Math.round(earthRadius * c); station.setDistance(distance); } getFromLocation(); }
From source file:org.opensha.commons.geo.LocationUtils.java
/** * Computes the shortest distance between a point and a line (great-circle). * that extends infinitely in both directions. Both the line and point are * assumed to be at the earth's surface; the depth component of each * <code>Location</code> is ignored. This method uses the true spherical * geometric function for 'off-track distance'; See <a * href="http://williams.best.vwh.net/avform.htm#XTE"> Aviation * Formulary</a> for source. The sign of the result indicates which side of * the supplied line <code>p3</code> is on (right:[+] left:[-]).<br/> * <br/>/* ww w .j av a 2 s .c o m*/ * This method, though more accurate over longer distances and line lengths, * is up to 20x slower than * {@link #distanceToLineFast(Location, Location, Location)}. However, this * method returns accurate results for values spanning #177;180°. <br/> * <br/> * If the line should instead be treated as a segment such that the result * will be a distance to an endpoint if <code>p3</code> does not project * onto the segment, use * {@link #distanceToLineSegment(Location, Location, Location)} instead. * * @param p1 the first <code>Location</code> point on the line * @param p2 the second <code>Location</code> point on the line * @param p3 the <code>Location</code> point for which distance will be * calculated * @return the shortest distance in km between the supplied point and line * @see #distanceToLineFast(Location, Location, Location) * @see #distanceToLineSegment(Location, Location, Location) */ public static double distanceToLine(Location p1, Location p2, Location p3) { // angular distance double ad13 = angle(p1, p3); // delta azimuth p1 to p3 and azimuth p1 to p2 double Daz13az12 = azimuthRad(p1, p3) - azimuthRad(p1, p2); // cross-track distance (in radians) double xtd = Math.asin(Math.sin(ad13) * Math.sin(Daz13az12)); return (Math.abs(xtd) < TOLERANCE) ? 0.0 : xtd * EARTH_RADIUS_MEAN; }
From source file:info.wncwaterfalls.app.ResultsActivity.java
public static Location calculatePositionAtRange(Location origin, double range, double bearing) { double EarthRadius = 6371000; // m double latA = Math.toRadians(origin.getLatitude()); double lonA = Math.toRadians(origin.getLongitude()); double angularDistance = range / EarthRadius; double trueCourse = Math.toRadians(bearing); double lat = Math.asin(Math.sin(latA) * Math.cos(angularDistance) + Math.cos(latA) * Math.sin(angularDistance) * Math.cos(trueCourse)); double dlon = Math.atan2(Math.sin(trueCourse) * Math.sin(angularDistance) * Math.cos(latA), Math.cos(angularDistance) - Math.sin(latA) * Math.sin(lat)); double lon = ((lonA + dlon + Math.PI) % (Math.PI * 2)) - Math.PI; lat = Math.toDegrees(lat);/*from w w w . ja va2 s.c o m*/ lon = Math.toDegrees(lon); Location destination = new Location(""); destination.setLatitude((float) lat); destination.setLongitude((float) lon); return destination; }
From source file:com.example.gps_project.Places.java
public static double GetDistance(double lat1, double lng1, double lat2, double lng2) { double radLat1 = rad(lat1); double radLat2 = rad(lat2); double a = radLat1 - radLat2; double b = rad(lng1) - rad(lng2); 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 ww .ja va2 s . co m s = Math.round(s * 10000) / 10000; return s; }
From source file:org.marinemc.util.Location.java
/** * Rotate the yaw to look at an X and Z cordinate * @param x The X to look at//from w w w .j a v a 2s . c om * @param z The Z to look at */ public void lookAt(double x, double z) { double l = this.x - x; double w = this.z - z; double c = Math.sqrt(l * l + w * w); if ((Math.asin(w / c) / Math.PI * 180) > 90) setYaw((float) (180 - (-Math.asin(l / c) / Math.PI * 180))); else setYaw((float) (-Math.asin(l / c) / Math.PI * 180)); }
From source file:com.seekret.data.flickr.FlickrRequestHandler.java
/** * This method generates satelites around a given spot. Attention, using * this method for requests to flickr, we can get problems with write/read * operations and problems with the spot size ( > 1MB) concerning memcache. * /*from w ww .j a va 2 s. c o m*/ * @param spot * given Spot. * @param allPoints * Map of Points with spotradius. */ @SuppressWarnings("unused") private void createSatelitesArroundGivenSpot(Spot spot, HashMap<LatLng, Double> allPoints) { for (int degree = 0; degree < 316; degree += 45) { double d = spot.getSpotRadiusInKm() + (spot.getSpotRadiusInKm() / 2.0); System.out.println("Distance = " + d); double dist = d / 6371.0; double brng = Math.toRadians(degree); double lat1 = Math.toRadians(spot.getLatitude()); double lon1 = Math.toRadians(spot.getLongitude()); double lat2 = Math .asin(Math.sin(lat1) * Math.cos(dist) + Math.cos(lat1) * Math.sin(dist) * Math.cos(brng)); double a = Math.atan2(Math.sin(brng) * Math.sin(dist) * Math.cos(lat1), Math.cos(dist) - Math.sin(lat1) * Math.sin(lat2)); System.out.println("a = " + a); double lon2 = lon1 + a; lon2 = (lon2 + 3 * Math.PI) % (2 * Math.PI) - Math.PI; double latitude2 = Math.toDegrees(lat2); double longitude2 = Math.toDegrees(lon2); System.out.println("Latitude = " + latitude2 + "\nLongitude = " + longitude2); LatLng origin = new LatLng(spot.getLatitude(), spot.getLongitude()); LatLng newPoint = new LatLng(latitude2, longitude2); log.log(Level.INFO, "DISTANCE TO CENTER " + (LatLngTool.distance(origin, newPoint, LengthUnit.KILOMETER))); allPoints.put(newPoint, Double.valueOf(spot.getSpotRadiusInKm() / 2.0)); } }
From source file:org.dawnsci.plotting.tools.powdercheck.PowderCheckJob.java
private List<PowderCheckResult> fitPeaksToTrace(final Dataset xIn, final Dataset yIn, Dataset baselineIn) { resultList.clear();/*from ww w . j ava2 s .c o m*/ List<HKL> spacings = CalibrationFactory.getCalibrationStandards().getCalibrant().getHKLs(); final double[] qVals = new double[spacings.size()]; for (int i = 0; i < spacings.size(); i++) { if (xAxis == XAxis.ANGLE) qVals[i] = 2 * Math.toDegrees(Math.asin((metadata.getDiffractionCrystalEnvironment().getWavelength() / (2 * spacings.get(i).getDNano() * 10)))); else qVals[i] = (Math.PI * 2) / (spacings.get(i).getDNano() * 10); } double qMax = xIn.max().doubleValue(); double qMin = xIn.min().doubleValue(); List<Double> qList = new ArrayList<Double>(); int count = 0; for (double q : qVals) { if (q > qMax || q < qMin) continue; count++; qList.add(q); } double minPeak = Collections.min(qList); double maxPeak = Collections.max(qList); int minXidx = ROISliceUtils.findPositionOfClosestValueInAxis(xIn, minPeak) - EDGE_PIXEL_NUMBER; int maxXidx = ROISliceUtils.findPositionOfClosestValueInAxis(xIn, maxPeak) + EDGE_PIXEL_NUMBER; int maxSize = xIn.getSize(); minXidx = minXidx < 0 ? 0 : minXidx; maxXidx = maxXidx > maxSize - 1 ? maxSize - 1 : maxXidx; final Dataset x = xIn.getSlice(new int[] { minXidx }, new int[] { maxXidx }, null); final Dataset y = yIn.getSlice(new int[] { minXidx }, new int[] { maxXidx }, null); y.setName("Fit"); Dataset baseline = baselineIn.getSlice(new int[] { minXidx }, new int[] { maxXidx }, null); List<APeak> peaks = Generic1DFitter.fitPeaks(x, y, Gaussian.class, count + 10); List<PowderCheckResult> initResults = new ArrayList<PowderCheckResult>(); CompositeFunction cf = new CompositeFunction(); for (APeak peak : peaks) cf.addFunction(peak); double limit = findMatchLimit(qList, cf); while (cf.getNoOfFunctions() != 0 && !qList.isEmpty()) findMatches(initResults, qList, cf, limit); final CompositeFunction cfFinal = compositeFunctionFromResults(initResults); double[] initParam = new double[cfFinal.getFunctions().length * 3]; { int i = 0; for (IFunction func : cfFinal.getFunctions()) { initParam[i++] = func.getParameter(0).getValue(); initParam[i++] = func.getParameter(1).getValue(); initParam[i++] = func.getParameter(2).getValue(); } } final Dataset yfit = DatasetFactory.zeros(x, Dataset.FLOAT64); MultivariateOptimizer opt = new SimplexOptimizer(REL_TOL, ABS_TOL); MultivariateFunction fun = new MultivariateFunction() { @Override public double value(double[] arg0) { int j = 0; for (IFunction func : cfFinal.getFunctions()) { double[] p = func.getParameterValues(); p[0] = arg0[j++]; p[1] = arg0[j++]; p[2] = arg0[j++]; func.setParameterValues(p); } for (int i = 0; i < yfit.getSize(); i++) { yfit.set(cfFinal.val(x.getDouble(i)), i); } return y.residual(yfit); } }; opt.optimize(new InitialGuess(initParam), GoalType.MINIMIZE, new ObjectiveFunction(fun), new MaxEval(MAX_EVAL), new NelderMeadSimplex(initParam.length)); Dataset fit = Maths.add(yfit, baseline); fit.setName("Fit"); Dataset residual = Maths.subtract(y, yfit); residual.setName("Residual"); system.updatePlot1D(x, Arrays.asList(new IDataset[] { fit, residual }), null); setPlottingSystemAxes(); for (int i = 0; i < cfFinal.getNoOfFunctions(); i++) { resultList.add(new PowderCheckResult(cfFinal.getFunction(i), initResults.get(i).getCalibrantQValue())); } return resultList; }