List of usage examples for java.lang Math toDegrees
public static double toDegrees(double angrad)
From source file:org.dawnsci.plotting.tools.powdercheck.PowderCheckJob.java
public void updateCalibrantLines() { 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/*from w ww.jav a 2s . co m*/ qVals[i] = (Math.PI * 2) / (spacings.get(i).getDNano() * 10); } Display.getDefault().syncExec(new Runnable() { @Override public void run() { if (system.getPlotComposite() == null) return; IAxis ax = system.getSelectedXAxis(); double low = ax.getLower(); double up = ax.getUpper(); for (IRegion r : system.getRegions()) system.removeRegion(r); for (int i = 0; i < qVals.length; i++) { if (qVals[i] < low || qVals[i] > up) continue; try { RectangularROI roi = new RectangularROI(qVals[i], 0, 1, 1, 0); IRegion reg = system.getRegion("Q value: " + qVals[i]); if (reg != null) system.removeRegion(reg); final IRegion area = system.createRegion("Q value: " + qVals[i], RegionType.XAXIS_LINE); area.setROI(roi); area.setRegionColor(ColorConstants.gray); area.setUserRegion(false); system.addRegion(area); area.setMobile(false); } catch (Exception e) { logger.error("Region is already there", e); } } } }); }
From source file:be.makercafe.apps.makerbench.editors.GCodeEditor.java
/** * Draws a line in 3D between 2 3D points on the given group. * /*from w w w . j ava 2s .co m*/ * @param origin * Origin point * @param target * Target point * @return 3D line (cylinder) between to points */ private Cylinder drawLine3D(Group group, Point3D origin, Point3D target, Material color) { if (color == null) { color = MATERIAL_BLACK; // default to orange } Point3D yAxis = new Point3D(0, 1, 0); Point3D diff = target.subtract(origin); double height = diff.magnitude(); Point3D mid = target.midpoint(origin); Translate moveToMidpoint = new Translate(mid.getX(), mid.getY(), mid.getZ()); Point3D axisOfRotation = diff.crossProduct(yAxis); double angle = Math.acos(diff.normalize().dotProduct(yAxis)); Rotate rotateAroundCenter = new Rotate(-Math.toDegrees(angle), axisOfRotation); Cylinder line = new Cylinder(1, height); line.setMaterial(color); line.getTransforms().addAll(moveToMidpoint, rotateAroundCenter); if (group != null) { group.getChildren().add(line); } return line; }
From source file:com.thalmic.android.sample.helloworld.HelloWorldActivity.java
private void convertToDegrees(float[] vector) { for (int i = 0; i < vector.length; i++) { vector[i] = Math.round(Math.toDegrees(vector[i])); }//from ww w .j a va 2s.c om }
From source file:ngat.opsgui.xcomp.SeeingPanel2.java
/** * Update components with latest seeing update. *//*w w w.ja v a2s. c o m*/ public void seeingUpdate(SkyModelSeeingUpdate sm) { // Table shtm.addRow(sm); // Summary panel fields correctedSeeingField.setText(String.format("%4.2f", sm.getCorrectedSeeing())); rawSeeingField.setText(String.format("%4.2f", sm.getRawSeeing())); sourceNameField.setText(sm.getSource()); // Category field updateSeeingCategory(sm.getCorrectedSeeing()); // Elevation field elevationField.setText(String.format("%4.2f", Math.toDegrees(sm.getElevation()))); // Histograms rawSeeingHistogram.updateSeeing(sm.getRawSeeing()); correctedSeeingHistogram.updateSeeing(sm.getCorrectedSeeing()); // Time series plots if (sm.isStandard()) { tac.addData("RAW_STD", sm.getStatusTimeStamp(), sm.getRawSeeing()); tac.addData("CORR_STD", sm.getStatusTimeStamp(), sm.getCorrectedSeeing()); } else { tac.addData("RAW_SCI", sm.getStatusTimeStamp(), sm.getRawSeeing()); tac.addData("CORR_SCI", sm.getStatusTimeStamp(), sm.getCorrectedSeeing()); } // Prediction plot tac.addData("PRED", sm.getStatusTimeStamp(), sm.getPredictedSeeing()); }
From source file:com.example.piechart3d.PieChart3DView.java
@SuppressLint("NewApi") @Override//from w w w .java2s. c o m public boolean onTouchEvent(MotionEvent event) { getParent().requestDisallowInterceptTouchEvent(true); float xxx = event.getX() - centerx; float yyy = event.getY() - centery; { mDetector.onTouchEvent(event); String direction; switch (event.getAction() & MotionEvent.ACTION_MASK) { case (MotionEvent.ACTION_DOWN): if (mZAnimator != null) mZAnimator.cancel(); iniMAngle = (float) java.lang.Math.atan2(yyy, xxx); inix = mRenderer.angle_x; iniz = mRenderer.angle_z; x1 = event.getX(); y1 = event.getY(); break; case MotionEvent.ACTION_POINTER_DOWN: iniMAngle = (float) java.lang.Math.atan2(yyy, xxx); Log.d("appAS", "Pointer down"); inix = mRenderer.angle_x; iniz = mRenderer.angle_z; d = rotation(event); break; case MotionEvent.ACTION_POINTER_UP: inix = mRenderer.angle_x; iniz = mRenderer.angle_z; iniMAngle = (float) java.lang.Math.atan2(yyy, xxx); break; case (MotionEvent.ACTION_MOVE): { if (event.getPointerCount() == 1) { x2 = event.getX(); y2 = event.getY(); dx = x2 - x1; dy = y2 - y1; if (Math.abs(dx) < Math.abs(dy) && Math.abs(dy) > 25) { iniz = mRenderer.angle_z; if (dy > 0) direction = "down"; else direction = "up"; this.requestDoRender(inix - (dy / 3), iniz); } else { mAngle = (float) java.lang.Math.atan2(yyy, xxx); inix = mRenderer.angle_x; if (dx > 0) direction = "right"; else direction = "left"; this.requestDoRender(inix, /* iniz + (dx / 3) */ iniz + (float) Math.toDegrees((mAngle - iniMAngle))); Log.d("ang", "" + iniz + " " + (iniz + (float) Math.toDegrees((mAngle - iniMAngle)))); } } else if (event.getPointerCount() == 2) { Log.d("app", "Rotating " + event.getPointerCount()); float rot = rotation(event) - d; this.requestDoRender(inix, iniz + rot); } } } } return true; }
From source file:com.shadowmaps.example.GpsTestActivity.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) @Override//from w w w. j av a2 s . c o m public void onSensorChanged(SensorEvent event) { double orientation = Double.NaN; double tilt = Double.NaN; switch (event.sensor.getType()) { case Sensor.TYPE_ROTATION_VECTOR: // Modern rotation vector sensors if (!mTruncateVector) { try { SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values); } catch (IllegalArgumentException e) { // On some Samsung devices, an exception is thrown if this vector > 4 (see #39) // Truncate the array, since we can deal with only the first four values Log.e(TAG, "Samsung device error? Will truncate vectors - " + e); mTruncateVector = true; // Do the truncation here the first time the exception occurs getRotationMatrixFromTruncatedVector(event.values); } } else { // Truncate the array to avoid the exception on some devices (see #39) getRotationMatrixFromTruncatedVector(event.values); } int rot = getWindowManager().getDefaultDisplay().getRotation(); switch (rot) { case Surface.ROTATION_0: // No orientation change, use default coordinate system SensorManager.getOrientation(mRotationMatrix, mValues); // Log.d(TAG, "Rotation-0"); break; case Surface.ROTATION_90: // Log.d(TAG, "Rotation-90"); SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, mRemappedMatrix); SensorManager.getOrientation(mRemappedMatrix, mValues); break; case Surface.ROTATION_180: // Log.d(TAG, "Rotation-180"); SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_MINUS_X, SensorManager.AXIS_MINUS_Y, mRemappedMatrix); SensorManager.getOrientation(mRemappedMatrix, mValues); break; case Surface.ROTATION_270: // Log.d(TAG, "Rotation-270"); SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X, mRemappedMatrix); SensorManager.getOrientation(mRemappedMatrix, mValues); break; default: // This shouldn't happen - assume default orientation SensorManager.getOrientation(mRotationMatrix, mValues); // Log.d(TAG, "Rotation-Unknown"); break; } orientation = Math.toDegrees(mValues[0]); // azimuth tilt = Math.toDegrees(mValues[1]); break; case Sensor.TYPE_ORIENTATION: // Legacy orientation sensors orientation = event.values[0]; break; default: // A sensor we're not using, so return return; } // Correct for true north, if preference is set if (mFaceTrueNorth && mGeomagneticField != null) { orientation += mGeomagneticField.getDeclination(); } for (GpsTestListener listener : mGpsTestListeners) { listener.onOrientationChanged(orientation, tilt); } }
From source file:devlight.io.library.ArcProgressStackView.java
private float getActionMoveAngle(final float x, final float y) { //Get radius//from w w w.j a v a 2 s . co m final float radius = mSize * 0.5F; // Get degrees without offset float degrees = (float) ((Math.toDegrees(Math.atan2(y - radius, x - radius)) + 360.0F) % 360.0F); if (degrees < 0) degrees += 2.0F * Math.PI; // Get point with offset relative to start angle final float newActionMoveX = (float) (radius * Math.cos((degrees - mStartAngle) / 180.0F * Math.PI)); final float newActionMoveY = (float) (radius * Math.sin((degrees - mStartAngle) / 180.0F * Math.PI)); // Set new angle with offset degrees = (float) ((Math.toDegrees(Math.atan2(newActionMoveY, newActionMoveX)) + 360.0F) % 360.0F); if (degrees < 0) degrees += 2.0F * Math.PI; return degrees; }
From source file:io.github.malapert.jwcs.coordsystem.Utility.java
/** * Given Cartesian x,y,z return corresponding longitude and latitude in * degrees.// ww w . j a v a 2 s . c om * * Notes: * ------ * Note that one can expect strange behavior for the values of the * longitudes very close to the pole. In fact, at the poles itself, * the longitudes are meaningless. * * @param xyz Vector with values for x,y,z * @return The same number of positions (longitude, latitude and in the * same order as the input. */ public final static double[] xyz2longlat(final RealMatrix xyz) { double x = xyz.getEntry(0, 0); double y = xyz.getEntry(1, 0); double z = xyz.getEntry(2, 0); double longitude = Math.toDegrees(Math.atan2(y, x)); longitude = (longitude < 0) ? longitude + 360.0d : longitude; double latitude = Math.toDegrees(Math.asin(z)); double coord[] = { longitude, latitude }; return coord; }
From source file:app.akexorcist.gdaplibrary.GoogleDirection.java
private LatLng getNewPosition(LatLng begin, LatLng end) { double lat = Math.abs(begin.latitude - end.latitude); double lng = Math.abs(begin.longitude - end.longitude); double dis = Math.sqrt(Math.pow(lat, 2) + Math.pow(lng, 2)); if (dis >= animateDistance) { double angle = -1; if (begin.latitude <= end.latitude && begin.longitude <= end.longitude) angle = Math.toDegrees(Math.atan(lng / lat)); else if (begin.latitude > end.latitude && begin.longitude <= end.longitude) angle = (90 - Math.toDegrees(Math.atan(lng / lat))) + 90; else if (begin.latitude > end.latitude && begin.longitude > end.longitude) angle = Math.toDegrees(Math.atan(lng / lat)) + 180; else if (begin.latitude <= end.latitude && begin.longitude > end.longitude) angle = (90 - Math.toDegrees(Math.atan(lng / lat))) + 270; double x = Math.cos(Math.toRadians(angle)) * animateDistance; double y = Math.sin(Math.toRadians(angle)) * animateDistance; totalAnimateDistance += animateDistance; double finalLat = begin.latitude + x; double finalLng = begin.longitude + y; return new LatLng(finalLat, finalLng); } else {//from ww w.ja v a 2s. c om return end; } }
From source file:com.example.piechart3d.PieChart3DView.java
private float rotation(MotionEvent event) { double delta_x = (event.getX(0) - event.getX(1)); double delta_y = (event.getY(0) - event.getY(1)); double radians = Math.atan2(delta_y, delta_x); return (float) Math.toDegrees(radians); }