List of usage examples for java.lang Math toDegrees
public static double toDegrees(double angrad)
From source file:android.support.wear.widget.util.ArcSwipe.java
@VisibleForTesting float getAngle(double x, double y) { double relativeX = x - (mBounds.width() / 2); double relativeY = y - (mBounds.height() / 2); double rowAngle = Math.atan2(relativeX, relativeY); double angle = -Math.toDegrees(rowAngle) - 180; if (angle < 0) { angle += 360;//from w w w .ja va 2 s . com } return (float) angle; }
From source file:pt.lsts.neptus.plugins.urready4os.IverPlanExporter.java
@Override public void exportToFile(PlanType plan, File out, ProgressMonitor monitor) throws Exception { double distanceSum = 0; double timeSum = 0; double minDepth = Double.MAX_VALUE, minLat = Double.MAX_VALUE, minLon = Double.MAX_VALUE; double maxDepth = -Double.MAX_VALUE, maxLat = -Double.MAX_VALUE, maxLon = -Double.MAX_VALUE; int count = 1; ManeuverLocation previousLoc = null; StringBuilder wpts = new StringBuilder(); StringBuilder wpt_times = new StringBuilder(); for (Maneuver m : plan.getGraph().getManeuversSequence()) { double speed = ManeuversUtil.getSpeedMps(m); if (Double.isNaN(speed)) continue; if (m instanceof YoYo) { ManeuverLocation loc = ((YoYo) m).getManeuverLocation(); loc.convertToAbsoluteLatLonDepth(); double amp = ((YoYo) m).getAmplitude(); double depth = loc.getDepth(); double distance = 0; if (previousLoc != null) distance = previousLoc.getDistanceInMeters(loc); double time = distance / speed;// * Math.cos(((YoYo)m).getPitchAngle())); maxDepth = Math.max(depth + amp, maxDepth); minDepth = Math.min(depth - amp, minDepth); minLat = Math.min(minLat, loc.getLatitudeDegs()); maxLat = Math.max(maxLat, loc.getLatitudeDegs()); minLon = Math.min(minLon, loc.getLongitudeDegs()); maxLon = Math.max(maxLon, loc.getLongitudeDegs()); wpts.append(iverWaypoint(count, speed, /*distance,*/ ((YoYo) m).getAmplitude(), Math.toDegrees(((YoYo) m).getPitchAngle()), previousLoc, ((YoYo) m).getManeuverLocation())); timeSum += time;//from w w w . jav a 2s .c o m distanceSum += distance; if (distanceSum == 0) wpt_times.append(String.format(Locale.US, "WP%d;Time=0;Dist=0\r\n", count++)); else wpt_times.append(String.format(Locale.US, "WP%d;Time=%.11f;Dist=%.11f\r\n", count++, timeSum, distanceSum)); previousLoc = loc; } else if (m instanceof LocatedManeuver) { for (ManeuverLocation wpt : ((LocatedManeuver) m).getWaypoints()) { wpt.convertToAbsoluteLatLonDepth(); double depth = wpt.getDepth(); double distance = 0; if (previousLoc != null) distance = previousLoc.getDistanceInMeters(wpt); double time = distance / speed; maxDepth = Math.max(depth, maxDepth); minDepth = Math.min(depth, minDepth); minLat = Math.min(minLat, wpt.getLatitudeDegs()); maxLat = Math.max(maxLat, wpt.getLatitudeDegs()); minLon = Math.min(minLon, wpt.getLongitudeDegs()); maxLon = Math.max(maxLon, wpt.getLongitudeDegs()); wpts.append(iverWaypoint(count, speed, /*distance,*/ 0, 0, previousLoc, wpt)); timeSum += time; distanceSum += distance; if (distanceSum == 0) wpt_times.append(String.format(Locale.US, "WP%d;Time=0;Dist=0\r\n", count++)); else wpt_times.append(String.format(Locale.US, "WP%d;Time=%.11f;Dist=%.11f\r\n", count++, timeSum, distanceSum)); previousLoc = wpt; } } else { NeptusLog.pub() .warn("Maneuvers of type " + m.getType() + " are not supported and thus will be skipped."); } } int secs = (int) timeSum; wpt_times.append(String.format(Locale.US, "Total Time = %02d:%02d:%02d;Total Distance = %.2f\r\n", secs / 3600, (secs % 3600) / 60, secs % 60, distanceSum)); String template = PluginUtils.getResourceAsString("pt/lsts/neptus/plugins/urready4os/template.mis"); template = template.replaceAll("\\$\\{wpts\\}", wpts.toString().trim()); template = template.replaceAll("\\$\\{wpt_times\\}", wpt_times.toString().trim()); template = template.replaceAll("\\$\\{mission_name\\}", out.getName()); template = template.replaceAll("\\$\\{minLat\\}", String.format(Locale.US, "%.6f", minLat)); template = template.replaceAll("\\$\\{maxLat\\}", String.format(Locale.US, "%.6f", maxLat)); template = template.replaceAll("\\$\\{minLon\\}", String.format(Locale.US, "%.6f", minLon)); template = template.replaceAll("\\$\\{maxLon\\}", String.format(Locale.US, "%.6f", maxLon)); template = template.replaceAll("\\$\\{centerLat\\}", String.format(Locale.US, "%.6f", (minLat + maxLat) / 2)); template = template.replaceAll("\\$\\{centerLon\\}", String.format(Locale.US, "%.6f", (minLon + maxLon) / 2)); FileUtils.write(out, template); }
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); }
From source file:org.gearvrf.viewmanager.controls.gestures.TouchPadGesturesDetector.java
@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { Log.d(TouchPadGesturesDetector.DEBUG_TAG, "onFling()"); if (mDetector == null) { return false; }// www .j a v a2s.c om double distance = Math.sqrt(Math.pow(e2.getX() - e1.getX(), 2) + Math.pow(e2.getY() - e1.getY(), 2)); saveSwipeDistanceValue((float) distance); if (distance > SWIPE_MIN_DISTANCE) { try { double deltaY = e2.getY() - e1.getY(); double deltaX = e2.getX() - e1.getX(); double angle = Math.toDegrees(Math.atan2(deltaY, deltaX)) + 180 + 45; if (angle > 360) angle -= 360; if (angle < 90) { return gestureListener.onSwipe(e1, SwipeDirection.Forward, velocityX, velocityY); } else if (angle < 180) { return gestureListener.onSwipe(e1, SwipeDirection.Up, velocityX, velocityY); } else if (angle < 270) { return gestureListener.onSwipe(e1, SwipeDirection.Backward, velocityX, velocityY); } else { return gestureListener.onSwipe(e1, SwipeDirection.Down, velocityX, velocityY); } } catch (Exception e) { // Ignore } } else if (distance >= ONTAP_MIN_DISTANCE) { /* * The gesture listener filters out dirty taps that look like swipes * altogether. This reduces usability as it's hard to get a clean * tap on the tracker */ gestureListener.onSingleTap(e1); return true; } return false; }
From source file:com.compomics.cell_coord.computation.impl.TrackOperatorImpl.java
@Override public void computeAngles(Track track) { Double[][] steps = track.getSteps(); Double[] angles = new Double[steps.length]; for (int row = 0; row < angles.length; row++) { // This method computes the phase theta by computing an arc tangent of y/x in the range of -pi to pi. double d = steps[row][1] / steps[row][0]; // if division is 0, the cell is going exactly back on its path! Double angleRadians = Math.atan(d) + 0; // need to add 0 to avoid signed 0 in Java // go from radians to degrees Double angleDegrees = Math.toDegrees(angleRadians); // if the angle is NaN (both deltaX and deltaY are zero), the cell stays exactly on place if (angleDegrees < 0) { angleDegrees = angleDegrees + 360; }//from ww w . j a va 2 s. co m angles[row] = angleDegrees; } track.setAngles(angles); }
From source file:org.gearvrf.controls.util.VRSamplesTouchPadGesturesDetector.java
@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (mDetector == null) { return false; }/*from w w w. ja v a2s. c o m*/ double distance = Math.sqrt(Math.pow(e2.getX() - e1.getX(), 2) + Math.pow(e2.getY() - e1.getY(), 2)); saveSwipeDistanceValue((float) distance); if (distance > SWIPE_MIN_DISTANCE) { try { double deltaY = e2.getY() - e1.getY(); double deltaX = e2.getX() - e1.getX(); double angle = Math.toDegrees(Math.atan2(deltaY, deltaX)) + 180 + 45; if (angle > 360) angle -= 360; if (angle < 90) { return gestureListener.onSwipe(e1, SwipeDirection.Forward, velocityX, velocityY); } else if (angle < 180) { return gestureListener.onSwipe(e1, SwipeDirection.Up, velocityX, velocityY); } else if (angle < 270) { return gestureListener.onSwipe(e1, SwipeDirection.Backward, velocityX, velocityY); } else { return gestureListener.onSwipe(e1, SwipeDirection.Down, velocityX, velocityY); } } catch (Exception e) { // Ignore } } else if (distance >= ONTAP_MIN_DISTANCE) { /* * The gesture listener filters out dirty taps that look like swipes * altogether. This reduces usability as it's hard to get a clean * tap on the tracker */ gestureListener.onSingleTap(e1); return true; } return false; }
From source file:Satellite.java
public static double[] Convert_To_Lat_Long(double[] posVec) { double Xcomp = posVec[0]; double Ycomp = posVec[1]; double Zcomp = posVec[2]; double longitude; double latitude; double altitude; //Done so all cases of longitudes are right if (Ycomp > 0) { if (Xcomp > 0) { longitude = Math.toDegrees(Math.atan(Ycomp / Xcomp)); } else {// ww w . j a v a2 s. c o m longitude = 180 - Math.toDegrees(Math.atan(Math.abs(Ycomp / Xcomp))); } } else { if (Xcomp > 0) { longitude = -1 * Math.toDegrees(Math.atan(Math.abs(Ycomp / Xcomp))); } else { longitude = -1 * (180 - Math.toDegrees(Math.atan(Ycomp / Xcomp))); } } //Calculate latitude latitude = Math.toDegrees(Math.atan(Zcomp / Math.sqrt(Xcomp * Xcomp + Ycomp * Ycomp))); //Calculate radius and altitude double EPR = 6356800; //Earth Polar Radius in meters double EER = 6378100; //Earth Equator Radius in meters double earthRadius = Math .sqrt((Math.pow(EPR * EPR * Math.cos(latitude), 2) + Math.pow(EER * EER * Math.cos(latitude), 2)) / (Math.pow(EPR * Math.cos(latitude), 2) + Math.pow(EER * Math.cos(latitude), 2))); double orbitRadius = Math.sqrt(Xcomp * Xcomp + Ycomp * Ycomp + Zcomp * Zcomp); altitude = orbitRadius - earthRadius; return new double[] { latitude, longitude, altitude }; }
From source file:com.laex.cg2d.model.joints.BEPrismaticJoint.java
@Override public Object getPropertyValue(Object id) { if (isWorldAnchorProp(id)) { return new Vec2PropertySource(this.worldAnchor); } else if (isWorldAxisProp(id)) { return new Vec2PropertySource(this.worldAxis); } else if (isReferenceAngleProp(id)) { return Float.toString((float) Math.toDegrees(this.prismaticJointDef.referenceAngle)); } else if (isEnableLimitProp(id)) { return BooleanUtil.getIntegerFromBoolean(prismaticJointDef.enableLimit); } else if (isLowerTranslationProp(id)) { return Float.toString(prismaticJointDef.lowerTranslation); } else if (isUpperTranslationProp(id)) { return Float.toString(prismaticJointDef.upperTranslation); } else if (isEnableMotorProp(id)) { return BooleanUtil.getIntegerFromBoolean(prismaticJointDef.enableMotor); } else if (isMaxMotorForceProp(id)) { return Float.toString(prismaticJointDef.maxMotorForce); } else if (isMotorSpeedProp(id)) { return Float.toString(prismaticJointDef.motorSpeed); }/*from ww w . ja va 2 s . c om*/ return super.getPropertyValue(id); }
From source file:com.logicdrop.fordchallenge.api.services.IterisService.java
private double distanceFrom(List<String> item) { double lat = Double.parseDouble(item.get(0)); double lng = Double.parseDouble(item.get(1)); if (IncidentsActivity.getLocation() == null) return 0; double theta = lng - IncidentsActivity.getLocation().getLongitude(); double distance = Math.sin(deg2rad(lat)) * Math.sin(deg2rad(IncidentsActivity.getLocation().getLatitude())) + Math.cos(deg2rad(lat)) * Math.cos(deg2rad(IncidentsActivity.getLocation().getLatitude())) * Math.cos(deg2rad(theta)); distance = Math.acos(distance); distance = Math.toDegrees(distance); distance = distance * 60 * 1.1515;//from ww w. j a v a 2s .c o m return distance; }
From source file:edu.wpi.first.wpilibj.templates.RobotTemplate.java
public void teleopPeriodic() { autonomousModeSelecter();//from w ww . j av a 2 s. c o m dirX = driveStick.getX(); dirY = driveStick.getY(); dirM = driveStick.getDirectionRadians(); //if(0<dirM<) driveM.arcadeDrive(driveStick, true); //Enabling Drive with Joystick driveA.arcadeDrive(assistStick, true); if (driveStick.getRawButton(12)) { liftMotor.set(-1.00); } else if (assistStick.getRawButton(7)) { liftMotor.set(1.00); } else liftMotor.set(0.00); dir = Math.toDegrees(assistStick.getDirectionRadians()); lcd.println(Line.kUser1, 1, "Teleop Enabled"); //lcd.println(Line.kUser2, 1, Double.toString(dir)); //lcd.println(Line.kUser3, 1, Double.toString(dirM)); //lcd.println(Line.kUser4, 1, Double.toString(dirX)); //lcd.println(Line.kUser5, 1, Double.toString(dirY)); lcd.println(Line.kUser4, 1, "Battery Voltage:"); lcd.println(Line.kUser3, 1, "Compensation Value:"); lcd.println(Line.kUser4, 17, Double.toString(robotBatteryVoltage)); lcd.println(Line.kUser3, 20, Double.toString(m)); lcd.updateLCD(); Timer.delay(0.005); }