List of usage examples for java.lang Math toDegrees
public static double toDegrees(double angrad)
From source file:com.kircherelectronics.gyroscopeexplorer.activity.GyroscopeActivity.java
private void updateText() { tvXAxis.setText(String.format("%.2f", Math.toDegrees(fusedOrientation[0]))); tvYAxis.setText(String.format("%.2f", Math.toDegrees(fusedOrientation[1]))); tvZAxis.setText(String.format("%.2f", Math.toDegrees(fusedOrientation[2]))); }
From source file:com.javadog.cgeowear.cgeoWear.java
/** * Interprets watch compass if user has requested that feature. *//* w w w . jav a2s. c o m*/ @Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { gravity = event.values.clone(); } else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { geomagnetic = event.values.clone(); //TODO: Some watches don't let me access the compass correctly yet. } if (gravity != null && geomagnetic != null) { float[] R = new float[9]; float[] I = new float[9]; boolean success = SensorManager.getRotationMatrix(R, I, gravity, geomagnetic); if (success) { float[] orientation = new float[3]; SensorManager.getOrientation(R, orientation); float azimuth = (float) Math.toDegrees(orientation[0]); if (currentLocation != null) { float smoothedLatitude = smoothSensorValues(oldLatitude, (float) currentLocation.getLatitude(), 1 / 3f); float smoothedLongitude = smoothSensorValues(oldLongitude, (float) currentLocation.getLongitude(), 1 / 3f); float smoothedAltitude = smoothSensorValues(oldAltitude, (float) currentLocation.getAltitude(), 1 / 3f); GeomagneticField geomagneticField = new GeomagneticField(smoothedLatitude, smoothedLongitude, smoothedAltitude, System.currentTimeMillis()); azimuth += geomagneticField.getDeclination(); float bearing = currentLocation.bearingTo(geocacheLocation); direction = smoothSensorValues(oldDirection, -(azimuth - bearing), 1 / 5f); //Set old values to current values (for smoothing) oldDirection = direction; oldLatitude = smoothedLatitude; oldLongitude = smoothedLongitude; oldAltitude = smoothedAltitude; //Display direction on compass if update interval has passed long currentTime = System.currentTimeMillis(); if ((currentTime - prevTime) > DIRECTION_UPDATE_SPEED) { rotateCompass(direction); prevTime = currentTime; } } } } }
From source file:org.dawnsci.plotting.tools.powdercheck.PowderCheckJob.java
private List<PowderCheckResult> fitPeaksToTrace(final Dataset xIn, final Dataset yIn, Dataset baselineIn) { resultList.clear();// ww w . jav a 2s . c om List<HKL> spacings = CalibrationFactory.getCalibrationStandards().getCalibrant().getHKLs(); final double[] qVals = new double[spacings.size()]; for (int i = 0; i < spacings.size(); i++) { if (xAxis == XAxis.ANGLE) qVals[i] = 2 * Math.toDegrees(Math.asin((metadata.getDiffractionCrystalEnvironment().getWavelength() / (2 * spacings.get(i).getDNano() * 10)))); else qVals[i] = (Math.PI * 2) / (spacings.get(i).getDNano() * 10); } double qMax = xIn.max().doubleValue(); double qMin = xIn.min().doubleValue(); List<Double> qList = new ArrayList<Double>(); int count = 0; for (double q : qVals) { if (q > qMax || q < qMin) continue; count++; qList.add(q); } double minPeak = Collections.min(qList); double maxPeak = Collections.max(qList); int minXidx = ROISliceUtils.findPositionOfClosestValueInAxis(xIn, minPeak) - EDGE_PIXEL_NUMBER; int maxXidx = ROISliceUtils.findPositionOfClosestValueInAxis(xIn, maxPeak) + EDGE_PIXEL_NUMBER; int maxSize = xIn.getSize(); minXidx = minXidx < 0 ? 0 : minXidx; maxXidx = maxXidx > maxSize - 1 ? maxSize - 1 : maxXidx; final Dataset x = xIn.getSlice(new int[] { minXidx }, new int[] { maxXidx }, null); final Dataset y = yIn.getSlice(new int[] { minXidx }, new int[] { maxXidx }, null); y.setName("Fit"); Dataset baseline = baselineIn.getSlice(new int[] { minXidx }, new int[] { maxXidx }, null); List<APeak> peaks = Generic1DFitter.fitPeaks(x, y, Gaussian.class, count + 10); List<PowderCheckResult> initResults = new ArrayList<PowderCheckResult>(); CompositeFunction cf = new CompositeFunction(); for (APeak peak : peaks) cf.addFunction(peak); double limit = findMatchLimit(qList, cf); while (cf.getNoOfFunctions() != 0 && !qList.isEmpty()) findMatches(initResults, qList, cf, limit); final CompositeFunction cfFinal = compositeFunctionFromResults(initResults); double[] initParam = new double[cfFinal.getFunctions().length * 3]; { int i = 0; for (IFunction func : cfFinal.getFunctions()) { initParam[i++] = func.getParameter(0).getValue(); initParam[i++] = func.getParameter(1).getValue(); initParam[i++] = func.getParameter(2).getValue(); } } final Dataset yfit = DatasetFactory.zeros(x, Dataset.FLOAT64); MultivariateOptimizer opt = new SimplexOptimizer(REL_TOL, ABS_TOL); MultivariateFunction fun = new MultivariateFunction() { @Override public double value(double[] arg0) { int j = 0; for (IFunction func : cfFinal.getFunctions()) { double[] p = func.getParameterValues(); p[0] = arg0[j++]; p[1] = arg0[j++]; p[2] = arg0[j++]; func.setParameterValues(p); } for (int i = 0; i < yfit.getSize(); i++) { yfit.set(cfFinal.val(x.getDouble(i)), i); } return y.residual(yfit); } }; opt.optimize(new InitialGuess(initParam), GoalType.MINIMIZE, new ObjectiveFunction(fun), new MaxEval(MAX_EVAL), new NelderMeadSimplex(initParam.length)); Dataset fit = Maths.add(yfit, baseline); fit.setName("Fit"); Dataset residual = Maths.subtract(y, yfit); residual.setName("Residual"); system.updatePlot1D(x, Arrays.asList(new IDataset[] { fit, residual }), null); setPlottingSystemAxes(); for (int i = 0; i < cfFinal.getNoOfFunctions(); i++) { resultList.add(new PowderCheckResult(cfFinal.getFunction(i), initResults.get(i).getCalibrantQValue())); } return resultList; }
From source file:com.planetmayo.debrief.satc.model.contributions.Range1959ForecastContribution.java
private double calculateBearingRate(ProblemSpace space) { // get the states for our time period // get a few bounded states Collection<BoundedState> testStates = space.getBoundedStatesBetween(this.getStartDate(), this.getFinishDate()); ArrayList<Double> values = new ArrayList<Double>(); ArrayList<Double> times = new ArrayList<Double>(); for (Iterator<BoundedState> iterator = testStates.iterator(); iterator.hasNext();) { BoundedState boundedState = iterator.next(); // does it have a bearing? if (boundedState.hasBearing()) { values.add(boundedState.getBearing()); long millis = boundedState.getTime().getTime(); double mins = millis / 1000 / 60d; times.add(mins);//ww w . j av a 2s. c o m } } double bDotRads = getSlope(times, values); // convert the bearing rate to degs (our formula needs it return Math.toDegrees(bDotRads); }
From source file:uk.ac.diamond.scisoft.analysis.dataset.function.MapToPolarAndIntegrate.java
private double pixelToValue(double x, double y) { switch (axisType) { case RESOLUTION: Vector3d vect = qSpace.qFromPixelPosition(x, y); return (2 * Math.PI) / vect.length(); case ANGLE:/*from w ww .j ava 2 s .c o m*/ vect = qSpace.qFromPixelPosition(x, y); return Math.toDegrees(qSpace.scatteringAngle(vect)); case Q: vect = qSpace.qFromPixelPosition(x, y); return vect.length(); default: Vector2d vect2 = new Vector2d(new double[] { x - cx, y - cy }); return vect2.length(); } }
From source file:com.tritop.androsense2.fragments.GpsFragment.java
@Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { mAccel = event.values;//from w w w . jav a2 s . com } if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { mMag = event.values; } if ((mAccel != null) && (mMag != null)) { float R[] = new float[9]; float I[] = new float[9]; float Rot[] = new float[9]; if (SensorManager.getRotationMatrix(R, I, mAccel, mMag)) { float orientation[] = new float[3]; int axisX = 0, axisY = 0; switch (display.getRotation()) { case Surface.ROTATION_0: axisX = SensorManager.AXIS_X; axisY = SensorManager.AXIS_Y; break; case Surface.ROTATION_90: axisX = SensorManager.AXIS_Y; axisY = SensorManager.AXIS_MINUS_X; break; case Surface.ROTATION_180: axisX = SensorManager.AXIS_MINUS_X; axisY = SensorManager.AXIS_MINUS_Y; break; case Surface.ROTATION_270: axisX = SensorManager.AXIS_MINUS_Y; axisY = SensorManager.AXIS_X; break; default: break; } SensorManager.remapCoordinateSystem(R, axisX, axisY, Rot); SensorManager.getOrientation(Rot, orientation); aRotation = orientation[0]; aRotation = (int) Math.toDegrees(aRotation); satView.setAzimutRotation(-aRotation); satView.invalidate(); } } }
From source file:com.googlecode.eyesfree.widget.RadialMenuView.java
/** * Re-draw cached wedge bitmaps.// ww w .java 2s . co m */ private void invalidateCachedWedgeShapes() { final RadialMenu menu = mSubMenu != null ? mSubMenu : mRootMenu; final int menuSize = menu.size(); if (menuSize <= 0) { return; } final float wedgeArc = (360.0f / menuSize); final float offsetArc = ((wedgeArc / 2.0f) + 90.0f); final float spacingArc = (float) Math.toDegrees(Math.tan(mSpacing / (double) mOuterRadius)); final float spacingExtremeArc = (float) Math.toDegrees(Math.tan(mSpacing / (double) mExtremeRadius)); final float left = (wedgeArc - spacingArc - offsetArc); final float leftExtreme = (wedgeArc - spacingExtremeArc - offsetArc); final float center = ((wedgeArc / 2.0f) - offsetArc); final float right = (spacingArc - offsetArc); final float rightExtreme = (spacingExtremeArc - offsetArc); // Outer wedge. mCachedOuterPath.rewind(); mCachedOuterPath.arcTo(mCachedOuterBound, center, (left - center)); mCachedOuterPath.arcTo(mCachedExtremeBound, left, (right - left)); mCachedOuterPath.arcTo(mCachedOuterBound, right, (center - right)); mCachedOuterPath.close(); mCachedOuterPathWidth = arcLength((left - right), mExtremeRadius); // Outer wedge in reverse, for rendering text. mCachedOuterPathReverse.rewind(); mCachedOuterPathReverse.arcTo(mCachedOuterBound, center, (right - center)); mCachedOuterPathReverse.arcTo(mCachedExtremeBound, right, (left - right)); mCachedOuterPathReverse.arcTo(mCachedOuterBound, left, (center - left)); mCachedOuterPathReverse.close(); }
From source file:com.seekret.data.flickr.FlickrRequestHandler.java
/** * This method generates satelites around a given spot. Attention, using * this method for requests to flickr, we can get problems with write/read * operations and problems with the spot size ( > 1MB) concerning memcache. * //from ww w. ja va 2 s . c o m * @param spot * given Spot. * @param allPoints * Map of Points with spotradius. */ @SuppressWarnings("unused") private void createSatelitesArroundGivenSpot(Spot spot, HashMap<LatLng, Double> allPoints) { for (int degree = 0; degree < 316; degree += 45) { double d = spot.getSpotRadiusInKm() + (spot.getSpotRadiusInKm() / 2.0); System.out.println("Distance = " + d); double dist = d / 6371.0; double brng = Math.toRadians(degree); double lat1 = Math.toRadians(spot.getLatitude()); double lon1 = Math.toRadians(spot.getLongitude()); double lat2 = Math .asin(Math.sin(lat1) * Math.cos(dist) + Math.cos(lat1) * Math.sin(dist) * Math.cos(brng)); double a = Math.atan2(Math.sin(brng) * Math.sin(dist) * Math.cos(lat1), Math.cos(dist) - Math.sin(lat1) * Math.sin(lat2)); System.out.println("a = " + a); double lon2 = lon1 + a; lon2 = (lon2 + 3 * Math.PI) % (2 * Math.PI) - Math.PI; double latitude2 = Math.toDegrees(lat2); double longitude2 = Math.toDegrees(lon2); System.out.println("Latitude = " + latitude2 + "\nLongitude = " + longitude2); LatLng origin = new LatLng(spot.getLatitude(), spot.getLongitude()); LatLng newPoint = new LatLng(latitude2, longitude2); log.log(Level.INFO, "DISTANCE TO CENTER " + (LatLngTool.distance(origin, newPoint, LengthUnit.KILOMETER))); allPoints.put(newPoint, Double.valueOf(spot.getSpotRadiusInKm() / 2.0)); } }
From source file:com.samebits.beacon.locator.ui.view.RadarScanView.java
private synchronized void calcBearing(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { System.arraycopy(event.values, 0, mLastAccelerometer, 0, event.values.length); mLastAccelerometerSet = true;// w ww. j ava 2s . c o m } else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { System.arraycopy(event.values, 0, mLastMagnetometer, 0, event.values.length); mLastMagnetometerSet = true; } if (mLastAccelerometerSet && mLastMagnetometerSet) { /* Create rotation Matrix */ float[] rotationMatrix = new float[9]; if (SensorManager.getRotationMatrix(rotationMatrix, null, mLastAccelerometer, mLastMagnetometer)) { SensorManager.getOrientation(rotationMatrix, mOrientation); float azimuthInRadians = mOrientation[0]; angleLowpassFilter.add(azimuthInRadians); mLast_bearing = (float) (Math.toDegrees(angleLowpassFilter.average()) + 360) % 360; postInvalidate(); //Log.d(Constants.TAG, "orientation bearing: " + mLast_bearing); } } }
From source file:com.android.screenspeak.contextmenu.RadialMenuView.java
/** * Re-draw cached wedge bitmaps.// ww w . j av a 2s. c o m */ private void invalidateCachedWedgeShapes() { final RadialMenu menu = mSubMenu != null ? mSubMenu : mRootMenu; final int menuSize = menu.size(); if (menuSize <= 0) { return; } final float wedgeArc = (360.0f / menuSize); final float offsetArc = ((wedgeArc / 2.0f) + 90.0f); final float spacingArc = (float) Math.toDegrees(Math.tan(mSpacing / (double) mOuterRadius)); final float left = (wedgeArc - spacingArc - offsetArc); final float center = ((wedgeArc / 2.0f) - offsetArc); final float right = (spacingArc - offsetArc); // Outer wedge. mCachedOuterPath.rewind(); mCachedOuterPath.arcTo(mCachedOuterBound, center, (left - center)); mCachedOuterPath.arcTo(mCachedExtremeBound, left, (right - left)); mCachedOuterPath.arcTo(mCachedOuterBound, right, (center - right)); mCachedOuterPath.close(); mCachedOuterPathWidth = arcLength((left - right), mExtremeRadius); // Outer wedge in reverse, for rendering text. mCachedOuterPathReverse.rewind(); mCachedOuterPathReverse.arcTo(mCachedOuterBound, center, (right - center)); mCachedOuterPathReverse.arcTo(mCachedExtremeBound, right, (left - right)); mCachedOuterPathReverse.arcTo(mCachedOuterBound, left, (center - left)); mCachedOuterPathReverse.close(); }