List of usage examples for java.lang Math toRadians
public static double toRadians(double angdeg)
From source file:com.duy.pascal.interperter.libraries.math.MathLib.java
@PascalMethod(description = "") public double DegToRad(double deg) { return Math.toRadians(deg); }
From source file:org.interpss.numeric.datatype.ComplexFunc.java
/** * Angle function, return the angle in rad of this obj * /* w w w . j a v a2s . c o m*/ * @return the resulting angle in rad */ public static double arg(final Complex c) { // the angle in the plane in rad if (c.getReal() == 0.0) { if (c.getImaginary() > 0.0) { return Math.toRadians(90.0); } else if (c.getImaginary() < 0.0) { return Math.toRadians(-90.0); } else { return 0.0; } } else { double ang = Math.atan(c.getImaginary() / c.getReal()); if (c.getReal() < 0.0) ang += Math.PI; return ang; } }
From source file:no.met.jtimeseries.chart.XYWindArrowRenderer.java
/** * Draws the visual representation of a single wind arrow. *///from ww w .j a v a 2 s.com @Override public void drawItem(Graphics2D g2d, XYItemRendererState state, Rectangle2D plotArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { resizeArrowByPlotHeight((int) plotArea.getHeight()); // Needs a new graphics object to use translate() and rotate() Graphics2D g2 = (Graphics2D) g2d.create(); g2.setRenderingHints(renderHints); RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); double middleY = plotArea.getCenterY(); WindDataset windData = (WindDataset) dataset; Number x = windData.getX(series, item); Number windDir = windData.getWindDirection(series, item); Number wforce = windData.getWindForce(series, item); double middleX = domainAxis.valueToJava2D(x.doubleValue(), plotArea, domainAxisLocation); g2.translate((int) middleX, (int) middleY); g2.setColor(Color.BLACK); if (wforce.doubleValue() <= zeroWindLimit) { drawCircle(g2); } else { g2.rotate(Math.toRadians(windDir.doubleValue() - 180)); drawArrow(g2, wforce.doubleValue()); if (useArrowHead) { g2.fill(getPolygonHead(arrowHeadSize, arrowHeight)); } else { g2.draw(getCircleHead(arrowHeadSize, arrowHeight)); } } }
From source file:org.opentripplanner.common.geometry.SphericalDistanceLibrary.java
/** * Equirectangular project a polyline./* www .j a va 2 s . com*/ * @param lineString * @param cosLat cos(lat) of the projection center point. * @return The projected polyline. Coordinates in radians. */ private LineString equirectangularProject(LineString lineString, double cosLat) { Coordinate[] coords = lineString.getCoordinates(); Coordinate[] coords2 = new Coordinate[coords.length]; for (int i = 0; i < coords.length; i++) { coords2[i] = new Coordinate(Math.toRadians(coords[i].x) * cosLat, Math.toRadians(coords[i].y)); } return GeometryUtils.getGeometryFactory().createLineString(coords2); }
From source file:com.grayfox.server.service.PoiService.java
private double distanceBetween(Location location1, Location location2) { double fi1 = Math.toRadians(location1.getLatitude()); double fi2 = Math.toRadians(location2.getLatitude()); double deltaLambda = Math.toRadians(location2.getLongitude() - location1.getLongitude()); return Math.acos(Math.sin(fi1) * Math.sin(fi2) + Math.cos(fi1) * Math.cos(fi2) * Math.cos(deltaLambda)) * Constants.Ints.EARTH_RADIUS; }
From source file:org.nuxeo.pdf.service.PDFTransformationServiceImpl.java
@Override public Blob applyTextWatermark(Blob input, String text, WatermarkProperties properties) { // Set up the graphic state to handle transparency // Define a new extended graphic state PDExtendedGraphicsState extendedGraphicsState = new PDExtendedGraphicsState(); // Set the transparency/opacity extendedGraphicsState.setNonStrokingAlphaConstant((float) properties.getAlphaColor()); try (PDDocument pdfDoc = PDDocument.load(input.getStream())) { PDFont font = PDType1Font.getStandardFont(properties.getFontFamily()); float watermarkWidth = (float) (font.getStringWidth(text) * properties.getFontSize() / 1000f); int[] rgb = PDFUtils.hex255ToRGB(properties.getHex255Color()); for (Object o : pdfDoc.getDocumentCatalog().getAllPages()) { PDPage page = (PDPage) o;// w w w .j ava2 s . c om PDRectangle pageSize = page.findMediaBox(); PDResources resources = page.findResources(); // Get the defined graphic states. HashMap<String, PDExtendedGraphicsState> graphicsStateDictionary = (HashMap<String, PDExtendedGraphicsState>) resources .getGraphicsStates(); if (graphicsStateDictionary != null) { graphicsStateDictionary.put("TransparentState", extendedGraphicsState); resources.setGraphicsStates(graphicsStateDictionary); } else { Map<String, PDExtendedGraphicsState> m = new HashMap<>(); m.put("TransparentState", extendedGraphicsState); resources.setGraphicsStates(m); } try (PDPageContentStream contentStream = new PDPageContentStream(pdfDoc, page, true, true, true)) { contentStream.beginText(); contentStream.setFont(font, (float) properties.getFontSize()); contentStream.appendRawCommands("/TransparentState gs\n"); contentStream.setNonStrokingColor(rgb[0], rgb[1], rgb[2]); Point2D position = computeTranslationVector(pageSize.getWidth(), watermarkWidth, pageSize.getHeight(), properties.getFontSize(), properties); contentStream.setTextRotation(Math.toRadians(properties.getTextRotation()), position.getX(), position.getY()); contentStream.drawString(text); contentStream.endText(); } } return saveInTempFile(pdfDoc); } catch (Exception e) { throw new NuxeoException(e); } }
From source file:de.bund.bfr.knime.openkrise.util.cluster.DBSCANNodeModel.java
/** * {@inheritDoc}//from w w w . ja va 2 s . c o m */ @Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { BufferedDataTable table = inData[0]; DataTableSpec spec = table.getSpec(); TracingUtils.assertColumnNotMissing(spec, TracingColumns.ID, null); TracingUtils.assertColumnNotMissing(spec, GeocodingNodeModel.LATITUDE_COLUMN, null); TracingUtils.assertColumnNotMissing(spec, GeocodingNodeModel.LONGITUDE_COLUMN, null); NodePropertySchema nodeSchema = new NodePropertySchema(TracingUtils.getTableColumns(table.getSpec()), TracingColumns.ID); Collection<GraphNode> nodes = TracingUtils.readGraphNodes(table, nodeSchema).values(); Set<String> filteredOut = new LinkedHashSet<>(); if (set.getFilter() != null) { set.getFilter().getValues(nodes).forEach((node, value) -> { if (value == 0.0) { filteredOut.add(node.getId()); } }); } List<ClusterableRow> clusterableRows = new ArrayList<>(); for (DataRow row : table) { String id = IO.getToCleanString(row.getCell(spec.findColumnIndex(TracingColumns.ID))); Double lat = IO.getDouble(row.getCell(spec.findColumnIndex(GeocodingNodeModel.LATITUDE_COLUMN))); Double lon = IO.getDouble(row.getCell(spec.findColumnIndex(GeocodingNodeModel.LONGITUDE_COLUMN))); if (id == null || lat == null || lon == null || filteredOut.contains(id)) { continue; } clusterableRows.add(new ClusterableRow(row.getKey(), Math.toRadians(lat), Math.toRadians(lon))); } List<? extends Cluster<ClusterableRow>> clusters; if (set.getModel().equals(DBSCANNSettings.MODEL_DBSCAN)) { clusters = new DBSCANClusterer<ClusterableRow>(set.getMaxDistance(), set.getMinPoints(), new HaversineDistance()).cluster(clusterableRows); } else if (set.getModel().equals(DBSCANNSettings.MODEL_K_MEANS)) { clusters = new MultiKMeansPlusPlusClusterer<ClusterableRow>( new KMeansPlusPlusClusterer<>(set.getNumClusters(), -1, new HaversineDistance()), 5) .cluster(clusterableRows); } else { throw new InvalidSettingsException(set.getModel()); } Map<RowKey, Integer> clusterIds = new LinkedHashMap<>(); for (int i = 0; i < clusters.size(); i++) { for (ClusterableRow r : clusters.get(i).getPoints()) { clusterIds.put(r.getKey(), i); } } DataTableSpec outSpec = createSpec(spec); BufferedDataContainer container = exec.createDataContainer(outSpec); for (DataRow row : table) { DataCell[] cells = new DataCell[outSpec.getNumColumns()]; for (String column : spec.getColumnNames()) { cells[outSpec.findColumnIndex(column)] = row.getCell(spec.findColumnIndex(column)); } cells[outSpec.findColumnIndex(TracingColumns.CLUSTER_ID)] = IO.createCell(clusterIds.get(row.getKey())); container.addRowToTable(new DefaultRow(row.getKey(), cells)); exec.checkCanceled(); } container.close(); return new BufferedDataTable[] { container.getTable() }; }
From source file:org.openhab.core.library.types.PointType.java
/** * Return the distance in meters from otherPoint, ignoring altitude. This algorithm also * ignores the oblate spheroid shape of Earth and assumes a perfect sphere, so results * are inexact./*from w w w. j a v a 2 s . c o m*/ * * @param otherPoint * @return distance in meters * @see <a href="https://en.wikipedia.org/wiki/Haversine_formula">Haversine formula</a> */ public DecimalType distanceFrom(PointType otherPoint) { double dLat = Math.toRadians(otherPoint.latitude.doubleValue() - this.latitude.doubleValue()); double dLong = Math.toRadians(otherPoint.longitude.doubleValue() - this.longitude.doubleValue()); double a = Math.pow(Math.sin(dLat / 2D), 2D) + Math.cos(Math.toRadians(this.latitude.doubleValue())) * Math.cos(Math.toRadians(otherPoint.latitude.doubleValue())) * Math.pow(Math.sin(dLong / 2D), 2D); double c = 2D * Math.atan2(Math.sqrt(a), Math.sqrt(1D - a)); return new DecimalType(WGS84_a * c); }
From source file:dz.alkhwarizmix.winrak.java.model.vo.WinrakPosition.java
/** * http://www.movable-type.co.uk/scripts/latlong.html *///from w ww . j a v a 2 s.c o m @Override public int distanceTo(final IWinrakPosition pos2) { final WinrakPosition pos1 = this; final Double R = 6371000.0; // metres final Double radLat1 = Math.toRadians(pos1.getLat()); final Double radLat2 = Math.toRadians(pos2.getLat()); final Double deltaLat = Math.toRadians(pos2.getLat() - pos1.getLat()); final Double deltaLng = Math.toRadians(pos2.getLng() - pos1.getLng()); final Double a = (Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2)) + (Math.cos(radLat1) * Math.cos(radLat2) * Math.sin(deltaLng / 2) * Math.sin(deltaLng / 2)); final Double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); final Double d = R * c; return (d.intValue()); }
From source file:ActualizadorLocal.Clientes.ClienteNodos.java
public void procesarDatos(String datos) throws SQLException { //Preprocesamos los datos, para darle un nombre al array: datos = "{\"nodos\":" + datos + "}"; JSONParser parser = new JSONParser(); try {/*from w w w .ja v a 2 s . co m*/ JSONObject obj = (JSONObject) parser.parse(datos); JSONArray lista = (JSONArray) obj.get("nodos"); for (int i = 0; i < lista.size(); i++) { long a0 = (long) ((JSONObject) lista.get(i)).get("idNodo"); String a1 = (String) ((JSONObject) lista.get(i)).get("nombre"); double a2 = (double) ((JSONObject) lista.get(i)).get("latitud"); double a3 = (double) ((JSONObject) lista.get(i)).get("longitud"); nodos.add(a0); //Tenemos que calcular el polgono para la visualizacin de los datos mediante GOOGLE FUSION TABLES: double lat = Math.toRadians(new Double(a2)); double lon = Math.toRadians(new Double(a3)); double radio = 50.0 / 6378137.0; String cadena_poligono = "<Polygon><outerBoundaryIs><LinearRing><coordinates>"; for (int j = 0; j <= 360; j = j + 15) { double r = Math.toRadians(j); double lat_rad = Math .asin(Math.sin(lat) * Math.cos(radio) + Math.cos(lat) * Math.sin(radio) * Math.cos(r)); double lon_rad = Math.atan2(Math.sin(r) * Math.sin(radio) * Math.cos(lat), Math.cos(radio) - Math.sin(lat) * Math.sin(lat_rad)); double lon_rad_f = ((lon + lon_rad + Math.PI) % (2 * Math.PI)) - Math.PI; cadena_poligono = cadena_poligono + Math.toDegrees(lon_rad_f) + "," + Math.toDegrees(lat_rad) + ",0.0 "; } cadena_poligono = cadena_poligono + "</coordinates></LinearRing></outerBoundaryIs></Polygon>"; this.InsertarDatos("\"" + (String) Long.toString(a0) + "\",\"" + a1 + "\",\"" + Double.toString(a2) + "\",\"" + Double.toString(a3) + "\",\"" + cadena_poligono + "\""); } } catch (Exception e) { System.err.println(e.getMessage()); } syncDB(); }