List of usage examples for java.lang Math cos
@HotSpotIntrinsicCandidate public static double cos(double a)
From source file:es.udc.gii.common.eaf.benchmark.multiobjective.wfg.Wfg_Objective.java
protected double s_multi(double y, int A, double B, double C) { double tmp1 = Math.abs(y - C) / (2.0 * (Math.floor(C - y) + C)); double tmp2 = (4.0 * A + 2.0) * Math.PI * (0.5 - tmp1); return correct_to_01((1.0 + Math.cos(tmp2) + 4.0 * B * Math.pow(tmp1, 2.0)) / (B + 2.0), EPSILON); }
From source file:org.jfree.eastwood.GXYPlot.java
/** * Draws the background for the plot.//w w w . ja va 2s . c o m * * @param g2 the graphics device. * @param area the area. */ public void drawBackground(Graphics2D g2, Rectangle2D area) { Paint p = getBackgroundPaint(); if (p instanceof GradientPaint) { // do the transformation directly GradientPaint gp = (GradientPaint) p; double r = (this.f1 - this.f0) * area.getWidth(); Point2D p0 = new Point2D.Double(area.getMinX() + this.f0 * area.getWidth(), area.getMaxY()); Point2D p1 = new Point2D.Double(p0.getX() + r * Math.cos(this.angle), p0.getY() - r * Math.sin(this.angle)); p = new GradientPaint(p0, gp.getColor1(), p1, gp.getColor2()); } g2.setPaint(p); g2.fill(area); }
From source file:com.esri.geoevent.solutions.processor.geometry.RangeFanProcessor.java
private Geometry constructRangeFan(double x, double y, double range, String unit, double bearing, double traversal) throws GeometryException { Polygon fan = new Polygon(); Point center = new Point(); center.setX(x);// w w w . j ava 2s . c om center.setY(y); // SpatialReference srIn = SpatialReference.create(wkidin); // SpatialReference srBuffer = SpatialReference.create(wkidbuffer); // SpatialReference srOut = SpatialReference.create(wkidout); Point centerProj = (Point) GeometryEngine.project(center, srIn, srBuffer); double centerX = centerProj.getX(); double centerY = centerProj.getY(); bearing = GeometryUtility.Geo2Arithmetic(bearing); double leftAngle = bearing - (traversal / 2); double rightAngle = bearing + (traversal / 2); int count = (int) Math.round(Math.abs(leftAngle - rightAngle)); fan.startPath(centerProj); UnitConverter uc = new UnitConverter(); range = uc.Convert(range, unit, srBuffer); for (int i = 0; i < count; ++i) { double d = Math.toRadians(leftAngle + i); double arcX = centerX + (range * Math.cos(d)); double arcY = centerY + (range * Math.sin(d)); Point arcPt = new Point(arcX, arcY); // arcPt = (Point) GeometryEngine.project(arcPt, srBuffer, srOut); fan.lineTo(arcPt); } fan.closeAllPaths(); return fan; }
From source file:com.bdb.weather.display.windplot.WindItemRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device.//from w w w .java 2 s.c om * @param rendererState the renderer state. * @param dataArea the area within which the data is being drawn. * @param info collects information about the drawing. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState rendererState, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // // Let the base class handle drawing the line and the shapes (passes 0 and 1). This class will handle drawing the // wind direction lines. // if (pass < 2) super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); else { if (!(dataset instanceof TimeSeriesCollection) || !showWindDirectionLines) return; if (item == 0) state.resetLastDirection(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); TimeSeriesCollection collection = (TimeSeriesCollection) dataset; TimeSeries timeSeries = collection.getSeries(series); if (!(timeSeries instanceof WindSeries)) return; WindSeries windSeries = (WindSeries) timeSeries; WindSeriesDataItem windItem = windSeries.getWindDataItem(item); double speed = windItem.getWindSpeed().doubleValue(); double time = dataset.getXValue(series, item); double dir = windItem.getWindDirection().doubleValue(); if (speed > 0.0 && dir != state.getLastDirection()) { state.setLastDirection(dir); double radians = Math.toRadians(dir - 90.0); double dirXOffset = directionLineLength * Math.cos(radians); double dirYOffset = directionLineLength * Math.sin(radians); double transTime = domainAxis.valueToJava2D(time, dataArea, xAxisLocation); double transSpeed = rangeAxis.valueToJava2D(speed, dataArea, yAxisLocation); double dirX = transTime + dirXOffset; double dirY = transSpeed + dirYOffset; // update path to reflect latest point if (!Double.isNaN(transTime) && !Double.isNaN(transSpeed)) { int x1 = (int) transTime; int y1 = (int) transSpeed; int x2 = (int) dirX; int y2 = (int) dirY; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { x1 = (int) transSpeed; y1 = (int) transTime; x2 = (int) dirY; y2 = (int) dirX; } g2.setPaint(windDirectionPaint); g2.setStroke(windDirectionStroke); g2.drawLine(x1, y1, x2, y2); } } } }
From source file:geogebra.common.kernel.geos.GeoVec2D.java
/** * @param r/*from w ww . jav a 2 s.co m*/ * radius * @param phi * phase */ public void setPolarCoords(double r, double phi) { x = r * Math.cos(phi); y = r * Math.sin(phi); }
From source file:com.nextbreakpoint.nextfractal.mandelbrot.core.Expression.java
public static Number funcSin(MutableNumber out, Number x) { return out.set(Math.sin(x.r()) * Math.cosh(x.i()), +Math.cos(x.r()) * Math.sinh(x.i())); }
From source file:edu.umn.cs.spatialHadoop.nasa.SpatioTemporalAggregateQuery.java
/** * Performs a spatio-temporal aggregate query on an indexed directory * @param inFile/*from w ww .jav a 2s .c om*/ * @param params * @throws ParseException * @throws IOException */ public static AggregateQuadTree.Node aggregateQuery(Path inFile, OperationsParams params) throws ParseException, IOException { // 1- Run a temporal filter step to find all matching temporal partitions Vector<Path> matchingPartitions = new Vector<Path>(); // List of time ranges to check. Initially it contains one range as // specified by the user. Eventually, it can be split into at most two // partitions if partially matched by a partition. Vector<TimeRange> temporalRanges = new Vector<TimeRange>(); temporalRanges.add(new TimeRange(params.get("time"))); Path[] temporalIndexes = new Path[] { new Path(inFile, "yearly"), new Path(inFile, "monthly"), new Path(inFile, "daily") }; int index = 0; final FileSystem fs = inFile.getFileSystem(params); while (index < temporalIndexes.length && !temporalRanges.isEmpty()) { Path indexDir = temporalIndexes[index]; LOG.info("Checking index dir " + indexDir); TemporalIndex temporalIndex = new TemporalIndex(fs, indexDir); for (int iRange = 0; iRange < temporalRanges.size(); iRange++) { TimeRange range = temporalRanges.get(iRange); TemporalPartition[] matches = temporalIndex.selectContained(range.start, range.end); if (matches != null) { LOG.info("Matched " + matches.length + " partitions in " + indexDir); for (TemporalPartition match : matches) { LOG.info("Matched temporal partition: " + match.dirName); matchingPartitions.add(new Path(indexDir, match.dirName)); } // Update range to remove matching part TemporalPartition firstMatch = matches[0]; TemporalPartition lastMatch = matches[matches.length - 1]; if (range.start < firstMatch.start && range.end > lastMatch.end) { // Need to split the range into two temporalRanges.setElementAt(new TimeRange(range.start, firstMatch.start), iRange); temporalRanges.insertElementAt(new TimeRange(lastMatch.end, range.end), iRange); } else if (range.start < firstMatch.start) { // Update range in-place range.end = firstMatch.start; } else if (range.end > lastMatch.end) { // Update range in-place range.start = lastMatch.end; } else { // Current range was completely covered. Remove it temporalRanges.remove(iRange); } } } index++; } numOfTemporalPartitionsInLastQuery = matchingPartitions.size(); // 2- Find all matching files (AggregateQuadTrees) in matching partitions final Rectangle spatialRange = params.getShape("rect", new Rectangle()).getMBR(); // Convert spatialRange from lat/lng space to Sinusoidal space double cosPhiRad = Math.cos(spatialRange.y1 * Math.PI / 180); double southWest = spatialRange.x1 * cosPhiRad; double southEast = spatialRange.x2 * cosPhiRad; cosPhiRad = Math.cos(spatialRange.y2 * Math.PI / 180); double northWest = spatialRange.x1 * cosPhiRad; double northEast = spatialRange.x2 * cosPhiRad; spatialRange.x1 = Math.min(northWest, southWest); spatialRange.x2 = Math.max(northEast, southEast); // Convert to the h v space used by MODIS spatialRange.x1 = (spatialRange.x1 + 180.0) / 10.0; spatialRange.x2 = (spatialRange.x2 + 180.0) / 10.0; spatialRange.y2 = (90.0 - spatialRange.y2) / 10.0; spatialRange.y1 = (90.0 - spatialRange.y1) / 10.0; // Vertically flip because the Sinusoidal space increases to the south double tmp = spatialRange.y2; spatialRange.y2 = spatialRange.y1; spatialRange.y1 = tmp; // Find the range of cells in MODIS Sinusoidal grid overlapping the range final int h1 = (int) Math.floor(spatialRange.x1); final int h2 = (int) Math.ceil(spatialRange.x2); final int v1 = (int) Math.floor(spatialRange.y1); final int v2 = (int) Math.ceil(spatialRange.y2); PathFilter rangeFilter = new PathFilter() { @Override public boolean accept(Path p) { Matcher matcher = MODISTileID.matcher(p.getName()); if (!matcher.matches()) return false; int h = Integer.parseInt(matcher.group(1)); int v = Integer.parseInt(matcher.group(2)); return h >= h1 && h < h2 && v >= v1 && v < v2; } }; final Vector<Path> allMatchingFiles = new Vector<Path>(); for (Path matchingPartition : matchingPartitions) { // Select all matching files FileStatus[] matchingFiles = fs.listStatus(matchingPartition, rangeFilter); for (FileStatus matchingFile : matchingFiles) { allMatchingFiles.add(matchingFile.getPath()); } } // 3- Query all matching files in parallel Vector<Node> threadsResults = Parallel.forEach(allMatchingFiles.size(), new RunnableRange<AggregateQuadTree.Node>() { @Override public Node run(int i1, int i2) { Node threadResult = new AggregateQuadTree.Node(); for (int i_file = i1; i_file < i2; i_file++) { try { Path matchingFile = allMatchingFiles.get(i_file); Matcher matcher = MODISTileID.matcher(matchingFile.getName()); matcher.matches(); // It has to match int h = Integer.parseInt(matcher.group(1)); int v = Integer.parseInt(matcher.group(2)); // Clip the query region and normalize in this tile Rectangle translated = spatialRange.translate(-h, -v); int x1 = (int) (Math.max(translated.x1, 0) * 1200); int y1 = (int) (Math.max(translated.y1, 0) * 1200); int x2 = (int) (Math.min(translated.x2, 1.0) * 1200); int y2 = (int) (Math.min(translated.y2, 1.0) * 1200); AggregateQuadTree.Node fileResult = AggregateQuadTree.aggregateQuery(fs, matchingFile, new java.awt.Rectangle(x1, y1, (x2 - x1), (y2 - y1))); threadResult.accumulate(fileResult); } catch (IOException e) { e.printStackTrace(); } } return threadResult; } }); AggregateQuadTree.Node finalResult = new AggregateQuadTree.Node(); for (Node threadResult : threadsResults) finalResult.accumulate(threadResult); numOfTreesTouchesInLastRequest = allMatchingFiles.size(); return finalResult; }
From source file:graph.GraphExplorer.java
/** * create an instance of a simple graph with popup controls to * create a graph.//from w w w . j av a 2 s .c om * */ public GraphExplorer(Synset synset) { // create a simple graph for the demo // graph = new SparseMultigraph<Gnode,String>(); map = new HashMap<Synset, Gnode>(); Graph<Gnode, Gedge> ig = Graphs .<Gnode, Gedge>synchronizedDirectedGraph(new DirectedSparseMultigraph<Gnode, Gedge>()); ObservableGraph<Gnode, Gedge> og = new ObservableGraph<Gnode, Gedge>(ig); graph = og; this.layout = new SpringLayout<Gnode, Gedge>(graph, new ConstantTransformer(EDGE_LENGTH)); Dimension d = new Dimension(HEIGHT, WIDTH); layout.setSize(d); vv = new VisualizationViewer<Gnode, Gedge>(layout); vv.setBackground(Color.white); GraphMouse gm = new DefaultModalGraphMouse<Gnode, String>(); vv.setGraphMouse(gm); GraphMouseListener<Gnode> gml = new GraphMouseListener<Gnode>() { @Override public void graphClicked(Gnode gnode, java.awt.event.MouseEvent me) { System.out.println(gnode.synset.toString()); if (!gnode.extended) { layout.lock(true); Relaxer relaxer = vv.getModel().getRelaxer(); relaxer.pause(); gnode.extended = true; double x = layout.getX(gnode); double y = layout.getY(gnode); SynsetPointer[] sp = gnode.synset.getPointers(); for (int i = 0; i < sp.length; ++i) { Synset synset_ = DataManager.getSingleton().getSynset(sp[i].getSynsetOffset(), sp[i].getPartOfSpeech()); if (map.get(synset_) == null) map.put(synset_, new Gnode(synset_)); graph.addEdge(new Gedge(sp[i].getPointerSymbol().getDescription()), gnode, map.get(synset_)); layout.setLocation(map.get(synset_), x + 0.5 * EDGE_LENGTH * Math.cos(Math.PI * 2 / sp.length * i), y + 0.5 * EDGE_LENGTH * Math.sin(Math.PI * 2 / sp.length * i)); } layout.initialize(); relaxer.resume(); layout.lock(false); } } @Override public void graphPressed(Gnode arg0, java.awt.event.MouseEvent arg1) { } @Override public void graphReleased(Gnode arg0, java.awt.event.MouseEvent arg1) { } }; vv.addGraphMouseListener(gml); Transformer<Gnode, Paint> vertexPaint = new Transformer<Gnode, Paint>() { public Paint transform(Gnode i) { coloring.Color color = ColorManager.getSingleton().getColor(i.synset); return new Color(color.getR(), color.getG(), color.getB()); } }; vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); /* Transformer<Gnode,Font> vertexFont = new Transformer<Gnode,Font>() { public Font transform(Gnode i) { Map<java.awt.font.TextAttribute,Paint> map= new HashMap<java.awt.font.TextAttribute,Paint>(); map.put(java.awt.font.TextAttribute.BACKGROUND, new Color(255,255,255)); return new Font(map); } }; vv.getRenderContext().setVertexFontTransformer(vertexFont);*/ Transformer<Gnode, Shape> vertexShape = new Transformer<Gnode, Shape>() { public Shape transform(Gnode i) { float len = (float) (Math.log(i.synset.getWordCount()) * 10 + 50); return new Ellipse2D.Float(-len / 2, -len / 2, len, len); } }; vv.getRenderContext().setVertexShapeTransformer(vertexShape); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Gnode>()); vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<Gedge>()); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); Relaxer relaxer = vv.getModel().getRelaxer(); relaxer.pause(); if (map.get(synset) == null) map.put(synset, new Gnode(synset)); graph.addVertex(map.get(synset)); System.out.println(map.get(synset).synset.toString()); map.get(synset).extended = true; layout.setLocation(map.get(synset), HEIGHT / 2, WIDTH / 2); SynsetPointer[] sp = synset.getPointers(); for (int i = 0; i < sp.length; ++i) { Synset synset_ = DataManager.getSingleton().getSynset(sp[i].getSynsetOffset(), sp[i].getPartOfSpeech()); if (map.get(synset_) == null) map.put(synset_, new Gnode(synset_)); graph.addEdge(new Gedge(sp[i].getPointerSymbol().getDescription()), map.get(synset), map.get(synset_)); layout.setLocation(map.get(synset_), HEIGHT / 2 + EDGE_LENGTH * Math.cos(Math.PI * 2 / sp.length * i), WIDTH / 2 + Math.sin(Math.PI * 2 / sp.length * i)); } layout.initialize(); relaxer.resume(); getContentPane().add(vv); }
From source file:com.nextbreakpoint.nextfractal.mandelbrot.core.Expression.java
public static Number funcCos(MutableNumber out, Number x) { return out.set(Math.cos(x.r()) * Math.cosh(x.i()), -Math.sin(x.r()) * Math.sinh(x.i())); }
From source file:com.nextbreakpoint.nextfractal.mandelbrot.core.Expression.java
public static Number funcTan(MutableNumber out, Number x) { double d = Math.pow(Math.cos(x.r()), 2) + Math.pow(Math.sinh(x.i()), 2); return out.set((Math.sin(x.r()) * Math.cos(x.r())) / d, (Math.sinh(x.i()) * Math.cosh(x.i())) / d); }