List of usage examples for java.lang Math toRadians
public static double toRadians(double angdeg)
From source file:org.openhab.binding.mqttitude.internal.MqttitudeConsumer.java
private double calculateDistance(Location location1, Location location2) { float lat1 = location1.getLatitude(); float lng1 = location1.getLongitude(); float lat2 = location2.getLatitude(); float lng2 = location2.getLongitude(); 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)); double earthRadiusKm = 6369; double distKm = earthRadiusKm * c; // return the distance in meters return distKm * 1000; }
From source file:com.evgenyvyaz.cinaytaren.activity.FaceTrackerActivity.java
public static double distance(double lat1, double lon1, double lat2, double lon2) { double dLat = (double) Math.toRadians(lat2 - lat1); double dLon = (double) Math.toRadians(lon2 - lon1); double a = (double) (Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2)); double c = (double) (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))); double d = 6371 * c; return Math.round(d * 1000); }
From source file:org.encuestame.core.util.EnMeUtils.java
/** * Convert degrees cordinates to radians. * @param degreesValue//from w w w. j a v a 2s . c o m * @return */ public static Double convertDegreesToRadians(final double degreesValue) { final Double radiansValue = Math.toRadians(degreesValue); return radiansValue; }
From source file:com.alvermont.terraj.planet.ProjectionParameters.java
/** * Getter for property latitudeRadians./*from www. j av a2 s . com*/ * @return Value of property lat. */ public double getLatitudeRadians() { return Math.toRadians(this.lat); }
From source file:com.qasp.diego.arsp.indice_localFrag.java
public double FormuladHaversine(double lat1, double long1, double lat2, double long2) { final double RAIO_DA_TERRA = 6371; // em Km // Converso/*from w w w . ja va 2 s . c o m*/ double radlat1 = Math.toRadians(lat1); double radlong1 = Math.toRadians(long1); double radlat2 = Math.toRadians(lat2); double radlong2 = Math.toRadians(long2); //Parametros TO DO: BigDecimal? double radlat = radlat2 - radlat1; double radlong = radlong2 - radlong1; // Formula double d = Math.pow(Math.sin(radlat * 0.5), 2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.pow(Math.sin(radlong * 0.5), 2); return 2 * RAIO_DA_TERRA * Math.asin(Math.sqrt(d)); }
From source file:org.deegree.tools.crs.EPSGDBSynchronizer.java
protected void getCodesForProjections(DBCRSStore dbSTore) { try {/*from ww w .j ava2 s. c om*/ // select the EPSG code of all ProjectedCRS's, and their projection projection codes and type PreparedStatement ps = EPSGdbConn.prepareStatement("SELECT coord_ref_sys_code, " + "coord_op_method_code, " + "coord_op_code " + "FROM epsg_coordinatereferencesystem, " + "epsg_coordoperation " + "WHERE coord_ref_sys_kind = 'projected' AND " + "projection_conv_code = coord_op_code"); ResultSet largeRs = ps.executeQuery(); while (largeRs.next()) { int projectedCRSCode = largeRs.getInt(1); int projectionTypeCode = largeRs.getInt(2); int projectionCode = largeRs.getInt(3); ICRS crs = dbSTore.getCRSByCode(new CRSCodeType(String.valueOf(projectedCRSCode), "EPSG")); if (crs != null && (crs instanceof IProjectedCRS)) { // if the projections are of the known types ( Transverse Mercator, Lambert Azimuthal EA, Lambert // Conic Conformal, Stereographic alternative or Stereografic azimuthal ) if (projectionTypeCode == 9807 || projectionTypeCode == 9820 || projectionTypeCode == 9801 || projectionTypeCode == 9809 || projectionTypeCode == 9810) { IProjectedCRS projectedCRS = (IProjectedCRS) crs; IProjection projection = projectedCRS.getProjection(); ps = EPSGdbConn.prepareStatement( "SELECT parameter_value, parameter_code FROM epsg_coordoperationparamvalue " + "WHERE coord_op_code = " + projectionCode); ResultSet rs = ps.executeQuery(); // initialize the specific projection attributes double latNatOrigin = Double.NaN; double longNatOrigin = Double.NaN; double scale = Double.NaN; double falseEasting = Double.NaN; double falseNorthing = Double.NaN; // get the attributes values according to their codes while (rs.next()) { if (rs.getInt(2) == 8801) latNatOrigin = rs.getDouble(1); else if (rs.getInt(2) == 8802) longNatOrigin = rs.getDouble(1); else if (rs.getInt(2) == 8805) scale = rs.getDouble(1); else if (rs.getInt(2) == 8806) falseEasting = rs.getDouble(1); else if (rs.getInt(2) == 8807) falseNorthing = rs.getDouble(1); } // // TRANSVERSE MERCATOR // if (projectionTypeCode == 9807 && (projection instanceof TransverseMercator)) { TransverseMercator tmProjection = (TransverseMercator) projection; // compare the CRS database projection attributes with the attributes from the EPSG database if (java.lang.Math .abs(tmProjection.getNaturalOrigin().y - Math.toRadians(latNatOrigin)) < 1e-7 && java.lang.Math.abs(tmProjection.getNaturalOrigin().x - Math.toRadians(longNatOrigin)) < 1e-7 && tmProjection.getScale() == scale && tmProjection.getFalseEasting() == falseEasting && tmProjection.getFalseNorthing() == falseNorthing) { LOG.info( "The two Transverse Mercator projections attributes match. Updating the projection with Code: " + projectionCode); // do the UPDATE // int pInternalID = dbProvider.getInternalID( tmProjection ); // dbProvider.setCode( pInternalID, String.valueOf( projectionCode ) ); } } // // LAMBERT AZIMUTHAL EQUAL AREA // if (projectionTypeCode == 9820 && (projection instanceof LambertAzimuthalEqualArea)) { LambertAzimuthalEqualArea laeaProjection = (LambertAzimuthalEqualArea) projection; // compare the CRS database projection attributes with the attributes from the EPSG database if (java.lang.Math .abs(laeaProjection.getNaturalOrigin().y - Math.toRadians(latNatOrigin)) < 1e-7 && java.lang.Math.abs(laeaProjection.getNaturalOrigin().x - Math.toRadians(longNatOrigin)) < 1e-7 && laeaProjection.getFalseEasting() == falseEasting && // no scale comparison since no // scale attribute laeaProjection.getFalseNorthing() == falseNorthing) { LOG.info( "The two Lambert Azimuthal projections attributes match. Updating the projection with Code: " + projectionCode); // do the UPDATE // int pInternalID = dbProvider.getInternalID( laeaProjection ); // dbProvider.setCode( pInternalID, String.valueOf( projectionCode ) ); } } // // LAMBERT CONIC CONFORMAL // if (projectionTypeCode == 9801 && (projection instanceof LambertConformalConic)) { LambertConformalConic lccProjection = (LambertConformalConic) projection; // compare the CRS database projection attributes with the attributes from the EPSG database if (java.lang.Math .abs(lccProjection.getNaturalOrigin().y - Math.toRadians(latNatOrigin)) < 1e-7 && java.lang.Math.abs(lccProjection.getNaturalOrigin().x - Math.toRadians(longNatOrigin)) < 1e-7 && lccProjection.getScale() == scale && lccProjection.getFalseEasting() == falseEasting && lccProjection.getFalseNorthing() == falseNorthing) { LOG.info( "The two Lambert Conic Conformal projections attributes match. Updating the projection with the Code " + projectionCode); // do the UPDATE // int pInternalID = dbProvider.getInternalID( lccProjection ); // dbProvider.setCode( pInternalID, String.valueOf( projectionCode ) ); } } // // STEREOGRAPHIC // if (projectionTypeCode == 9809 || projectionTypeCode == 9810) { if (projection instanceof StereographicAlternative) { StereographicAlternative salProjection = (StereographicAlternative) projection; // compare the CRS database projection attributes with the attributes from the EPSG // database if (java.lang.Math.abs( salProjection.getNaturalOrigin().y - Math.toRadians(latNatOrigin)) < 0.00001 && java.lang.Math.abs(salProjection.getNaturalOrigin().x - Math.toRadians(longNatOrigin)) < 0.00001 && salProjection.getScale() == scale && salProjection.getFalseEasting() == falseEasting && salProjection.getFalseNorthing() == falseNorthing) { LOG.info( "The two StereographicAlternative projections attributes match. Updating the projection with the Code: " + projectionCode); // do the UPDATE // int pInternalID = dbProvider.getInternalID( salProjection ); // dbProvider.setCode( pInternalID, String.valueOf( projectionCode ) ); } } else if (projection instanceof StereographicAzimuthal) { StereographicAzimuthal sazProjection = (StereographicAzimuthal) projection; // compare the CRS database projection attributes with the attributes from the EPSG // database if (java.lang.Math.abs( sazProjection.getNaturalOrigin().y - Math.toRadians(latNatOrigin)) < 0.00001 && java.lang.Math.abs(sazProjection.getNaturalOrigin().x - Math.toRadians(longNatOrigin)) < 0.00001 && sazProjection.getScale() == scale && sazProjection.getFalseEasting() == falseEasting && sazProjection.getFalseNorthing() == falseNorthing) { LOG.info( "The two StereographicAzimuthal projections attributes match. Updating the projectio with the Code: " + projectionCode); // do the UPDATE // int pInternalID = dbProvider.getInternalID( sazProjection ); // dbProvider.setCode( pInternalID, String.valueOf( projectionCode ) ); } } } } } } } catch (SQLException e) { LOG.error(e.getMessage()); } }
From source file:com.georgeme.Act_Circle.java
public double CalculationByDistance(LatLng StartP, LatLng EndP) { int Radius = 6371;// radius of earth in Km double lat1 = StartP.latitude; double lat2 = EndP.latitude; double lon1 = StartP.longitude; double lon2 = EndP.longitude; double dLat = Math.toRadians(lat2 - lat1); double dLon = Math.toRadians(lon2 - lon1); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2); double c = 2 * Math.asin(Math.sqrt(a)); return Radius * c * 1000; }
From source file:com.samebits.beacon.locator.ui.view.RadarScanView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int center = getWidth() / 2; int radius = center - 8; // Draw the rings final Paint gridPaint = mGridPaint; canvas.drawCircle(center, center, radius, gridPaint); canvas.drawCircle(center, center, radius * 3 / 4, gridPaint); canvas.drawCircle(center, center, radius >> 1, gridPaint); canvas.drawCircle(center, center, radius >> 2, gridPaint); int blipRadius = (int) (mDistanceRatio * radius); final long now = SystemClock.uptimeMillis(); if (mSweepTime > 0) { // Draw the sweep. Radius is determined by how long ago it started long sweepDifference = now - mSweepTime; if (sweepDifference < 512L) { int sweepRadius = (int) (((radius + 6) * sweepDifference) >> 9); canvas.drawCircle(center, center, sweepRadius, mSweepPaint0); canvas.drawCircle(center, center, sweepRadius - 2, mSweepPaint1); canvas.drawCircle(center, center, sweepRadius - 4, mSweepPaint2); // Note when the sweep has passed the blip boolean before = sweepRadius < blipRadius; if (!before && mSweepBefore) { mSweepBefore = false;// w w w .j av a2s .c om mBlipTime = now; } } else { mSweepTime = now + 1000; mSweepBefore = true; } postInvalidate(); } // Draw horizontal and vertical lines canvas.drawLine(center, center - (radius >> 2) + 6, center, center - radius - 6, gridPaint); canvas.drawLine(center, center + (radius >> 2) - 6, center, center + radius + 6, gridPaint); canvas.drawLine(center - (radius >> 2) + 6, center, center - radius - 6, center, gridPaint); canvas.drawLine(center + (radius >> 2) - 6, center, center + radius + 6, center, gridPaint); // Draw X in the center of the screen canvas.drawLine(center - 4, center - 4, center + 4, center + 4, gridPaint); canvas.drawLine(center - 4, center + 4, center + 4, center - 4, gridPaint); if (mHaveDetected) { // Draw the blip. Alpha is based on how long ago the sweep crossed the blip long blipDifference = now - mBlipTime; gridPaint.setAlpha(255 - (int) ((128 * blipDifference) >> 10)); double bearingToTarget = mLast_bearing; double drawingAngle = Math.toRadians(bearingToTarget) - (Math.PI / 2); float cos = (float) Math.cos(drawingAngle); float sin = (float) Math.sin(drawingAngle); addText(canvas, getRatioDistanceText(0.25f), center, center + (radius >> 2)); addText(canvas, getRatioDistanceText(0.5f), center, center + (radius >> 1)); addText(canvas, getRatioDistanceText(0.75f), center, center + radius * 3 / 4); addText(canvas, getRatioDistanceText(1.0f), center, center + radius); for (Map.Entry<String, DetectedBeacon> entry : mBeacons.entrySet()) { //String key = entry.getKey(); DetectedBeacon dBeacon = entry.getValue(); System.out.println("value: " + dBeacon); // drawing the beacon if (((System.currentTimeMillis() - dBeacon.getTimeLastSeen()) / 1000 < 5)) { canvas.drawBitmap(mBlip, center + (cos * distanceToPix(dBeacon.getDistance())) - 8, center + (sin * distanceToPix(dBeacon.getDistance())) - 8, gridPaint); } } gridPaint.setAlpha(255); } }
From source file:eu.hansolo.tilesfx.tools.Location.java
public double calcDistanceInMeter(final double LAT_1, final double LON_1, final double LAT_2, final double LON_2) { final double EARTH_RADIUS = 6_371_000; // m final double LAT_1_RADIANS = Math.toRadians(LAT_1); final double LAT_2_RADIANS = Math.toRadians(LAT_2); final double DELTA_LAT_RADIANS = Math.toRadians(LAT_2 - LAT_1); final double DELTA_LON_RADIANS = Math.toRadians(LON_2 - LON_1); final double A = Math.sin(DELTA_LAT_RADIANS * 0.5) * Math.sin(DELTA_LAT_RADIANS * 0.5) + Math.cos(LAT_1_RADIANS) * Math.cos(LAT_2_RADIANS) * Math.sin(DELTA_LON_RADIANS * 0.5) * Math.sin(DELTA_LON_RADIANS * 0.5); final double C = 2 * Math.atan2(Math.sqrt(A), Math.sqrt(1 - A)); final double DISTANCE = EARTH_RADIUS * C; return DISTANCE; }
From source file:org.kalypsodeegree_impl.graphics.displayelements.LabelFactory.java
private Label[] createPointLabels(final Feature feature, final String caption, final GM_Point geometry, final java.awt.Font font, final Color color, final LineMetrics metrics, final Dimension bounds) throws FilterEvaluationException { // get screen coordinates final int[] coords = LabelUtils.calcScreenCoordinates(m_projection, geometry); final int x = coords[0]; final int y = coords[1]; final PointPlacement pPlacement = getPointPlacement(); final double rotation = getRotation(pPlacement, feature); final double[] anchorPoint = getAnchor(pPlacement, feature, DEFAULT_POINT_ANCHOR); final double[] displacement = getDisplacement(pPlacement, feature); final Label label = createLabel(caption, font, color, metrics, feature, x, y, bounds, Math.toRadians(rotation), anchorPoint, displacement); return new Label[] { label }; }