List of usage examples for java.lang Math cos
@HotSpotIntrinsicCandidate public static double cos(double a)
From source file:geogebra.common.kernel.geos.GeoVec2D.java
/** * mirror transform with angle phi [ cos(phi) sin(phi) ] [ sin(phi) * -cos(phi) ]/* w w w. j a va2 s . c o m*/ * * @param phi * parameter */ final public void mirror(double phi) { double cos = Math.cos(phi); double sin = Math.sin(phi); double x0 = x * cos + y * sin; y = x * sin - y * cos; x = x0; }
From source file:com.net2plan.libraries.GraphUtils.java
/** Computes the Haversine distance between two points, that is, the shortest distance over the Earth's surface. * /*from w w w. j a va 2s . c o m*/ * <p><b>Important</b>: It is assumed an Earth's radius equal to {@link com.net2plan.utils.Constants#EARTH_RADIUS_IN_KM Constants.EARTH_RADIUS_IN_KM }</p> * * <p><b>Important</b>: Coordinates are assumed to be given in degress, conversions to radians are made internally.</p> * * @param point1 Point 1 (x-coord is equal to longitude, y-coord is equal to latitude) * @param point2 Point 2 (x-coord is equal to longitude, y-coord is equal to latitude) * @return Haversine distance between two points * @see <a href="http://www.movable-type.co.uk/scripts/latlong.html">Calculate distance, bearing and more between Latitude/Longitude points</a> */ public static double computeHaversineDistanceInKm(Point2D point1, Point2D point2) { double lon1 = point1.getX(); double lat1 = point1.getY(); double lon2 = point2.getX(); double lat2 = point2.getY(); double dLat = Math.toRadians(lat2 - lat1); double dLon = Math.toRadians(lon2 - lon1); double sindLat = Math.sin(dLat / 2); double sindLon = Math.sin(dLon / 2); double a = Math.pow(sindLat, 2) + Math.pow(sindLon, 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return Constants.EARTH_RADIUS_IN_KM * c; }
From source file:eu.vital.orchestrator.rest.EvaluationRESTService.java
private double distance(double lat1, double lon1, double lat2, double lon2) { int R = 6371; // Radius of the earth in km double dLat = deg2rad(lat2 - lat1); // deg2rad below double dLon = deg2rad(lon2 - lon1); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double d = R * c; // Distance in km return d;//from w w w .java2s . co m }
From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java
@Test public void cosPi() { try {//from ww w.j a v a2 s.com Expression expression = getExpressionWithFunctionContext("cos(pi)"); assertEquals(ExpressionType.DOUBLE, expression.getExpressionType()); assertEquals(Math.cos(Math.PI), expression.evaluateNumerical(), 1e-15); } catch (ExpressionException e) { assertNotNull(e.getMessage()); } }
From source file:com.buzz.buzzdata.MongoBuzz.java
public double haversine(double lat1, double lng1, double lat2, double lng2) { double r = 6371 / 1.6; // average radius of the earth in miles double dLat = Math.toRadians(lat2 - lat1); double dLon = 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(dLon / 2) * Math.sin(dLon / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double d = r * c; return round(d, 1); }
From source file:PathLength.java
/** * Returns the point that is at the given length along the path. * @param length The length along the path * @return The point at the given length *//*from w w w. j a v a 2 s.c o m*/ public Point2D pointAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return null; } PathSegment upper = (PathSegment) segments.get(upperIndex); if (upperIndex == 0) { // Length was probably zero, so return the upper point. return new Point2D.Float(upper.getX(), upper.getY()); } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); // Now work out where along the line would be the length. float offset = length - lower.getLength(); // Compute the slope. double theta = Math.atan2(upper.getY() - lower.getY(), upper.getX() - lower.getX()); float xPoint = (float) (lower.getX() + offset * Math.cos(theta)); float yPoint = (float) (lower.getY() + offset * Math.sin(theta)); return new Point2D.Float(xPoint, yPoint); }
From source file:com.duy.pascal.interperter.libraries.math.MathLib.java
@PascalMethod(description = "") public double Secant(double x) { return 1 / Math.cos(x); }
From source file:charts.Chart.java
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed DefaultCategoryDataset dataset = new DefaultCategoryDataset(); double x = 2; double y = 2; double teta = 5; double p = 5; for (teta = 1; teta < 5; teta++) { p = x * Math.cos(teta) + y * Math.sin(teta); dataset.addValue(p, "teta=5", String.valueOf(teta)); }/*from w w w . j a v a 2 s. com*/ LineChart(dataset, "Line", "axis x", "axis y", true, 0, 0); }
From source file:mrmc.chart.ROCCurvePlot.java
/** * Creates an ROC curve that averages together the scores for all readers in * the diagonal direction// w ww. j ava 2 s.c om * * @param treeMap Mapping of readers to points defining a curve * @return Series containing the ROC curve points */ private XYSeries generateDiagonalROC(TreeMap<String, TreeSet<XYPair>> treeMap) { XYSeries diagAvg = new XYSeries("Diagonal Average", false); TreeMap<String, TreeSet<XYPair>> rotatedData = new TreeMap<String, TreeSet<XYPair>>(); // rotate all points in data 45 degrees clockwise about origin for (String r : treeMap.keySet()) { rotatedData.put(r, new TreeSet<XYPair>()); for (XYPair point : treeMap.get(r)) { double x2 = (point.x + point.y) / Math.sqrt(2.0); double y2 = (point.y - point.x) / Math.sqrt(2.0); rotatedData.get(r).add(new XYPair(x2, y2)); } } // generate linear interpolation with new points ArrayList<InterpolatedLine> rotatedLines = new ArrayList<InterpolatedLine>(); for (String r : rotatedData.keySet()) { rotatedLines.add(new InterpolatedLine(rotatedData.get(r))); } // take vertical sample averages from x = 0 to x = 1 for (double i = 0; i <= Math.sqrt(2); i += 0.01) { double avg = 0; int counter = 0; for (InterpolatedLine line : rotatedLines) { avg += line.getYatDiag(i); counter++; } // rotate points back 45 degrees counterclockwise double x1 = i; double y1 = (avg / (double) counter); double x2 = (x1 * Math.cos(Math.toRadians(45))) - (y1 * Math.sin(Math.toRadians(45))); double y2 = (x1 * Math.sin(Math.toRadians(45))) + (y1 * Math.cos(Math.toRadians(45))); diagAvg.add(x2, y2); } diagAvg.add(1, 1); return diagAvg; }
From source file:com.eyekabob.util.EyekabobHelper.java
/** * Gets distance from current location to given lat/lon. * @param lat//from w w w .j av a2s . c o m * @param lon * @param context * @return */ public static long getDistance(double lat, double lon, Context context) { Location location = EyekabobHelper.getLocation(context); if (location == null) { return -1; } double currentLat = location.getLatitude(); double currentLon = location.getLongitude(); int R = 3959; // Earth radius in miles. double dLat = Math.toRadians(currentLat - lat); double dLon = Math.toRadians(currentLon - lon); lat = Math.toRadians(lat); currentLat = Math.toRadians(currentLat); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat) * Math.cos(currentLat); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return Math.round(R * c); }