List of usage examples for java.lang Math toRadians
public static double toRadians(double angdeg)
From source file:org.spout.api.math.Quaternion.java
/** * Constructs a new Quaternion that represents a given rotation around an * arbatrary axis/*from ww w .j a v a 2 s . co m*/ * * @param angle Angle, in Degrees, to rotate the axis about by * @param x-axis * @param y-axis * @param z-axis */ public Quaternion(float angle, float x, float y, float z) { double rads = Math.toRadians(angle); double halfAngle = Math.sin(rads / 2); this.x = (float) (x * halfAngle); this.y = (float) (y * halfAngle); this.z = (float) (z * halfAngle); this.w = (float) Math.cos(rads / 2); }
From source file:com.androidquery.simplefeed.data.Place.java
public static double distFrom(double lat1, double lng1, double lat2, double lng2) { double earthRadius = 3958.75; 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 dist = earthRadius * c; int meterConversion = 1609; return new Double(dist * meterConversion); }
From source file:fr.amap.lidar.amapvox.commons.GTheta.java
/** * Generate the probability density array. * @param stepNumber Number of intervals *//*ww w.j ava2s . com*/ private void setupDensityProbabilityArray(int stepNumber) { //contains angles from 0 to 90 serie_angulaire = new double[stepNumber]; double step = (Math.round((90 / (float) (stepNumber - 1)) * 100)) / 100.0; double totalStep = 0; for (int i = 0; i < stepNumber; i++) { if (i == 0) { serie_angulaire[i] = Math.toRadians((Math.round(0.001 * 1000)) / 1000.0); } else { serie_angulaire[i] = Math.toRadians((Math.round(totalStep * 1000)) / 1000.0); } totalStep += step; } nbIntervals = serie_angulaire.length - 1; serie_angulaire[nbIntervals] = Math.toRadians(90) - 0.00000001; //integration failed on the last interval (patch) //calcul du tableau de densits ou probabilits pdfArray = new double[serie_angulaire.length]; for (int i = 0; i < pdfArray.length; i++) { pdfArray[i] = distribution.getDensityProbability(serie_angulaire[i]); SOM += pdfArray[i]; } }
From source file:magma.agent.worldmodel.impl.ThisPlayer.java
public void updateThisPlayer(IPerception perception) { String teamSide = perception.getGameState().getTeam(); if ("right".equalsIgnoreCase(teamSide)) side = IMagmaConstants.RIGHT_SIDE; else if ("left".equalsIgnoreCase(teamSide)) side = IMagmaConstants.LEFT_SIDE; IHingeJointPerceptor neck = perception .getHingeJointPerceptor(IServerConfigFilesConstants.HINGEJOINT_PERCEPTORS[0]); if (neck != null) { neckYawAngle = Math.toRadians(neck.getAxis()); }//from w w w . j a v a 2 s .co m neck = perception.getHingeJointPerceptor(IServerConfigFilesConstants.HINGEJOINT_PERCEPTORS[1]); if (neck != null) { neckPitchAngle = Math.toRadians(neck.getAxis()); } }
From source file:org.uiautomation.ios.utils.InstrumentsGeneratedImage.java
private BufferedImage rotate() { int rotateDegrees = orientation.getRotationInDegree(); boolean flip = orientation == Orientation.LANDSCAPE || orientation == Orientation.UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT; try {/*from w w w .j a va2 s . c o m*/ final BufferedImage originalImage = ImageIO.read(source); // no rotation needed. if (rotateDegrees == 0) { return originalImage; } // need to rotate. final BufferedImage rotated; int width; int height; if (flip) { width = originalImage.getHeight(); height = originalImage.getWidth(); } else { width = originalImage.getWidth(); height = originalImage.getHeight(); } rotated = new BufferedImage(width, height, originalImage.getType()); // Rotate the image and then move it back up to the origin through a translation call, since it'll pivot around // the center point which will cause non-square images to offset by the different in height and width. final Graphics2D graphics = rotated.createGraphics(); graphics.rotate(Math.toRadians(rotateDegrees), rotated.getWidth() / 2, rotated.getHeight() / 2); graphics.translate((rotated.getWidth() - originalImage.getWidth()) / 2, (rotated.getHeight() - originalImage.getHeight()) / 2); graphics.drawImage(originalImage, 0, 0, originalImage.getWidth(), originalImage.getHeight(), null); return rotated; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:edu.jhuapl.graphs.jfreechart.utils.RotatedTickDateAxis.java
@SuppressWarnings("unchecked") @Override/*from w w w . j av a 2 s . co m*/ protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { double rotationAngleInRad = Math.toRadians(tickLabelAngle); //Template types are specified here for additional type safety. List<Tick> ticks = (List<Tick>) super.refreshTicksHorizontal(g2, dataArea, edge); List<Tick> ret = new ArrayList<Tick>(); for (Tick tick : ticks) { if (tick instanceof DateTick) { DateTick dateTick = (DateTick) tick; //The anchor used depends on the label angle, as follows: TextAnchor textAnchor, rotationAnchor; double modRadians = rotationAngleInRad % (2 * Math.PI); //Handle case where user provided a negative angle value. if (modRadians < 0) { modRadians += 2 * Math.PI; } //For angles between 0-180 degrees: if (modRadians <= Math.PI) { textAnchor = TextAnchor.CENTER_LEFT; rotationAnchor = TextAnchor.CENTER_LEFT; } //For angles between 180-360 degrees: else { textAnchor = TextAnchor.CENTER_RIGHT; rotationAnchor = TextAnchor.CENTER_RIGHT; } ret.add(new DateTick(dateTick.getDate(), dateTick.getText(), textAnchor, rotationAnchor, rotationAngleInRad)); } else { ret.add(tick); } } return ret; }
From source file:beans.BL.java
public void test(TPVObject tpv) { /**/*from ww w . j a v a 2 s .co m*/ * Neue Idee alles zu speichern */ /*Umwandlung von Double in LDT Problem das es zu ungenau ist Double test = (tpv.getTimestamp()); long int_timestamp = test.longValue(); LocalDateTime ldt = LocalDateTime.ofEpochSecond(int_timestamp, 0, ZoneOffset.UTC); */ System.out.println( tpv.getTimestamp() + " Longitude: " + tpv.getLatitude() + " Latitude: " + tpv.getLongitude()); //TODO: /** * Algorithmus um die gefahrenen Km zu messen */ if (tpv.getSpeed() > 2.77) { if (latOld == -1 && lonOld == -1) { latNew = tpv.getLatitude(); lonNew = tpv.getLongitude(); } latOld = latNew; lonOld = lonNew; latNew = tpv.getLatitude(); lonNew = tpv.getLongitude(); double R = 6371000; // metres double dLat = Math.toRadians(latNew - latOld); double dLon = Math.toRadians(lonNew - lonOld); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(latOld)) * Math.cos(Math.toRadians(latNew)) * Math.sin(dLon / 2) * Math.sin(dLon / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); d = d + (R * c); System.out.println("Distance:" + d + "Speed:" + tpv.getSpeed()); } Point point = new Point(LocalDateTime.now(), tpv.getLatitude(), tpv.getLongitude(), d, tpv.getSpeed(), track); try { points.put(point); } catch (InterruptedException ex) { Logger.getLogger(BL.class.getName()).log(Level.SEVERE, null, ex); } try { System.out.println("points size:" + points.size()); System.out.println("traks size:" + tracks.size()); for (Track track1 : tracks) { System.out.println("track: " + track1.getId()); } data_manager.writeFile(points); } catch (ParseException ex) { Logger.getLogger(BL.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(BL.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.rifidi.designer.library.retail.clothing.Clothing.java
@Override public void init() { setCollides(false);// w w w . j av a 2 s. co m URI modelpath = null; if (model == null) { try { modelpath = getClass().getClassLoader() .getResource("org/rifidi/designer/library/retail/clothing/cloth0.jme").toURI(); model = (Node) BinaryImporter.getInstance().load(modelpath.toURL()); } catch (MalformedURLException e) { logger.error("Can't load model: " + e); } catch (IOException e) { logger.error("Can't load model: " + e); } catch (URISyntaxException e) { logger.error("Can't load model: " + e); } Quaternion quat = new Quaternion(new float[] { (float) Math.toRadians(270f), 0f, 0f }); model.setLocalRotation(quat); } DynamicPhysicsNode physix = physicsSpace.createDynamicNode(); physix.setModelBound(new BoundingBox()); physix.attachChild(new SharedNode("sharedcloth", model)); setNode(physix); physix.setLocalTranslation(startTranslation); physix.setLocalRotation(startRotation); physix.updateModelBound(); physix.generatePhysicsGeometry(); physix.setIsCollidable(true); physix.setActive(true); physix.updateModelBound(); }
From source file:edu.ucsf.valelab.saim.RunTheFit.java
@Override public void run() { // pre-populate arrays with angles in radians and in degrees final double[] anglesRadians = new double[ip_.getNSlices()]; final double[] anglesDegrees = new double[ip_.getNSlices()]; for (int i = 0; i < anglesRadians.length; i++) { double angle = sd_.firstAngle_ + i * sd_.angleStep_; anglesDegrees[i] = angle;/*w ww . j a v a 2s . c o m*/ anglesRadians[i] = Math.toRadians(angle); } final ImageStack is = ip_.getImageStack(); final int width = ip_.getWidth(); final int height = ip_.getHeight(); // create the fitter final SaimFunctionFitter sff = new SaimFunctionFitter(sd_.wavelength_, sd_.dOx_, sd_.nSample_, false); final SaimFunction sf = new SaimFunction(sd_); final int nrTries = sd_.heights_.length; Double[] r2s = new Double[nrTries]; double[][] results = new double[nrTries][]; // now cycle through the x/y pixels and fit each of them IntensityData observed = new IntensityData(); IntensityData calculated = new IntensityData(); int lastX = startX_ + numberX_; try { for (int x = startX_; x < lastX; x++) { for (int y = 0; y < height; y++) { if (stop_.get()) { return; } float sum = 0.0f; float[] values = new float[ip_.getNSlices()]; for (int i = 0; i < ip_.getNSlices(); i++) { values[i] = is.getProcessor(i + 1).get(x, y); sum += values[i]; } // only calculate if the average pixel intensity is // above the threshold if ((sum / (float) values.length) > sd_.threshold_) { observed.clear(); SaimUtils.organize(observed, sd_, values, anglesDegrees, anglesRadians); for (int i = 0; i < nrTries; i++) { try { double[] guess = new double[] { sd_.A_, sd_.B_, sd_.heights_[i] }; sff.setGuess(guess); results[i] = sff.fit(observed.getWeightedObservedPoints()); calculated.clear(); SaimUtils.predictValues(observed, calculated, results[i], sf); try { r2s[i] = SaimUtils.getRSquared(observed, calculated); } catch (InvalidInputException ex) { ij.IJ.log("Observed and Calculated datasets differe in size"); } } catch (TooManyIterationsException tiex) { for (int j = 0; j < 4; j++) { fpOut_[j].setf(x, y, Float.NaN); } r2s[i] = 0.0; ij.IJ.log("Failed to fit pixel " + x + ", " + y); } } final int bestIndex = SaimUtils.getIndexOfMaxValue(r2s); fpOut_[2].setf(x, y, (float) results[bestIndex][0]); // A fpOut_[3].setf(x, y, (float) results[bestIndex][1]); // B fpOut_[0].setf(x, y, (float) results[bestIndex][2]); // height fpOut_[1].setf(x, y, (float) r2s[bestIndex].doubleValue()); } } nrXProcessed_.getAndIncrement(); synchronized (nrXProcessed_) { ij.IJ.showProgress(nrXProcessed_.get(), width); } } } catch (InvalidInputException ex) { ij.IJ.error("Saim Fit", ex.getMessage()); } }
From source file:com.comcast.cdn.traffic_control.traffic_router.core.loc.Geolocation.java
/** * Returns the great circle distance in kilometers between this {@link Geolocation} and the * specified location/*www . j ava2 s .c o m*/ * * @param other * @return the great circle distance in km */ public double getDistanceFrom(final Geolocation other) { if (other != null) { final double dLat = Math.toRadians(getLatitude() - other.getLatitude()); final double dLon = Math.toRadians(getLongitude() - other.getLongitude()); final double a = (Math.sin(dLat / 2) * Math.sin(dLat / 2)) + (Math.cos(Math.toRadians(getLatitude())) * Math.cos(Math.toRadians(other.getLatitude())) * Math.sin(dLon / 2) * Math.sin(dLon / 2)); final double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return MEAN_EARTH_RADIUS * c; } else { return Double.POSITIVE_INFINITY; } }