List of usage examples for java.lang Math PI
double PI
To view the source code for java.lang Math PI.
Click Source Link
From source file:org.neo4j.bench.chart.JFreeBarChart.java
@Override protected JFreeChart createChart(AbstractDataset dataset) { JFreeChart chart = ChartFactory.createBarChart("Performance chart", "Bench case", "Time(s)", (DefaultCategoryDataset) dataset, PlotOrientation.VERTICAL, true, true, false); rotateCategoryAxis(chart, Math.PI / 4.0); CategoryPlot plot = chart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setItemLabelGenerator(new CategoryItemLabelGenerator() { public String generateColumnLabel(CategoryDataset dataset, int column) { return "col" + column; }/*from w ww . java 2s .com*/ public String generateLabel(CategoryDataset dataset, int row, int column) { return "" + dataset.getValue(row, column).intValue(); } public String generateRowLabel(CategoryDataset dataset, int row) { return "row" + row; } }); renderer.setBaseItemLabelPaint(Color.black); renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0)); renderer.setItemLabelsVisible(true); return chart; }
From source file:net.sf.dsp4j.octave.packages.signal_1_0_11.Butter.java
private Butter(int n, double[] w, boolean digital, boolean stop) { super(w, digital, stop); // Generate splane poles for the prototype butterworth filter // source: Kuc pole = new Complex[n]; for (int i = 1; i <= pole.length; i++) { pole[i - 1] = ComplexUtils.polar2Complex(1, Math.PI * (2 * i + n - 1) / (2 * n)); }//from www .ja va 2 s.c o m if (n % 2 == 1) { pole[n / 2] = new Complex(-1, 0); // pure real value at exp(i*pi) } zero = new Complex[0]; gain = 1; }
From source file:edu.uniandes.ecos.ase.calculo.CalculoSimpsonRule.java
@Override public double coeficienteTres(double dof) { double coeficienteTres = 0; try {//from w ww . j av a2 s .com coeficienteTres = (calcularGamma((dof + 1) / 2)) / (((Math.pow(dof * Math.PI, 0.5))) * calcularGamma(dof / 2)); } catch (Exception e) { System.out.println("Error calculando el coeficiente tres: " + e.getMessage()); } return coeficienteTres; }
From source file:geogebra.util.MyMath.java
final public static double gamma(double x, Kernel kernel) { // Michael Borcherds 2008-05-04 if (x <= 0 && Kernel.isEqual(x, Math.round(x))) return Double.NaN; // negative integers // Michael Borcherds 2007-10-15 BEGIN added case for x<0 otherwise no // results in 3rd quadrant if (x >= 0) return Math.exp(Gamma.logGamma(x)); else//from ww w .j a v a2 s. com return -Math.PI / (x * gamma(-x, kernel) * Math.sin(Math.PI * x)); // Michael Borcherds 2007-10-15 END }
From source file:com.joey.software.dsp.HilbertTransform.java
public static void getHilbert(float[] reIn, float[] imIn, float[] reOut, float[] imOut) { float[] fftRe = new float[reIn.length]; float[] fftIm = new float[reIn.length]; FastFourierTransform3 fft = new FastFourierTransform3(reIn.length); fft.fft(reIn, imIn, fftRe, fftIm);/*from w ww . j av a2 s . c om*/ for (int n = 0; n < reIn.length; n++) { for (int k = 0; k < reIn.length; k++) { double val = 2 * Math.PI * k * n / reIn.length; reOut[k] += fftRe[k] * Math.sin(val) / reIn.length; imOut[k] += fftIm[k] * Math.cos(val) / reIn.length; } } }
From source file:edu.umn.cs.spatialHadoop.nasa.SpatioAggregateQueries.java
/** * Performs a spatio-temporal aggregate query on an indexed directory * @param inFile/*from w ww . ja v a 2 s . c o m*/ * @param params * @throws ParseException * @throws IOException * @throws InterruptedException */ public static AggregateQuadTree.Node aggregateQuery(Path inFile, OperationsParams params) throws ParseException, IOException, InterruptedException { // 1- Find matching temporal partitions final FileSystem fs = inFile.getFileSystem(params); Vector<Path> matchingPartitions = selectTemporalPartitions(inFile, params); // 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()); } } //noinspection SizeReplaceableByIsEmpty if (allMatchingFiles.isEmpty()) return null; final int resolution = AggregateQuadTree.getResolution(fs, allMatchingFiles.get(0)); // 3- Query all matching files in parallel List<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++) { Path matchingFile = allMatchingFiles.get(i_file); try { 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) * resolution); int y1 = (int) (Math.max(translated.y1, 0) * resolution); int x2 = (int) (Math.min(translated.x2, 1.0) * resolution); int y2 = (int) (Math.min(translated.y2, 1.0) * resolution); AggregateQuadTree.Node fileResult = AggregateQuadTree.aggregateQuery(fs, matchingFile, new java.awt.Rectangle(x1, y1, (x2 - x1), (y2 - y1))); threadResult.accumulate(fileResult); } catch (Exception e) { throw new RuntimeException("Error reading file " + matchingFile, e); } } return threadResult; } }); AggregateQuadTree.Node finalResult = new AggregateQuadTree.Node(); for (Node threadResult : threadsResults) { finalResult.accumulate(threadResult); } numOfTreesTouchesInLastRequest = allMatchingFiles.size(); return finalResult; }
From source file:Float11.java
static public double atan(double x) { boolean signChange = false; boolean Invert = false; int sp = 0;/*from w w w.ja v a 2 s . c o m*/ double x2, a; // check up the sign change if (x < 0.) { x = -x; signChange = true; } // check up the invertation if (x > 1.) { x = 1 / x; Invert = true; } // process shrinking the domain until x<PI/12 while (x > Math.PI / 12) { sp++; a = x + SQRT3; a = 1 / a; x = x * SQRT3; x = x - 1; x = x * a; } // calculation core x2 = x * x; a = x2 + 1.4087812; a = 0.55913709 / a; a = a + 0.60310579; a = a - (x2 * 0.05160454); a = a * x; // process until sp=0 while (sp > 0) { a = a + Math.PI / 6; sp--; } // invertation took place if (Invert) a = Math.PI / 2 - a; // sign change took place if (signChange) a = -a; // return a; }
From source file:com.opengamma.analytics.math.integration.GaussLegendreWeightAndAbscissaFunction.java
private double getInitialRootGuess(final int i, final int n) { return Math.cos(Math.PI * (i + 0.75) / (n + 0.5)); }
From source file:org.honeybee.coderally.Modelt.java
@Override public void onTimeStep() { if (!gogogogo) return;//from w w w .j a va2 s .co m Point checkpoint = schewy.getMidPoint(getCar().getCheckpoint()); double heading = getCar().calculateHeading(checkpoint); double rotation; if (heading < 1) { rotation = -90; } else if (heading > 1) { rotation = 90; } else { rotation = 0; } Point position = getCar().getPosition(); double radians = getCar().getRotation().getRadians() - Math.PI / 2 + Math.toRadians(rotation); Point target = new Point(position.getX() + Math.cos(radians) * 500, position.getY() + Math.sin(radians) * 500); getCar().setTarget(target); slowForTightCorner(getCar()); }
From source file:com.autodomum.daylight.algorithm.DaylightAlgorithm.java
/** * Calculate length of the day for a specific day * /* w w w . j a v a2s. c om*/ * @param latitude * the latitude * @param day * the day * @return time in hours */ public double length(double latitude, int day) { final double p = Math .asin(.39795 * Math.cos(.2163108 + 2 * Math.atan(.9671396 * Math.tan(.00860 * (day - 186))))); return (24.0d - (24.0d / Math.PI) * Math .acos((Math.sin(0.8333d * Math.PI / 180d) + Math.sin(latitude * Math.PI / 180.0d) * Math.sin(p)) / (Math.cos(latitude * Math.PI / 180.0d) * Math.cos(p)))); }