List of usage examples for java.lang Math toRadians
public static double toRadians(double angdeg)
From source file:ExtendedGeneralPath.java
/** * This constructs an unrotated Arc2D from the SVG specification of an * Elliptical arc. To get the final arc you need to apply a rotation * transform such as://from w w w. j a va2 s . c o m * * AffineTransform.getRotateInstance * (angle, arc.getX()+arc.getWidth()/2, arc.getY()+arc.getHeight()/2); */ public static Arc2D computeArc(double x0, double y0, double rx, double ry, double angle, boolean largeArcFlag, boolean sweepFlag, double x, double y) { // // Elliptical arc implementation based on the SVG specification notes // // Compute the half distance between the current and the final point double dx2 = (x0 - x) / 2.0; double dy2 = (y0 - y) / 2.0; // Convert angle from degrees to radians angle = Math.toRadians(angle % 360.0); double cosAngle = Math.cos(angle); double sinAngle = Math.sin(angle); // // Step 1 : Compute (x1, y1) // double x1 = (cosAngle * dx2 + sinAngle * dy2); double y1 = (-sinAngle * dx2 + cosAngle * dy2); // Ensure radii are large enough rx = Math.abs(rx); ry = Math.abs(ry); double Prx = rx * rx; double Pry = ry * ry; double Px1 = x1 * x1; double Py1 = y1 * y1; // check that radii are large enough double radiiCheck = Px1 / Prx + Py1 / Pry; if (radiiCheck > 1) { rx = Math.sqrt(radiiCheck) * rx; ry = Math.sqrt(radiiCheck) * ry; Prx = rx * rx; Pry = ry * ry; } // // Step 2 : Compute (cx1, cy1) // double sign = (largeArcFlag == sweepFlag) ? -1 : 1; double sq = ((Prx * Pry) - (Prx * Py1) - (Pry * Px1)) / ((Prx * Py1) + (Pry * Px1)); sq = (sq < 0) ? 0 : sq; double coef = (sign * Math.sqrt(sq)); double cx1 = coef * ((rx * y1) / ry); double cy1 = coef * -((ry * x1) / rx); // // Step 3 : Compute (cx, cy) from (cx1, cy1) // double sx2 = (x0 + x) / 2.0; double sy2 = (y0 + y) / 2.0; double cx = sx2 + (cosAngle * cx1 - sinAngle * cy1); double cy = sy2 + (sinAngle * cx1 + cosAngle * cy1); // // Step 4 : Compute the angleStart (angle1) and the angleExtent (dangle) // double ux = (x1 - cx1) / rx; double uy = (y1 - cy1) / ry; double vx = (-x1 - cx1) / rx; double vy = (-y1 - cy1) / ry; double p, n; // Compute the angle start n = Math.sqrt((ux * ux) + (uy * uy)); p = ux; // (1 * ux) + (0 * uy) sign = (uy < 0) ? -1.0 : 1.0; double angleStart = Math.toDegrees(sign * Math.acos(p / n)); // Compute the angle extent n = Math.sqrt((ux * ux + uy * uy) * (vx * vx + vy * vy)); p = ux * vx + uy * vy; sign = (ux * vy - uy * vx < 0) ? -1.0 : 1.0; double angleExtent = Math.toDegrees(sign * Math.acos(p / n)); if (!sweepFlag && angleExtent > 0) { angleExtent -= 360f; } else if (sweepFlag && angleExtent < 0) { angleExtent += 360f; } angleExtent %= 360f; angleStart %= 360f; // // We can now build the resulting Arc2D in double precision // Arc2D.Double arc = new Arc2D.Double(); arc.x = cx - rx; arc.y = cy - ry; arc.width = rx * 2.0; arc.height = ry * 2.0; arc.start = -angleStart; arc.extent = -angleExtent; return arc; }
From source file:com.alvermont.terraj.planet.project.SquareProjection.java
/** * Carry out the projection//ww w . j a v a 2 s . c o m */ public void project() { setcolours(); final int width = getParameters().getProjectionParameters().getWidth(); final int height = getParameters().getProjectionParameters().getHeight(); final double lat = getParameters().getProjectionParameters().getLatitudeRadians(); final double lon = getParameters().getProjectionParameters().getLongitudeRadians(); final double scale = getParameters().getProjectionParameters().getScale(); final double hgrid = getParameters().getProjectionParameters().getHgrid(); final double vgrid = getParameters().getProjectionParameters().getVgrid(); final boolean doShade = getParameters().getProjectionParameters().isDoShade(); depth = (3 * ((int) (log2(scale * height)))) + 6; cacheParameters(); colours = new short[width][height]; shades = new short[width][height]; double y; double scale1; double theta1; double cos2; int k; int i; int j; k = (int) ((lat * width * scale) / Math.PI); progress.progressStart(height, "Generating Terrain"); for (j = 0; j < height; ++j) { progress.progressStep(j); y = ((2.0 * (j - k)) - height) / width / scale * Math.PI; if (Math.abs(y) >= (0.5 * Math.PI)) { for (i = 0; i < width; ++i) { colours[i][j] = backgroundColour; if (doShade) { shades[i][j] = 255; } } } else { cos2 = Math.cos(y); if (cos2 > 0.0) { scale1 = (scale * width) / height / cos2 / Math.PI; depth = (3 * ((int) (log2(scale1 * height)))) + 3; for (i = 0; i < width; ++i) { theta1 = lon - (0.5 * Math.PI) + ((Math.PI * ((2.0 * i) - width)) / width / scale); colours[i][j] = (short) planet0(Math.cos(theta1) * cos2, Math.sin(y), -Math.sin(theta1) * cos2); if (doShade) { shades[i][j] = shade; } } } } } progress.progressComplete("Terrain Generated"); if (hgrid != 0.0) { /* draw horizontal gridlines */ for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid) ; for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) { y = Math.toRadians(theta1); j = (height / 2) + (int) ((0.5 * y * width * scale) / Math.PI) + k; if ((j >= 0) && (j < height)) { for (i = 0; i < width; ++i) colours[i][j] = BLACK; } } } if (vgrid != 0.0) { /* draw vertical gridlines */ for (theta1 = 0.0; theta1 > -360.0; theta1 -= vgrid) ; for (theta1 = theta1; theta1 < 360.0; theta1 += vgrid) { i = (int) (0.5 * width * (1.0 + ((scale * (Math.toRadians(theta1) - lon)) / Math.PI))); if ((i >= 0) && (i < width)) { for (j = Math.max(0, (height / 2) - (int) ((0.25 * Math.PI * width * scale) / Math.PI) + k); j < Math.min( height, (height / 2) + (int) ((0.25 * Math.PI * width * scale) / Math.PI) + k); ++j) { colours[i][j] = BLACK; } } } } if (doShade) { smoothshades(); } doOutlining(); }
From source file:com.example.map.BasicMapActivity.java
@Override protected void onResume() { super.onResume(); //retrieve fragment mMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_container); if (mMapFragment != null) { mMap = mMapFragment.getMap();// w ww.j av a 2s .com mMap.setMyLocationEnabled(true); mMap.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater())); LatLngBounds.Builder builder = new LatLngBounds.Builder(); if (markers == null) { markers = new HashMap<Integer, Marker>(); markerContacts = new HashMap<Marker, Contact>(); for (Contact place : mContacts) { Marker marker = mMap.addMarker(new MarkerOptions() .position(new LatLng(place.getLat(), place.getLon())).title(place.getName()) .snippet(place.getAddress()) .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))); markers.put(place.getId(), marker); markerContacts.put(marker, place); builder.include(marker.getPosition()); } LatLngBounds bounds = builder.build(); cu = CameraUpdateFactory.newLatLngBounds(bounds, 20); boolean post = mMapFragment.getView().post(new Runnable() { @Override public void run() { mMap.animateCamera(cu); me = mMap.addMarker(new MarkerOptions().position(mMap.getCameraPosition().target) .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE))); } }); } mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) { Contact place = markerContacts.get(marker); if (place != null) { marker.setSnippet(place.getAddress()); marker.showInfoWindow(); return true; } return false; } }); mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() { @Override public void onCameraChange(final CameraPosition cameraPosition) { me.setPosition(cameraPosition.target); double lat = cameraPosition.target.latitude; double lon = cameraPosition.target.longitude; mContacts = mDb.getContactByDist(lat, lon, 5); for (Marker marker : markers.values()) { marker.setVisible(false); } //add new markers within set distance for (Contact place : mContacts) { double lat2 = place.getLat(); double lon2 = place.getLon(); double distance = hdistance(Math.toRadians(lat), Math.toRadians(lon), Math.toRadians(lat2), Math.toRadians(lon2)); Marker marker = markers.get(place.getId()); marker.setSnippet(DIST_FORMAT.format(distance) + " km away"); marker.setVisible(true); } if (mContacts.size() > 0) markers.get(mContacts.get(0).getId()).showInfoWindow(); } }); //.icon(BitmapDescriptorFactory.fromResource(R.drawable.android_platform))); } }
From source file:com.alvermont.terraj.planet.project.GnomonicProjection.java
/** * Carry out the projection/*w w w . java 2 s .c o m*/ */ public void project() { setcolours(); final int width = getParameters().getProjectionParameters().getWidth(); final int height = getParameters().getProjectionParameters().getHeight(); final double lat = getParameters().getProjectionParameters().getLatitudeRadians(); final double lon = getParameters().getProjectionParameters().getLongitudeRadians(); final double scale = getParameters().getProjectionParameters().getScale(); final double hgrid = getParameters().getProjectionParameters().getHgrid(); final double vgrid = getParameters().getProjectionParameters().getVgrid(); final boolean doShade = getParameters().getProjectionParameters().isDoShade(); cacheParameters(); colours = new short[width][height]; shades = new short[width][height]; final double sla = Math.sin(lat); final double cla = Math.cos(lat); final double slo = Math.sin(lon); final double clo = Math.cos(lon); depth = (3 * ((int) (log2(scale * height)))) + 6; double x; double y; double z; double x1; double y1; double z1; double zz; double theta1; double theta2; double ymin; double ymax; int i; int j; ymin = 2.0; ymax = -2.0; progress.progressStart(height, "Generating Terrain"); for (j = 0; j < height; ++j) { progress.progressStep(j); for (i = 0; i < width; ++i) { x = ((2.0 * i) - width) / height / scale; y = ((2.0 * j) - height) / height / scale; zz = Math.sqrt(1.0 / (1.0 + (x * x) + (y * y))); x = x * zz; y = y * zz; z = Math.sqrt(1.0 - (x * x) - (y * y)); x1 = (clo * x) + (slo * sla * y) + (slo * cla * z); y1 = (cla * y) - (sla * z); z1 = (-slo * x) + (clo * sla * y) + (clo * cla * z); if (y1 < ymin) { ymin = y1; } if (y1 > ymax) { ymax = y1; } colours[i][j] = (short) planet0(x1, y1, z1); if (doShade) { shades[i][j] = shade; } } } progress.progressComplete("Terrain Generated"); if (hgrid != 0.0) { /* draw horizontal gridlines */ for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid) ; for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) { y = Math.sin(Math.toRadians(theta1)); if ((ymin <= y) && (y <= ymax)) { zz = Math.sqrt(1 - (y * y)); for (theta2 = -Math.PI; theta2 < Math.PI; theta2 += (0.5 / width / scale)) { x = Math.sin(theta2) * zz; z = Math.cos(theta2) * zz; x1 = (clo * x) - (slo * z); y1 = (slo * sla * x) + (cla * y) + (clo * sla * z); z1 = (slo * cla * x) - (sla * y) + (clo * cla * z); if (z1 != 0.0) { i = (int) (0.5 * (((height * scale * x1) / z1) + width)); j = (int) (0.5 * (((height * scale * y1) / z1) + height)); if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) { colours[i][j] = BLACK; } } } } } } if (vgrid != 0.0) { /* draw vertical gridlines */ for (theta2 = -Math.PI; theta2 < Math.PI; theta2 += (0.5 / width / scale)) { y = Math.sin(theta2); if ((ymin <= y) && (y <= ymax)) { for (theta1 = 0.0; theta1 < 360.0; theta1 += vgrid) { x = Math.sin(Math.toRadians(theta1)) * Math.cos(theta2); z = Math.cos(Math.toRadians(theta1)) * Math.cos(theta2); x1 = (clo * x) - (slo * z); y1 = (slo * sla * x) + (cla * y) + (clo * sla * z); z1 = (slo * cla * x) - (sla * y) + (clo * cla * z); if (z1 != 0.0) { i = (int) (0.5 * (((height * scale * x1) / z1) + width)); j = (int) (0.5 * (((height * scale * y1) / z1) + height)); if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) { colours[i][j] = BLACK; } } } } } } if (doShade) { smoothshades(); } doOutlining(); }
From source file:ddf.catalog.transformer.OverlayMetacardTransformer.java
private static Vector scaleByLatitude(Vector v, double lat) { double lon = v.get(0) * Math.cos(Math.toRadians(lat)); return new BasicVector(new double[] { lon, v.get(1) }); }
From source file:org.interpss.mapper.bean.aclf.AclfBean2NetMapper.java
/** * map the AclfBusBean object to an AclfBus object and added the AclfBus object * into the AclfNet// w w w .j av a 2 s. co m * * @param busBean AclfBusBean object to be mapped * @param aclfNet AclfNetwork object */ private void mapBusBean(AclfBusBean busBean, AclfNetwork aclfNet) throws InterpssException { AclfBus bus = CoreObjectFactory.createAclfBus(busBean.id, aclfNet); bus.setNumber(busBean.number); bus.setName(busBean.name); int status = busBean.status; if (status == 0) bus.setStatus(false); else bus.setStatus(true); bus.setVLimit(new LimitType(busBean.vmax, busBean.vmin)); Area area = CoreObjectFactory.createArea(busBean.area, aclfNet); area.setName(busBean.areaName); bus.setArea(area); Zone zone = CoreObjectFactory.createZone(busBean.zone, aclfNet); zone.setName(busBean.zoneName); bus.setZone(zone); bus.setBaseVoltage(busBean.base_v * 1000); bus.setVoltage(busBean.v_mag, Math.toRadians(busBean.v_ang)); if (busBean.gen != null) { bus.setGenP(busBean.gen.re); bus.setGenQ(busBean.gen.im); } if (busBean.gen_code != null) { if (busBean.gen_code == AclfBusBean.GenCode.PQ) { bus.setGenCode(AclfGenCode.GEN_PQ); /*AclfPQGenBus pqBus = bus.toPQBus(); if(busBean.gen != null){ pqBus.setGen(busBean.gen.toComplex()); }*/ } else if (busBean.gen_code == AclfBusBean.GenCode.PV) { bus.setGenCode(AclfGenCode.GEN_PV); AclfPVGenBus pvBus = bus.toPVBus(); /*if(busBean.gen != null) pvBus.setGenP(busBean.gen.re);*/ pvBus.setDesiredVoltMag(busBean.vDesired_mag); } else if (busBean.gen_code == AclfBusBean.GenCode.Swing) { bus.setGenCode(AclfGenCode.SWING); AclfSwingBus swingBus = bus.toSwingBus(); swingBus.setDesiredVoltMag(busBean.vDesired_mag); swingBus.setDesiredVoltAngDeg(Math.toRadians(busBean.vDesired_ang)); } else { bus.setGenCode(AclfGenCode.NON_GEN); /*bus.setVoltageMag(busBean.v_mag); bus.setVoltageAng(Math.toRadians(busBean.v_ang));*/ } //bus.setDesiredVoltMag(busBean.vDesired_mag); //bus.setDesiredVoltAng(busBean.vDesired_ang); bus.setPGenLimit(new LimitType(busBean.pmax, busBean.pmin)); bus.setQGenLimit(new LimitType(busBean.qmax, busBean.qmin)); String remoteBusId = busBean.remoteVControlBusId; if (!remoteBusId.equals("")) { RemoteQBus reQBus; try { reQBus = CoreObjectFactory.createRemoteQBus(bus, RemoteQControlType.BUS_VOLTAGE, remoteBusId); reQBus.setAccFactor(0.5); } catch (InterpssException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } if (busBean.load_code != null) { bus.setLoadCode(busBean.load_code == AclfBusBean.LoadCode.ConstP ? AclfLoadCode.CONST_P : (busBean.load_code == AclfBusBean.LoadCode.ConstI ? AclfLoadCode.CONST_I : (busBean.load_code == AclfBusBean.LoadCode.ConstZ ? AclfLoadCode.CONST_Z : AclfLoadCode.NON_LOAD))); if (busBean.load != null) bus.setLoadPQ(new Complex(busBean.load.re, busBean.load.im)); } if (busBean.shunt != null) { bus.setShuntY(new Complex(busBean.shunt.re, busBean.shunt.im)); } // switch shunt if (busBean.switchShunt != null) { SwitchShuntBean ssb = busBean.switchShunt; try { SwitchedShunt ss = CoreObjectFactory.createSwitchedShunt(bus); ss.setVSpecified(ssb.vSpecified); ss.setBInit(ssb.bInit); VarCompensationMode mode = ssb.controlMode == VarCompensatorControlModeBean.Continuous ? VarCompensationMode.CONTINUOUS : ssb.controlMode == VarCompensatorControlModeBean.Discrete ? VarCompensationMode.DISCRETE : VarCompensationMode.FIXED; ss.setControlMode(mode); ss.setDesiredVoltageRange(new LimitType(ssb.vmax, ssb.vmin)); ss.setQLimit(new LimitType(ssb.qmax, ssb.qmin)); for (QBankBean qbb : ssb.varBankList) { QBank qb = CoreObjectFactory.createQBank(ss); qb.setSteps(qbb.step); qb.setUnitQMvar(qbb.UnitQMvar); } ss.setRemoteBus(aclfNet.getBus(ssb.remoteBusId)); } catch (InterpssException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:org.jahia.services.image.AbstractJava2DImageService.java
public boolean rotateImage(Image image, File outputFile, boolean clockwise) throws IOException { BufferedImage originalImage = ((BufferImage) image).getOriginalImage(); BufferedImage dest = getDestImage(originalImage.getHeight(), originalImage.getWidth(), originalImage); // Paint source image into the destination, scaling as needed Graphics2D graphics2D = getGraphics2D(dest, OperationType.ROTATE); double angle = Math.toRadians(clockwise ? 90 : -90); double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle)); int w = originalImage.getWidth(), h = originalImage.getHeight(); int neww = (int) Math.floor(w * cos + h * sin), newh = (int) Math.floor(h * cos + w * sin); graphics2D.translate((neww - w) / 2, (newh - h) / 2); graphics2D.rotate(angle, w / (double) 2, h / (double) 2); graphics2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC)); if (originalImage.getColorModel() instanceof IndexColorModel) { graphics2D.drawImage(originalImage, 0, 0, graphics2D.getBackground(), null); } else {// w w w . j av a 2s .co m graphics2D.drawImage(originalImage, 0, 0, null); } // Save destination image saveImageToFile(dest, ((BufferImage) image).getMimeType(), outputFile); return true; }
From source file:com.alvermont.terraj.planet.project.StereographicProjection.java
/** * Carry out the projection// ww w .ja v a 2s .c o m */ public void project() { setcolours(); final int width = getParameters().getProjectionParameters().getWidth(); final int height = getParameters().getProjectionParameters().getHeight(); final double lat = getParameters().getProjectionParameters().getLatitudeRadians(); final double lon = getParameters().getProjectionParameters().getLongitudeRadians(); final double scale = getParameters().getProjectionParameters().getScale(); final double hgrid = getParameters().getProjectionParameters().getHgrid(); final double vgrid = getParameters().getProjectionParameters().getVgrid(); final boolean doShade = getParameters().getProjectionParameters().isDoShade(); depth = (3 * ((int) (log2(scale * height)))) + 6; cacheParameters(); colours = new short[width][height]; shades = new short[width][height]; double x; double y; double z; double x1; double y1; double z1; double ymin; double ymax; double theta1; double theta2; double zz; int i; int j; ymin = 2.0; ymax = -2.0; final double sla = Math.sin(lat); final double cla = Math.cos(lat); final double slo = Math.sin(lon); final double clo = Math.cos(lon); progress.progressStart(height, "Generating Terrain"); for (j = 0; j < height; ++j) { progress.progressStep(j); for (i = 0; i < width; ++i) { x = ((2.0 * i) - width) / height / scale; y = ((2.0 * j) - height) / height / scale; z = (x * x) + (y * y); zz = 0.25 * (4.0 + z); x = x / zz; y = y / zz; z = (1.0 - (0.25 * z)) / zz; x1 = (clo * x) + (slo * sla * y) + (slo * cla * z); y1 = (cla * y) - (sla * z); z1 = (-slo * x) + (clo * sla * y) + (clo * cla * z); if (y1 < ymin) { ymin = y1; } if (y1 > ymax) { ymax = y1; } colours[i][j] = (short) planet0(x1, y1, z1); if (doShade) { shades[i][j] = shade; } } } progress.progressComplete("Terrain Generated"); if (hgrid != 0.0) { /* draw horizontal gridlines */ for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid) ; for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) { y = Math.sin(Math.toRadians(theta1)); if ((ymin <= y) && (y <= ymax)) { zz = Math.sqrt(1 - (y * y)); for (theta2 = -Math.PI; theta2 < Math.PI; theta2 += (0.5 / width / scale)) { x = Math.sin(theta2) * zz; z = Math.cos(theta2) * zz; x1 = (clo * x) + (slo * z); y1 = ((slo * sla * x) + (cla * y)) - (clo * sla * z); z1 = (-slo * cla * x) + (sla * y) + (clo * cla * z); if (Math.abs(z1) < 1.0) { i = (int) (0.5 * (((height * scale * 2.0 * x1 * (1 + z1)) / (1.0 - (z1 * z1))) + width)); j = (int) (0.5 * (((height * scale * 2.0 * y1 * (1 + z1)) / (1.0 - (z1 * z1))) + height)); if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) { colours[i][j] = BLACK; } } } } } } if (vgrid != 0.0) { /* draw vertical gridlines */ for (theta2 = -Math.PI; theta2 < Math.PI; theta2 += (0.5 / width / scale)) { y = Math.sin(theta2); if ((ymin <= y) && (y <= ymax)) { for (theta1 = 0.0; theta1 < 360.0; theta1 += vgrid) { x = Math.sin(Math.toRadians(theta1)) * Math.cos(theta2); z = Math.cos(Math.toRadians(theta1)) * Math.cos(theta2); x1 = (clo * x) + (slo * z); y1 = ((slo * sla * x) + (cla * y)) - (clo * sla * z); z1 = (-slo * cla * x) + (sla * y) + (clo * cla * z); if (Math.abs(z1) < 1.0) { i = (int) (0.5 * (((height * scale * 2.0 * x1 * (1 + z1)) / (1 - (z1 * z1))) + width)); j = (int) (0.5 * (((height * scale * 2.0 * y1 * (1 + z1)) / (1 - (z1 * z1))) + height)); if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) { colours[i][j] = BLACK; } } } } } } if (doShade) { smoothshades(); } doOutlining(); }
From source file:main.java.gov.wa.wsdot.candidate.evaluation.App.java
/** * Using the Haversine formula this method calculates the distance in miles * between two latitude and longitude points. * /* ww w . ja va 2s .c om*/ * Formula from: https://en.wikipedia.org/wiki/Haversine_formula * * @param lat1 latitude of point 1 (user) * @param long1 longitude of point 1 (user) * @param lat2 latitude of point 2 (camera) * @param long2 longitude of point 2 (camera) * @return distance in miles between two points given */ private double getDistance(double lat1, double long1, double lat2, double long2) { double deltaLong; double deltaLat; double hav2; double hav1; lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); long1 = Math.toRadians(long1); long2 = Math.toRadians(long2); deltaLong = Math.toRadians(long2 - long1); deltaLat = Math.toRadians(lat2 - lat1); hav1 = (Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2)); hav2 = (Math.sin(deltaLong / 2) * Math.sin(deltaLong / 2)); return Math.toDegrees(2 * R * Math.asin(Math.sqrt(hav1 + Math.cos(lat1) * Math.cos(lat2) * hav2))); }
From source file:com.example.pyo.edit.MapsActivity.java
private static LatLng toRadiusLatLng(LatLng center, double radius) { double radiusAngle = Math.toDegrees(radius / RADIUS_OF_EARTH_METERS) / Math.cos(Math.toRadians(center.latitude)); return new LatLng(center.latitude, center.longitude + radiusAngle); }