List of usage examples for java.lang Math sin
@HotSpotIntrinsicCandidate public static double sin(double a)
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.RotationMatrixBuilder.java
/** * Returns a rotation matrix for rotating about the 2D plane defined by * the specified axes./* w w w. jav a2s. c o m*/ * * @param i the first axis * @param j the second axis * @param theta the rotation angle in radians * @return a rotation matrix for rotating about the 2D plane defined by * the specified axes */ private RealMatrix newRotationMatrix(int i, int j, double theta) { RealMatrix rotation = newIdentityMatrix(); rotation.setEntry(i, i, Math.cos(theta)); rotation.setEntry(i, j, -Math.sin(theta)); rotation.setEntry(j, i, Math.sin(theta)); rotation.setEntry(j, j, Math.cos(theta)); return rotation; }
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 .j ava 2 s . c om }
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.com*/ * * @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:org.jfree.experimental.chart.renderer.xy.VectorRenderer.java
/** * Draws the block representing the specified item. * //from www.ja v a 2 s. c o m * @param g2 the graphics device. * @param state the state. * @param dataArea the data area. * @param info the plot rendering info. * @param plot the plot. * @param domainAxis the x-axis. * @param rangeAxis the y-axis. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param crosshairState the crosshair state. * @param pass the pass index. */ public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double dx = 0.0; double dy = 0.0; if (dataset instanceof VectorXYDataset) { dx = ((VectorXYDataset) dataset).getDeltaXValue(series, item); dy = ((VectorXYDataset) dataset).getDeltaYValue(series, item); } double xx0 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); double yy0 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge()); double xx1 = domainAxis.valueToJava2D(x + dx, dataArea, plot.getDomainAxisEdge()); double yy1 = rangeAxis.valueToJava2D(y + dy, dataArea, plot.getRangeAxisEdge()); Line2D line; PlotOrientation orientation = plot.getOrientation(); if (orientation.equals(PlotOrientation.HORIZONTAL)) { line = new Line2D.Double(yy0, xx0, yy1, xx1); } else { line = new Line2D.Double(xx0, yy0, xx1, yy1); } g2.setPaint(getItemPaint(series, item)); g2.setStroke(getItemStroke(series, item)); g2.draw(line); // calculate the arrow head and draw it... double dxx = (xx1 - xx0); double dyy = (yy1 - yy0); double bx = xx0 + (1.0 - this.baseLength) * dxx; double by = yy0 + (1.0 - this.baseLength) * dyy; double cx = xx0 + (1.0 - this.headLength) * dxx; double cy = yy0 + (1.0 - this.headLength) * dyy; double angle = 0.0; if (dxx != 0.0) { angle = Math.PI / 2.0 - Math.atan(dyy / dxx); } double deltaX = 2.0 * Math.cos(angle); double deltaY = 2.0 * Math.sin(angle); double leftx = cx + deltaX; double lefty = cy - deltaY; double rightx = cx - deltaX; double righty = cy + deltaY; GeneralPath p = new GeneralPath(); p.moveTo((float) xx1, (float) yy1); p.lineTo((float) rightx, (float) righty); p.lineTo((float) bx, (float) by); p.lineTo((float) leftx, (float) lefty); p.closePath(); g2.draw(p); }
From source file:es.emergya.geo.util.Lambert.java
/** * Initializes from projected coordinates (conic projection). Note that * reference ellipsoid used by Lambert is Clark * * @param eastNorth projected coordinates pair in meters * @param Xs false east (coordinate system origin) in meters * @param Ys false north (coordinate system origin) in meters * @param c projection constant//from ww w . j a v a 2 s . c o m * @param n projection exponent * @return LatLon in radian */ private LatLon Geographic(EastNorth eastNorth, double Xs, double Ys, double c, double n) { double dx = eastNorth.east() - Xs; double dy = Ys - eastNorth.north(); double R = Math.sqrt(dx * dx + dy * dy); double gamma = Math.atan(dx / dy); double l = -1.0 / n * Math.log(Math.abs(R / c)); l = Math.exp(l); double lon = lg0 + gamma / n; double lat = 2.0 * Math.atan(l) - Math.PI / 2.0; double delta = 1.0; while (delta > epsilon) { double eslt = Ellipsoid.clarke.e * Math.sin(lat); double nlt = 2.0 * Math.atan(Math.pow((1.0 + eslt) / (1.0 - eslt), Ellipsoid.clarke.e / 2.0) * l) - Math.PI / 2.0; delta = Math.abs(nlt - lat); lat = nlt; } return new LatLon(lat, lon); // in radian }
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:com.eyekabob.util.EyekabobHelper.java
/** * Gets distance from current location to given lat/lon. * @param lat//from w ww . j av a 2s . co 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); }
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 va2 s .co m*/ LineChart(dataset, "Line", "axis x", "axis y", true, 0, 0); }
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 www .ja va 2s . 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:mrmc.chart.ROCCurvePlot.java
/** * Creates an ROC curve that averages together the scores for all readers in * the diagonal direction//w w w .j ava2 s. co m * * @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; }