List of usage examples for java.lang Math toRadians
public static double toRadians(double angdeg)
From source file:Main.java
/** * Computes the bearing in degrees between two points on Earth. * //w w w .j a v a 2 s. c o m * @param lat1 Latitude of the first point * @param lon1 Longitude of the first point * @param lat2 Latitude of the second point * @param lon2 Longitude of the second point * @return Bearing between the two points in degrees. A value of 0 means due * north. */ public static double bearing(double lat1, double lon1, double lat2, double lon2) { double lat1Rad = Math.toRadians(lat1); double lat2Rad = Math.toRadians(lat2); double deltaLonRad = Math.toRadians(lon2 - lon1); double y = Math.sin(deltaLonRad) * Math.cos(lat2Rad); double x = Math.cos(lat1Rad) * Math.sin(lat2Rad) - Math.sin(lat1Rad) * Math.cos(lat2Rad) * Math.cos(deltaLonRad); return radToBearing(Math.atan2(y, x)); }
From source file:Main.java
/** * Returns the distance between two given locations in meters. * * @param loc1 First location object//from w ww. jav a 2 s. c o m * @param loc2 Second location object * @return distance between Loc1 & Loc2 in meters. */ public static float getDistance(Location loc1, Location loc2) { double lat1 = loc1.getLatitude(); double lng1 = loc1.getLongitude(); double lat2 = loc2.getLatitude(); double lng2 = loc2.getLongitude(); double earthRad = 6371; //kilometers double dLatitude = Math.toRadians(lat2 - lat1); double dLongitude = Math.toRadians(lng2 - lng1); double a = Math.sin(dLatitude / 2) * Math.sin(dLatitude / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLongitude / 2) * Math.sin(dLongitude / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); float dist = (float) (earthRad * c); dist = dist * MILES_TO_METER_CONVERSION; return dist; }
From source file:Main.java
/** * Gets the relative bearing from one geographical coordinate to another. * * @param latitude1 the latitude of the source point * @param longitude1 the longitude of the source point * @param latitude2 the latitude of the destination point * @param longitude2 the longitude of the destination point * @return the relative bearing from point 1 to point 2, in degrees. The result is guaranteed * to fall in the range 0-360//from w w w .ja v a 2s. c o m */ public static float getBearing(double latitude1, double longitude1, double latitude2, double longitude2) { latitude1 = Math.toRadians(latitude1); longitude1 = Math.toRadians(longitude1); latitude2 = Math.toRadians(latitude2); longitude2 = Math.toRadians(longitude2); double dLon = longitude2 - longitude1; double y = Math.sin(dLon) * Math.cos(latitude2); double x = Math.cos(latitude1) * Math.sin(latitude2) - Math.sin(latitude1) * Math.cos(latitude2) * Math.cos(dLon); double bearing = Math.atan2(y, x); return mod((float) Math.toDegrees(bearing), 360.0f); }
From source file:Main.java
/** * Gets the great circle distance in kilometers between two geographical points, using * the <a href="http://en.wikipedia.org/wiki/Haversine_formula">haversine formula</a>. * * @param latitude1 the latitude of the first point * @param longitude1 the longitude of the first point * @param latitude2 the latitude of the second point * @param longitude2 the longitude of the second point * @return the distance, in kilometers, between the two points */// w w w . j a v a2 s . c o m public static float getDistance(double latitude1, double longitude1, double latitude2, double longitude2) { double dLat = Math.toRadians(latitude2 - latitude1); double dLon = Math.toRadians(longitude2 - longitude1); double lat1 = Math.toRadians(latitude1); double lat2 = Math.toRadians(latitude2); double sqrtHaversineLat = Math.sin(dLat / 2); double sqrtHaversineLon = Math.sin(dLon / 2); double a = sqrtHaversineLat * sqrtHaversineLat + sqrtHaversineLon * sqrtHaversineLon * Math.cos(lat1) * Math.cos(lat2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return (float) (EARTH_RADIUS_KM * c); }
From source file:RotateTransformed.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Ellipse2D e = new Ellipse2D.Double(0, 0, 80, 130); for (double i = 0; i < 360; i += 5) { AffineTransform at = AffineTransform.getTranslateInstance(400 / 2, 400 / 2); at.rotate(Math.toRadians(i)); g2.draw(at.createTransformedShape(e)); }/* w ww . j av a 2s . c o m*/ }
From source file:ImagePanel.java
public void paintComponent(Graphics grp) { Rectangle rect = this.getBounds(); Graphics2D g2d = (Graphics2D) grp; transform.setToTranslation((rect.width - w) / 2, (rect.height - h) / 2); transform.rotate(Math.toRadians(angle), w / 2, h / 2); g2d.drawImage(image, transform, this); }
From source file:org.apache.usergrid.client.QueryTestCase.java
public static float distFrom(float lat1, float lng1, float lat2, float lng2) { double earthRadius = 6371000; //meters double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return (float) (earthRadius * c); }
From source file:Main.java
/** * Calculate the corrected obliquity of the ecliptic. * * @param t number of Julian centuries since J2000. * @return Corrected obliquity in degrees. *//*from ww w . java 2 s .co m*/ private static double obliquityCorrected(final double t) { final double e0 = meanObliquityOfEcliptic(t); final double omega = Math.toRadians(125.04 - 1934.136 * t); return e0 + 0.00256 * Math.cos(omega); }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); String text = "I don't see the problem"; FontMetrics fm = g2d.getFontMetrics(); int x = (getWidth() - fm.stringWidth(text)) / 2; int y = ((getHeight() - fm.getHeight()) / 2) + fm.getDescent(); g2d.setTransform(AffineTransform.getRotateInstance(Math.toRadians(45), getWidth() / 2, getHeight() / 2)); g2d.drawString(text, x, y);/* w ww . j a v a 2 s. c o m*/ g2d.dispose(); }
From source file:com.cloudmade.api.Utils.java
/** * Convert latitude, longitude pair to tile coordinates * //from ww w . j a v a 2 s. c o m * @param latitude * @param longitude * @param zoom * @return Tile coordinates [x, y] */ public static final int[] latlon2tilenums(double latitude, double longitude, int zoom) { int factor = 1 << (zoom - 1); latitude = Math.toRadians(latitude); longitude = Math.toRadians(longitude); double xtile = 1 + longitude / Math.PI; double ytile = 1 - Math.log(Math.tan(latitude) + (1 / Math.cos(latitude))) / Math.PI; return new int[] { (int) (xtile * factor), (int) (ytile * factor) }; }