List of usage examples for java.lang Math acos
public static double acos(double a)
From source file:Main.java
/** * Reconvert back to lat/lon.// w ww . java2 s. c om * * @param x x value * @param y y value * @param z z value * * @return point in lat,lon */ private static double[] cartesian2latlon(double x, double y, double z) { return new double[] { Math.atan(y / x), Math.acos(z / EARTH_RADIUS) }; }
From source file:Main.java
static public final float acos(float value) { return (float) Math.acos(value); }
From source file:peasy.InterpolationUtil.java
static public Rotation slerp(final Rotation a, final Rotation b, final double t) { final double a0 = a.getQ0(), a1 = a.getQ1(), a2 = a.getQ2(), a3 = a.getQ3(); double b0 = b.getQ0(), b1 = b.getQ1(), b2 = b.getQ2(), b3 = b.getQ3(); double cosTheta = a0 * b0 + a1 * b1 + a2 * b2 + a3 * b3; if (cosTheta < 0) { b0 = -b0;/*from w w w .j a v a2s . co m*/ b1 = -b1; b2 = -b2; b3 = -b3; cosTheta = -cosTheta; } final double theta = Math.acos(cosTheta); final double sinTheta = Math.sqrt(1.0 - cosTheta * cosTheta); double w1, w2; if (sinTheta > 0.001) { w1 = Math.sin((1.0 - t) * theta) / sinTheta; w2 = Math.sin(t * theta) / sinTheta; } else { w1 = 1.0 - t; w2 = t; } return new Rotation(w1 * a0 + w2 * b0, w1 * a1 + w2 * b1, w1 * a2 + w2 * b2, w1 * a3 + w2 * b3, true); }
From source file:Main.java
/** * Get the radian between current line(determined by point A and B) and horizontal line. * * @param A point A/*from w w w .ja va 2 s. c om*/ * @param B point B * @return the radian */ public static float getRadian(Point A, Point B) { float lenA = B.x - A.x; float lenB = B.y - A.y; float lenC = (float) Math.sqrt(lenA * lenA + lenB * lenB); float radian = (float) Math.acos(lenA / lenC); radian = radian * (B.y < A.y ? -1 : 1); return radian; }
From source file:Main.java
/** * <p>This routine calculates the distance between two points (given the * latitude/longitude of those points). It is being used to calculate * the distance between two locations.</p> * <p/>// w w w . j a v a 2 s . c o m * <p>Definitions: South latitudes are negative, east longitudes are positive</p> * <p/> * <p>Passed to function: * <ul> * <li>lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees)</li> * <li>lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees)</li> * <li>unit = the unit you desire for results * <ul> * <li>where: 'M' is statute miles</li> * <li>'K' is kilometers (default) </li> * <li>'N' is nautical miles</li> * </ul> * </li> * </ul> * Worldwide cities and other features databases with latitude longitude * are available at http://www.geodatasource.com</p> * <p/> * <p>For enquiries, please contact sales@geodatasource.com</p> * <p>Official Web site: http://www.geodatasource.com</p> * <p>GeoDataSource.com (C) All Rights Reserved 2013</p> * * @param lat1 - latitude point 1 * @param lon1 - longitude point 1 * @param lat2 - latitude point 2 * @param lon2 - longitude point 2 * @param unit - unit of measure (M, K, N) * @return the distance between the two points */ public static final double distance(double lat1, double lon1, double lat2, double lon2, char unit) { double theta = lon1 - lon2; double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta)); dist = Math.acos(dist); dist = rad2deg(dist); dist = dist * 60 * 1.1515; if (unit == 'K') { dist = dist * 1.609344; } else if (unit == 'N') { dist = dist * 0.8684; } return (dist); }
From source file:Main.java
/************************************************************************************************************************************ This routine calculates the distance between two points (given the latitude/longitude of those points). It is being used to calculate the distance between two locations/* ww w . j a v a 2 s. com*/ Definitions: South latitudes are negative, east longitudes are positive Passed to function: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) unit = the unit you desire for results where: 'M' is statute miles 'K' is kilometers (default) 'N' is nautical miles *************************************************************************************************************************************/ public static double Distance(double lat1, double lon1, double lat2, double lon2, String unit) { double radius = 6371.0090667; lat1 = lat1 * Math.PI / 180.0; lon1 = lon1 * Math.PI / 180.0; lat2 = lat2 * Math.PI / 180.0; lon2 = lon2 * Math.PI / 180.0; double dlon = lon1 - lon2; double distance = Math .acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(dlon)) * radius; if (unit == "K") { return distance; } else if (unit == "M") { return (distance * 0.621371192); } else if (unit == "F") { //FEET return ((distance * 0.621371192) * 5280); } else if (unit == "N") { return (distance * 0.539956803); } else { return 0; } }
From source file:Main.java
static double distanceFromArc(double dA, double dB, double dAB) { // In spherical trinagle ABC // a is length of arc BC, that is dB // b is length of arc AC, that is dA // c is length of arc AB, that is dAB // We rename parameters so following formulas are more clear: double a = dB; double b = dA; double c = dAB; // First, we calculate angles alpha and beta in spherical triangle ABC // and based on them we decide how to calculate the distance: if (Math.sin(b) * Math.sin(c) == 0.0 || Math.sin(c) * Math.sin(a) == 0.0) { // It probably means that one of distance is n*pi, which gives around 20000km for n = 1, // unlikely for Denmark, so we should be fine. return -1.0; }/* w w w . j a v a 2s . co m*/ double alpha = Math.acos((Math.cos(a) - Math.cos(b) * Math.cos(c)) / (Math.sin(b) * Math.sin(c))); double beta = Math.acos((Math.cos(b) - Math.cos(c) * Math.cos(a)) / (Math.sin(c) * Math.sin(a))); // It is possible that both sinuses are too small so we can get nan when dividing with them if (Double.isNaN(alpha) || Double.isNaN(beta)) { // double cosa = cos(a); // double cosbc = cos(b) * cos(c); // double minus1 = cosa - cosbc; // double sinbc = sin(b) * sin(c); // double div1 = minus1 / sinbc; // // double cosb = cos(b); // double cosca = cos(a) * cos(c); // double minus2 = cosb - cosca; // double sinca = sin(a) * sin(c); // double div2 = minus2 / sinca; return -1.0; } // If alpha or beta are zero or pi, it means that C is on the same circle as arc AB, // we just need to figure out if it is between AB: if (alpha == 0.0 || beta == 0.0) { return (dA + dB > dAB) ? Math.min(dA, dB) : 0.0; } // If alpha is obtuse and beta is acute angle, then // distance is equal to dA: if (alpha > Math.PI / 2 && beta < Math.PI / 2) return dA; // Analogously, if beta is obtuse and alpha is acute angle, then // distance is equal to dB: if (beta > Math.PI / 2 && alpha < Math.PI / 2) return dB; // If both alpha and beta are acute or both obtuse or one of them (or both) are right, // distance is the height of the spherical triangle ABC: // Again, unlikely, since it would render at least pi/2*EARTH_RADIUS_IN_METERS, which is too much. if (Math.cos(a) == 0.0) return -1; double x = Math.atan(-1.0 / Math.tan(c) + (Math.cos(b) / (Math.cos(a) * Math.sin(c)))); // Similar to previous edge cases... if (Math.cos(x) == 0.0) return -1.0; return Math.acos(Math.cos(a) / Math.cos(x)); }
From source file:net.gtaun.shoebill.data.Velocity.java
public float angle2d() { return (float) Math.acos(getX() / Math.abs(speed2d())); }
From source file:playground.vsp.analysis.modules.ptTripAnalysis.utils.GeoCalculator.java
public static double angleBeetween2Straights(Tuple<Coord, Coord> one, Tuple<Coord, Coord> two) { double value; Vector2D o = new Vector2D(one.getSecond().getX() - one.getFirst().getX(), one.getSecond().getY() - one.getFirst().getY()); Vector2D t = new Vector2D(two.getSecond().getX() - two.getFirst().getX(), two.getSecond().getY() - two.getFirst().getY()); value = (o.scalarProduct(t) / (o.absolut() * t.absolut())); if (value > 1) { if ((value - 1.0) < (1.0 / 1000.0)) { return Math.acos(1); } else {//from w ww . j a v a 2s . c o m throw new RuntimeException("acos not defined for: " + value); } } else if (value < -1) { if ((value + 1.0) > -(1.0 / 1000.0)) { return Math.acos(-1); } else { throw new RuntimeException("acos not defined for: " + value); } } else { return Math.acos(value); } }
From source file:net.gtaun.shoebill.data.Velocity.java
public float angleZ() { return (float) Math.acos(getZ() / Math.abs(speed3d())); }