List of usage examples for java.lang Math atan2
@HotSpotIntrinsicCandidate public static double atan2(double y, double x)
From source file:Main.java
/** * Given two angles in degrees, determine the smallest angle between them. * * For example, given angles 90 and 170, the smallest angle difference would be 80 * and the larger angle difference would be 280. * * @param firstAngleDeg/* w ww .j a v a 2 s. c om*/ * @param secondAngleDeg * @return smallest angle */ public static double smallestAngularDifferenceDegrees(double firstAngleDeg, double secondAngleDeg) { double rawDiffDeg = firstAngleDeg - secondAngleDeg; double rawDiffRad = rawDiffDeg * Math.PI / 180; double wrappedDiffRad = Math.atan2(Math.sin(rawDiffRad), Math.cos(rawDiffRad)); double wrappedDiffDeg = wrappedDiffRad * 180 / Math.PI; return wrappedDiffDeg; }
From source file:org.gearvrf.controls.util.MathUtils.java
public static float getYRotationAngle(GVRSceneObject rotatingObject, GVRSceneObject targetObject) { return (float) Math.toDegrees(Math.atan2( targetObject.getTransform().getPositionX() - rotatingObject.getTransform().getPositionX(), targetObject.getTransform().getPositionZ() - rotatingObject.getTransform().getPositionZ())); }
From source file:r.base.MathExt.java
@Primitive public static double atan2(double y, double x) { return (Math.atan2(y, x)); }
From source file:Main.java
private static float transformAngle(Matrix m, float angleRadians) { // Construct and transform a vector oriented at the specified clockwise // angle from vertical. Coordinate system: down is increasing Y, right is // increasing X. float[] v = new float[2]; v[0] = (float) Math.sin(angleRadians); v[1] = (float) -Math.cos(angleRadians); m.mapVectors(v);/*w w w.ja va2 s.c o m*/ // Derive the transformed vector's clockwise angle from vertical. float result = (float) Math.atan2(v[0], -v[1]); if (result < -Math.PI / 2) { result += Math.PI; } else if (result > Math.PI / 2) { result -= Math.PI; } return result; }
From source file:org.renjin.MathExt.java
public static double atan2(double y, double x) { return (Math.atan2(y, x)); }
From source file:org.gearvrf.controls.util.MathUtils.java
public static float getYRotationAngle(GVRSceneObject rotatingObject, GVRCameraRig targetObject) { return (float) Math.toDegrees(Math.atan2( targetObject.getTransform().getPositionX() - rotatingObject.getTransform().getPositionX(), targetObject.getTransform().getPositionZ() - rotatingObject.getTransform().getPositionZ())); }
From source file:orchestration.path.RectShape.java
@Override public PlannerShape rotateToward(Point pt) { float o = pt.y - centerPt.y; float a = pt.x - centerPt.x; double angleRad = Math.atan2(o, a); float angleDeg = (float) (180. * angleRad / Math.PI); return rotateTo(angleDeg); }
From source file:com.google.location.lbs.gnss.gps.pseudorange.EcefToTopocentricConverter.java
/** * Transformation of {@code inputVectorMeters} with origin at {@code originECEFMeters} into * topocentric coordinate system. The result is {@code TopocentricAEDValues} containing azimuth * from north +ve clockwise, radians; elevation angle, radians; distance, vector length meters * * <p>Source: http://www.navipedia.net/index.php/Transformations_between_ECEF_and_ENU_coordinates * http://kom.aau.dk/~borre/life-l99/topocent.m * *//*from ww w. j a v a2 s .c o m*/ public static TopocentricAEDValues convertCartesianToTopocentericRadMeters(final double[] originECEFMeters, final double[] inputVectorMeters) { GeodeticLlaValues latLngAlt = Ecef2LlaConverter.convertECEFToLLACloseForm(originECEFMeters[0], originECEFMeters[1], originECEFMeters[2]); RealMatrix rotationMatrix = Ecef2EnuConverter .getRotationMatrix(latLngAlt.latitudeRadians, latLngAlt.longitudeRadians).transpose(); double[] eastNorthUpVectorMeters = GpsMathOperations .matrixByColVectMultiplication(rotationMatrix.transpose().getData(), inputVectorMeters); double eastMeters = eastNorthUpVectorMeters[EAST_IDX]; double northMeters = eastNorthUpVectorMeters[NORTH_IDX]; double upMeters = eastNorthUpVectorMeters[UP_IDX]; // calculate azimuth, elevation and height from the ENU values double horizontalDistanceMeters = Math.hypot(eastMeters, northMeters); double azimuthRadians; double elevationRadians; if (horizontalDistanceMeters < MIN_DISTANCE_MAGNITUDE_METERS) { elevationRadians = Math.PI / 2.0; azimuthRadians = 0; } else { elevationRadians = Math.atan2(upMeters, horizontalDistanceMeters); azimuthRadians = Math.atan2(eastMeters, northMeters); } if (azimuthRadians < 0) { azimuthRadians += 2 * Math.PI; } double distanceMeters = Math.sqrt(Math.pow(inputVectorMeters[0], 2) + Math.pow(inputVectorMeters[1], 2) + Math.pow(inputVectorMeters[2], 2)); return new TopocentricAEDValues(elevationRadians, azimuthRadians, distanceMeters); }
From source file:Main.java
/*************************************************************************** * This function is passed two points and calculates the angle between the * line defined by these points and the x-axis. **************************************************************************/ private static double get_angle(int p1, int p2) { int delta_x, delta_y; double ret = 0.0; /*//from w w w . j ava 2 s . c o m * Calculate (x2 - x1) and (y2 - y1). The points are passed in the form * x1y1 and x2y2. get_x() and get_y() are passed these points and return * the x and y values respectively. For example, get_x(1020) returns 10. */ delta_x = get_x(p2) - get_x(p1); delta_y = get_y(p2) - get_y(p1); if (delta_x == 0) { if (delta_y > 0) { ret = PI / 2; } else if (delta_y < 0) { ret = -PI / 2; } } else if (delta_y == 0) { if (delta_x > 0) { ret = 0.0; } else if (delta_x < 0) { ret = PI; } } else { ret = Math.atan2(delta_y, delta_x); } return ret; }
From source file:uk.ac.diamond.scisoft.analysis.fitting.EllipseFitterTest.java
@Test public void testOrthoDist() { AngleDerivativeFunction angleDerivative = new AngleDerivativeFunction(); BrentSolver solver = new BrentSolver(BrentSolver.DEFAULT_ABSOLUTE_ACCURACY); double a = 10.2; double b = 3.1; final double twopi = 2 * Math.PI; double alpha = twopi * 10. / 360; // 0 to 2 pi angleDerivative.setRadii(a, b);//from ww w . j ava 2s. com angleDerivative.setAngle(alpha); // final double ca = 0; // final double cb = b-0.5; final double Xc = -5.; // Math.cos(alpha)*ca + Math.sin(alpha)*cb; final double Yc = 5.5; //Math.sin(alpha)*ca + Math.cos(alpha)*cb; angleDerivative.setCoordinate(Xc, Yc); try { // find quadrant to use double p = Math.atan2(Yc, Xc); if (p < 0) p += twopi; p -= alpha; final double end; final double halfpi = 0.5 * Math.PI; p /= halfpi; end = Math.ceil(p) * halfpi; final double angle = solver.solve(BrentSolver.DEFAULT_MAXIMUM_ITERATIONS, angleDerivative, end - halfpi, end); // final double cos = Math.cos(angle); // final double sin = Math.sin(angle); Assert.assertEquals("Angle found is not close enough", 1.930, angle, 0.001); // double dx = a*cos + Xc; // double dy = b*sin + Yc; // // System.out.println("Bracket angle = " + Math.ceil(p)); // System.out.println("Delta angle = " + 180.*angle/Math.PI); // System.out.println(dx + ", " + dy); } catch (MaxIterationsExceededException e) { // TODO System.err.println(e); } catch (FunctionEvaluationException e) { // TODO System.err.println(e); } }