List of usage examples for java.lang Math toDegrees
public static double toDegrees(double angrad)
From source file:Main.java
/** * Calculate the angle to the target location from local. *///from ww w. j a v a 2 s .co m private static double getAngle(final double startheight, final double endheight, final float poslength) { double radian = Math.atan(Math.abs((endheight - startheight)) / poslength); double degree = Math.toDegrees(radian); if (startheight > endheight) { return -degree; } return degree; }
From source file:Main.java
public static float angleInDegrees(float originX, float originY, float targetX, float targetY) { return (float) Math.toDegrees(Math.atan2(targetY - originY, targetX - originX)); }
From source file:Main.java
/** * converts cartesian coordinates (positive Y is down, positive X is right) * into an angle in degrees (0 degrees is up, clockwise is positive). The * angle is between 0 and 359, inclusive. * /*from ww w . jav a2 s .c om*/ * @param x * @param y * @return */ public static int toAngle(int x, int y) { return (int) ((Math.toDegrees(Math.atan2(y, x)) + 90) % 360); }
From source file:Main.java
/** * Calculates the angle between two points on a cartesian plane */// w ww . j av a2 s. c om public static float getAngle(float center_x, float center_y, float post_x, float post_y) { float tmpv_x = post_x - center_x; float tmpv_y = post_y - center_y; float d = (float) Math.sqrt(tmpv_x * tmpv_x + tmpv_y * tmpv_y); float cos = tmpv_x / d; float angle = (float) Math.toDegrees(Math.acos(cos)); angle = (tmpv_y < 0) ? angle * -1 : angle; return angle; }
From source file:Main.java
public static double getBearing(double lat1, double lng1, double lat2, double lng2) { double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); lat1 = Math.toRadians(lat1);// w ww .j av a2 s .c o m lat2 = Math.toRadians(lat2); lng1 = Math.toRadians(lng1); lng2 = Math.toRadians(lng2); double y = Math.sin(dLng) * Math.cos(lat2); double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLng); double brng = Math.toDegrees(Math.atan2(y, x)); return brng; }
From source file:Main.java
/** * Gets the angle from P(center, p1) to P(center, p2), the value range is [-180, 180]. * * @param center center point/*from w ww . j a v a 2s . c o m*/ * @param p1 point 1 * @param p2 point 2 * @return angle */ public static float calculateRotationDegree(PointF center, PointF p1, PointF p2) { double angle1 = Math.atan2(p1.y - center.y, p1.x - center.x); double angle2 = Math.atan2(p2.y - center.y, p2.x - center.x); float angle = (float) Math.toDegrees(angle2 - angle1); if (angle > 180) { angle -= 360; } else if (angle < -180) { angle += 360; } return angle; }
From source file:Main.java
/** * Calculate the azimuth to the target location from local. *//*from w w w. j a v a 2 s .c o m*/ private static int getPosDirection(final double startlat, final double startlong, final double endlat, final double endlon) { double slat = Math.toRadians(startlat); double elat = Math.toRadians(endlat); double slng = Math.toRadians(startlong); double elng = Math.toRadians(endlon); double Y = Math.sin(elng - slng) * Math.cos(elat); double X = Math.cos(slat) * Math.sin(elat) - Math.sin(slat) * Math.cos(elat) * Math.cos(elng - slng); double deg = Math.toDegrees(Math.atan2(Y, X)); double angle = (deg + 360) % 360; return (int) (Math.abs(angle) + (1 / 7200)); }
From source file:Main.java
public static void getEulerAngles(float[] headView, float[] output) { float pitch = (float) Math.asin((double) headView[6]); float yaw;/*from www. java 2s. c o m*/ float roll; if (Math.abs(headView[6]) < 0.9999999999D) { yaw = (float) Math.atan2((double) (-headView[2]), (double) headView[10]); roll = (float) Math.atan2((double) (-headView[4]), (double) headView[5]); } else { yaw = 0.0F; roll = (float) Math.atan2((double) headView[1], (double) headView[0]); } output[0] = -pitch; output[1] = -yaw; output[2] = -roll; float pitchAngle = (float) Math.toDegrees(output[0]); float yawAngle = (float) Math.toDegrees(output[1]); float rollAngle = (float) Math.toDegrees(output[2]); Log.e(TAG, String.format("pitchAngle=%f, yawAngle=%f, rollAngle=%f", pitchAngle, yawAngle, rollAngle)); }
From source file:Main.java
/** * Returns the bearing from one point to another. * @param latFrom The latitude of the point from * @param lonFrom The longitude of the point from * @param latTo The latitude of the point to * @param lonTo The longitude of the point to * @return the bearing from one point to another *///from w w w . j a va 2 s . c o m private static double bearingTo(double latFrom, double lonFrom, double latTo, double lonTo) { double latitude1 = Math.toRadians(latFrom); double latitude2 = Math.toRadians(latTo); double longDiff = Math.toRadians(lonTo - lonFrom); double y = Math.sin(longDiff) * Math.cos(latitude2); double x = Math.cos(latitude1) * Math.sin(latitude2) - Math.sin(latitude1) * Math.cos(latitude2) * Math.cos(longDiff); return (Math.toDegrees(Math.atan2(y, x)) + 360) % 360; }
From source file:Main.java
public static double[] findClosePointsForDrawingArc(int x1, int x2, int y1, int y2) { double[] xy = new double[2]; double d = 5; double angle = 0; // if ((x1 - x2) != 0) { // tan a = y2-y1/x2-x1 // System.out.println(" x1 = " + x1 + " y1 = " + y1 + " | x2 = " + x2 + " | y2 = " + y2); // angle = Math.toDegrees(Math.atan2(Math.abs(y1 - y2), Math.abs(x1 - x2))); // xy[0] = (Math.cos(angle) * d) + x2; // xy[1] = (Math.sin(angle) * d) + y2; // System.out.println("xt " + xy[0] + " yt " + xy[1] + " angel would be : " + angle + " and Different number : " + d); angle = Math.toDegrees(Math.atan2(Math.abs(y1 - y2), Math.abs(x1 - x2))); System.out.println("----------------------------------vvvvv----------------------------------------"); System.out.println(" "); System.out.println("x1 " + x1 + " y1 " + y1 + " | x2 " + x2 + " y2 " + y2); System.out.println("Math.abs(x1-x2)" + Math.abs(x1 - x2) + " | Math.abs(y1-y2) " + Math.abs(y1 - y2) + " | angel would be Math.toDegrees(Math.atan2(Math.abs(y1 - y2), Math.abs(x1 - x2))) : " + angle + " | Different number : " + d); if (x1 > x2) { if (y1 > y2) { System.out.println(// w w w . j a v a2 s . co m "x1>x2 && y1>y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2 + (Math.abs(Math.cos(angle)) * d); System.out.println( "x1>x2 && y1>y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2 + (Math.abs(Math.sin(angle)) * d); } else if (y1 < y2) { System.out.println( "x1>x2 && y1< y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2 + (Math.abs(Math.cos(angle)) * d); System.out.println( "x1>x2 && y1< y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2 - (Math.abs(Math.sin(angle)) * d); } else { System.out.println( "x1>x2 && y1 = y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2 + (Math.abs(Math.cos(angle)) * d); System.out.println( "x1>x2 && y1 = y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2; } } else if (x1 < x2) { if (y1 > y2) { System.out.println( "x1<x2 && y1>y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2 - (Math.abs(Math.cos(angle)) * d); System.out.println( "x1<x2 && y1>y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2 + (Math.abs(Math.sin(angle)) * d); } else if (y1 < y2) { System.out.println( "x1<x2 && y1< y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2 - (Math.abs(Math.cos(angle)) * d); System.out.println( "x1<x2 && y1< y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2 - (Math.abs(Math.sin(angle)) * d); } else { System.out.println( "x1<x2 && y1 =y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2 - (Math.abs(Math.cos(angle)) * d); System.out.println( "x1<x2 && y1 =y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2; } } else { if (y1 > y2) { System.out.println( "x1=x2 && y1>y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2; System.out.println( "x1=x2 && y1>y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2 + (Math.abs(Math.sin(angle) * d)); } else if (y1 < y2) { System.out.println( "x1=x2 && y1< y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2; System.out.println( "x1=x2 && y1< y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2 - (Math.abs(Math.sin(angle)) * d); } else { System.out.println( "x1=x2 && y1 =y2 | x2= " + x2 + " | cos(angle) = " + Math.cos(angle) + " | d = " + d); xy[0] = x2; System.out.println( "x1=x2 && y1 =y2 | x2= " + x2 + " | sin(angle) = " + Math.sin(angle) + " | d = " + d); xy[1] = y2; } } System.out.println(" X1 = " + x1 + " | X2 = " + x2 + " | Y1 = " + y1 + " | Y2 = " + y2 + " | X target = " + xy[0] + " | Y target = " + xy[1]); System.out.println(" "); System.out.println("--------------------------------^^^^----------------------------------------"); // } else { // if (y2 > y1) { // System.out.println("(x1 - x2) == 0 | X1 = " + x1 + " | X2 = " + x2 + " | Y1 = " + y1 + " | Y2 = " + y2 + " | X target = " + x1 + " | Y target = " + (y2 + ((y2 - y1) / 12))); // xy[0] = (x2); // xy[1] = y2 + ((y2 - y1) / 12); // } else { // System.out.println("(x1 - x2) == 0 | X1 = " + x1 + " | X2 = " + x2 + " | Y1 = " + y1 + " | Y2 = " + y2 + " | X target = " + x1 + " | Y target = " + (y2 - ((y2 - y1) / 12))); // xy[0] = (x2); // xy[1] = y2 - ((y2 - y1 )/ 12); // } // } return xy; }