List of usage examples for java.lang Math atan2
@HotSpotIntrinsicCandidate public static double atan2(double y, double x)
From source file:android.support.transition.PatternPathMotion.java
/** * Sets the Path defining a pattern of motion between two coordinates. * The pattern will be translated, rotated, and scaled to fit between the start and end points. * The pattern must not be empty and must have the end point differ from the start point. * * @param patternPath A Path to be used as a pattern for two-dimensional motion. */// www. j av a2s.co m public void setPatternPath(Path patternPath) { PathMeasure pathMeasure = new PathMeasure(patternPath, false); float length = pathMeasure.getLength(); float[] pos = new float[2]; pathMeasure.getPosTan(length, pos, null); float endX = pos[0]; float endY = pos[1]; pathMeasure.getPosTan(0, pos, null); float startX = pos[0]; float startY = pos[1]; if (startX == endX && startY == endY) { throw new IllegalArgumentException("pattern must not end at the starting point"); } mTempMatrix.setTranslate(-startX, -startY); float dx = endX - startX; float dy = endY - startY; float distance = distance(dx, dy); float scale = 1 / distance; mTempMatrix.postScale(scale, scale); double angle = Math.atan2(dy, dx); mTempMatrix.postRotate((float) Math.toDegrees(-angle)); patternPath.transform(mTempMatrix, mPatternPath); mOriginalPatternPath = patternPath; }
From source file:com.nanosheep.bikeroute.parser.GoogleElevationParser.java
/** * Calculate the distance between two points of the earth using * the haversine formula.//from w ww . j a va 2 s . co m * @param lat Starting latitude. * @param lng Starting longitude. * @param latA End latitude, * @param lngA End longitude. * @return The distance between the two points in m. */ private double pointDiff(final double lat, final double lng, final double latA, final double lngA) { final double dLat = Math.toRadians(latA - lat); final double dLon = Math.toRadians(lngA - lng); final double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat)) * Math.cos(Math.toRadians(latA)) * Math.sin(dLon / 2) * Math.sin(dLon / 2); final double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return BikeRouteConsts.EARTH_RADIUS * c * 1000; }
From source file:com.nextbreakpoint.nextfractal.mandelbrot.core.Expression.java
public static double funcAtan2(double x, double y) { return Math.atan2(y, x); }
From source file:org.eclipse.dawnsci.analysis.dataset.roi.fitting.CircleCoordinatesFunction.java
/** * Calculate angles of closest points on circle to targets * @param initParameters geometric parameters * @return array of all initial parameters *///from ww w.j av a2 s .c o m InitialGuess calcAllInitValues(double[] initParameters) { double[] init = new double[n + PARAMETERS]; for (int i = 0; i < initParameters.length; i++) { init[i] = initParameters[i]; } final double x = initParameters[1]; final double y = initParameters[2]; // work out the angle values for the closest points on circle final IndexIterator itx = X.getIterator(); final IndexIterator ity = Y.getIterator(); int i = PARAMETERS; while (itx.hasNext() && ity.hasNext()) { final double Xc = X.getElementDoubleAbs(itx.index) - x; final double Yc = Y.getElementDoubleAbs(ity.index) - y; init[i++] = Math.atan2(Yc, Xc); } return new InitialGuess(init); }
From source file:com.nuig.trafficapp.MyGcmListenerService.java
public static double distFrom(double lat1, double lng1, double lat2, double lng2) { double earthRadius = 6371; double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); 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(lat1)) * Math.cos(Math.toRadians(lat2)); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double dist = earthRadius * c; return dist;/*from w w w.j av a 2 s .c o m*/ }
From source file:net.rptools.image.listeners.TransformHandler.java
/** * @see #transform(String, String, boolean, String, Point2D) * @param phase phase we are in//from ww w.j a va 2 s. co m * @param fix fixed point * @param transformType transform type * @param constraints contraints * @param newDrag new transform end point */ @ThreadPolicy(ThreadPolicy.ThreadId.JFX) private void resizeIntern(final String phase, final Point2D fix, final String transformType, final String constraints, final Point2D newDrag) { if (phase.equals(START)) { previousDrag = newDrag; } if (previousDrag == null) { return; } double scalex = Math.abs((fix.getX() - newDrag.getX()) / (fix.getX() - previousDrag.getX())); if (!Double.isFinite(scalex) || scalex < SANITY_SCALE || scalex > 1 / SANITY_SCALE) { scalex = 1; } double scaley = Math.abs((fix.getY() - newDrag.getY()) / (fix.getY() - previousDrag.getY())); if (!Double.isFinite(scaley) || scaley < SANITY_SCALE || scaley > 1 / SANITY_SCALE) { scaley = 1; } final double oldRad = Math.atan2(fix.getY() - previousDrag.getY(), fix.getX() - previousDrag.getX()); final double newRad = Math.atan2(fix.getY() - newDrag.getY(), fix.getX() - newDrag.getX()); if (constraints.equals(ISO)) { final double tmp = Math.max(scalex, scaley); scalex = tmp; scaley = tmp; } String transform = "1.0;0.0;0.0;0.0;1.0;0.0"; switch (transformType) { case "rotate": transform = GeometryHelper.createTransform(fix, newRad - oldRad); break; case "scalex": transform = GeometryHelper.createTransform(fix, scalex, 1); break; case "scaley": transform = GeometryHelper.createTransform(fix, 1, scaley); break; case "scalexy": transform = GeometryHelper.createTransform(fix, scalex, scaley); break; default: break; } LOGGER.info("transform={}", transform); previousDrag = newDrag; for (ModelViewBinding binding : getSelection().getBindings()) { binding.prependTransform(transform); } if (phase.equals(END)) { previousDrag = null; } }
From source file:android.support.transition.PatternPathMotion.java
@Override public Path getPath(float startX, float startY, float endX, float endY) { float dx = endX - startX; float dy = endY - startY; float length = distance(dx, dy); double angle = Math.atan2(dy, dx); mTempMatrix.setScale(length, length); mTempMatrix.postRotate((float) Math.toDegrees(angle)); mTempMatrix.postTranslate(startX, startY); Path path = new Path(); mPatternPath.transform(mTempMatrix, path); return path;//from w w w.jav a 2 s . c o m }
From source file:jat.core.cm.TwoBodyAPL.java
public void propagate(double t0, double tf, Printable pr, boolean print_switch, double steps) { double[] temp = new double[6]; // double ta_save = this.ta; this.steps = steps; // Determine step size double n = this.meanMotion(); double period = this.period(); double dt = period / steps; if ((t0 + dt) > tf) // check to see if we're going past tf {//w ww .j a v a2s . c o m dt = tf - t0; } // determine initial E and M double sqrome2 = Math.sqrt(1.0 - this.e * this.e); double cta = Math.cos(this.ta); double sta = Math.sin(this.ta); double sine0 = (sqrome2 * sta) / (1.0 + this.e * cta); double cose0 = (this.e + cta) / (1.0 + this.e * cta); double e0 = Math.atan2(sine0, cose0); double ma = e0 - this.e * Math.sin(e0); // initialize t double t = t0; if (print_switch) { temp = this.randv(); pr.print(t, temp); } while (t < tf) { ma = ma + n * dt; double ea = solveKepler(ma, this.e); double sinE = Math.sin(ea); double cosE = Math.cos(ea); double den = 1.0 - this.e * cosE; double sinv = (sqrome2 * sinE) / den; double cosv = (cosE - this.e) / den; this.ta = Math.atan2(sinv, cosv); if (this.ta < 0.0) { this.ta = this.ta + 2.0 * Constants.pi; } t = t + dt; temp = this.randv(); this.rv = new VectorN(temp); if (print_switch) { pr.print(t, temp); } if ((t + dt) > tf) { dt = tf - t; } } // Reset everything to before this.ta = initial_ta; }
From source file:org.jcurl.core.impl.CurveManager.java
/** * Internal. Compute one rock curve segment and don't change internal state. * //from w w w. ja va 2 s . c om * @param i16 * which rock * @param t0 * starttime * @param sweepFactor * @return the new Curve in world coordinates. */ CurveRock<Pos> doComputeCurve(final int i16, final double t0, final RockSet<Pos> p, final RockSet<Vel> s, final double sweepFactor) { final Rock<Pos> x = p.getRock(i16); final Rock<Vel> v = s.getRock(i16); final CurveRock<Pos> wc; if (v.p().distanceSq(0, 0) == 0) wc = CurveStill.newInstance(x); else // Convert the initial angle from WC to RC. // TUNE 2x sqrt, 2x atan2 to 1x each? wc = new CurveTransformed<Pos>(curler.computeRc(x.getA() + Math.atan2(v.getX(), v.getY()), MathVec.abs2D(v.p()), v.getA(), sweepFactor), CurveTransformed.createRc2Wc(x.p(), v.p(), null), t0); if (log.isDebugEnabled()) log.debug(i16 + " " + wc); return wc; }
From source file:org.openhab.core.library.types.PointType.java
/** * Return the distance in meters from otherPoint, ignoring altitude. This algorithm also * ignores the oblate spheroid shape of Earth and assumes a perfect sphere, so results * are inexact./* w w w . j av a 2 s . co m*/ * * @param otherPoint * @return distance in meters * @see <a href="https://en.wikipedia.org/wiki/Haversine_formula">Haversine formula</a> */ public DecimalType distanceFrom(PointType otherPoint) { double dLat = Math.toRadians(otherPoint.latitude.doubleValue() - this.latitude.doubleValue()); double dLong = Math.toRadians(otherPoint.longitude.doubleValue() - this.longitude.doubleValue()); double a = Math.pow(Math.sin(dLat / 2D), 2D) + Math.cos(Math.toRadians(this.latitude.doubleValue())) * Math.cos(Math.toRadians(otherPoint.latitude.doubleValue())) * Math.pow(Math.sin(dLong / 2D), 2D); double c = 2D * Math.atan2(Math.sqrt(a), Math.sqrt(1D - a)); return new DecimalType(WGS84_a * c); }