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:edu.purdue.cc.bionet.ui.layout.MultipleCirclesLayout.java
/** * Sets the initial position of the Graph nodes. *///w w w. j a v a2 s .co m public void initialize() { if (this.sampleGroups != null) { Dimension d = this.getSize(); List<List<V>> moleculeGroups = new ArrayList<List<V>>(); for (int i = 0; i < 3; i++) { moleculeGroups.add(new ArrayList<V>()); } if (d != null) { double height = d.getHeight(); double width = d.getWidth(); String groupName; for (V v : this.getGraph().getVertices()) { if (this.isUpRegulated(sampleGroups, v)) moleculeGroups.get(1).add(v); else if (this.isDownRegulated(sampleGroups, v)) moleculeGroups.get(2).add(v); else moleculeGroups.get(0).add(v); } this.radius = (Math.min(height, width)) * 0.3; int groupRadius = (int) (this.radius / Math.sqrt(moleculeGroups.size())); int j = 0, x, y; Point2D.Double graphCenter = new Point2D.Double(width / 2.0, height / 2.0); PolarPoint2D center = new PolarPoint2D(0, 0, graphCenter); PolarPoint2D coord = new PolarPoint2D(0, 0, center); double theta; for (List<V> group : moleculeGroups) { theta = (2 * Math.PI * j) / moleculeGroups.size(); j++; center.setLocation(this.radius, theta, PolarPoint2D.POLAR); int i = 0; for (V vertex : group) { theta = (2 * Math.PI * i) / group.size(); coord.setLocation(groupRadius, theta, PolarPoint2D.POLAR); this.setLocation(vertex, coord); i++; } } } } }
From source file:org.jfree.graphics2d.demo.ImageTest.java
private static double[] calculateReferenceArc(double angle) { double a = (angle / 180 * Math.PI) / 2.0; double x0 = Math.cos(a); double y0 = Math.sin(a); double x1 = (4 - x0) / 3; double y1 = (1 - x0) * (3 - x0) / (3 * y0); double x2 = x1; double y2 = -y1; double x3 = x0; double y3 = -y0; return new double[] { x0, y0, x1, y1, x2, y2, x3, y3 }; }
From source file:org.jfree.demo.DrawStringDemo.java
/** * Receives change event notification from the slider. * * @param event the event./*from w w w. ja va2 s. c o m*/ */ public void stateChanged(ChangeEvent event) { int r = this.slider.getValue(); double angle = Math.PI * 2.0 * (r / 360.0); this.drawStringPanel2.setAngle(angle); this.drawStringPanel2.invalidate(); this.drawStringPanel2.repaint(); }
From source file:de.berlios.statcvs.xml.chart.SymbolicNameAnnotation.java
/** * @see org.jfree.chart.annotations.XYAnnotation#draw(java.awt.Graphics2D, org.jfree.chart.plot.XYPlot, java.awt.geom.Rectangle2D, org.jfree.chart.axis.ValueAxis, org.jfree.chart.axis.ValueAxis) *///from www . j a v a 2s .c om public void draw(Graphics2D g2d, XYPlot xyPlot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis) { PlotOrientation orientation = xyPlot.getOrientation(); // don't draw the annotation if symbolic names date is out of axis' bounds. if (domainAxis.getUpperBound() < symbolicName.getDate().getTime() || domainAxis.getLowerBound() > symbolicName.getDate().getTime()) { return; } RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(xyPlot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(xyPlot.getRangeAxisLocation(), orientation); float x = (float) domainAxis.translateValueToJava2D(symbolicName.getDate().getTime(), dataArea, domainEdge); float y1 = (float) rangeAxis.translateValueToJava2D(rangeAxis.getUpperBound(), dataArea, rangeEdge); float y2 = (float) rangeAxis.translateValueToJava2D(rangeAxis.getLowerBound(), dataArea, rangeEdge); g2d.setPaint(linePaint); g2d.setStroke(stroke); Line2D line = new Line2D.Float(x, y1, x, y2); g2d.draw(line); float anchorX = x; float anchorY = y1 + 2; g2d.setFont(font); g2d.setPaint(textPaint); /*g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);*/ RefineryUtilities.drawRotatedString(symbolicName.getName(), g2d, anchorX, anchorY, TextAnchor.BOTTOM_RIGHT, TextAnchor.BOTTOM_RIGHT, -Math.PI / 2); }
From source file:org.mili.jmibs.jfree.JFreeChartBarIterationObjectLoadBenchmarkSuiteResultRenderer.java
private JFreeChart createChart(String title, CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart(title, "Benchmark (Iteration/Object Loading)", "Time in ns", dataset, PlotOrientation.HORIZONTAL, true, true, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false);/*from ww w .ja v a 2 s. c o m*/ GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); return chart; }
From source file:edu.jhuapl.graphs.jfreechart.utils.RotatedTickDateAxis.java
@SuppressWarnings("unchecked") @Override//from w w w .j a v a 2 s . c o m protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { double rotationAngleInRad = Math.toRadians(tickLabelAngle); //Template types are specified here for additional type safety. List<Tick> ticks = (List<Tick>) super.refreshTicksHorizontal(g2, dataArea, edge); List<Tick> ret = new ArrayList<Tick>(); for (Tick tick : ticks) { if (tick instanceof DateTick) { DateTick dateTick = (DateTick) tick; //The anchor used depends on the label angle, as follows: TextAnchor textAnchor, rotationAnchor; double modRadians = rotationAngleInRad % (2 * Math.PI); //Handle case where user provided a negative angle value. if (modRadians < 0) { modRadians += 2 * Math.PI; } //For angles between 0-180 degrees: if (modRadians <= Math.PI) { textAnchor = TextAnchor.CENTER_LEFT; rotationAnchor = TextAnchor.CENTER_LEFT; } //For angles between 180-360 degrees: else { textAnchor = TextAnchor.CENTER_RIGHT; rotationAnchor = TextAnchor.CENTER_RIGHT; } ret.add(new DateTick(dateTick.getDate(), dateTick.getText(), textAnchor, rotationAnchor, rotationAngleInRad)); } else { ret.add(tick); } } return ret; }
From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithBarChart.java
/** * Angle the labels on the category (x) axis to a nice, jaunty 30 degrees */ public void setCategoryLabelAngle30Degrees() { setCategoryLabelAngle(Math.PI / 6.0); }
From source file:eagle.security.userprofile.model.kde.UserProfileKDEModeler.java
private void computeProbabilityDensityEstimation(RealMatrix inputMat) { probabilityEstimation = new double[inputMat.getRowDimension()]; for (int i = 0; i < probabilityEstimation.length; i++) probabilityEstimation[i] = 1.0;//from w ww. ja va2s .c o m for (int i = 0; i < inputMat.getRowDimension(); i++) { for (int j = 0; j < inputMat.getColumnDimension(); j++) { if (statistics[j].getStddev() > 0) { double stddev = statistics[j].getStddev(); double mean = statistics[j].getMean(); double sqrt2PI = Math.sqrt(2.0 * Math.PI); double denominatorFirstPart = sqrt2PI * stddev; double squareMeanNormal = Math.pow((inputMat.getEntry(i, j) - mean), 2); double twoPowStandardDev = Math.pow(stddev, 2); double twoTimesTwoPowStandardDev = 2.0 * twoPowStandardDev; probabilityEstimation[i] *= ((1.00 / denominatorFirstPart) * (Math.exp(-(squareMeanNormal / twoTimesTwoPowStandardDev)))); } } } java.util.List<Double> listProb = new ArrayList<Double>(); for (int i = 0; i < probabilityEstimation.length; i++) { probabilityEstimation[i] = Math.log10(probabilityEstimation[i]); listProb.add(probabilityEstimation[i]); } Collections.sort(listProb); int i = 0; for (double d : listProb) probabilityEstimation[i++] = d; minProbabilityEstimate = probabilityEstimation[probabilityEstimation.length - 1]; maxProbabilityEstimate = probabilityEstimation[0]; int len = probabilityEstimation.length; int nintyFivePercentIndex = (int) Math.round(0.05 * len); int medianPercentIndex = (int) Math.round(0.5 * len); if (medianPercentIndex >= len) medianProbabilityEstimate = probabilityEstimation[medianPercentIndex - 1]; else medianProbabilityEstimate = probabilityEstimation[medianPercentIndex]; nintyFivePercentileEstimate = probabilityEstimation[nintyFivePercentIndex]; }
From source file:org.jfree.chart.swt.demo.SWTBarChartDemo1.java
/** * Creates a sample chart.//from w w w . j av a2 s. c o m * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("SWTBarChartDemo1", // chart title "Category", // domain axis label "Value", // range axis label dataset); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // get a reference to the plot for further customisation... CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // the SWTGraphics2D class doesn't handle GradientPaint well, so // replace the gradient painter from the default theme with a // standard painter... renderer.setBarPainter(new StandardBarPainter()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:TextureImage.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create the transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans);/* w w w. ja v a 2 s .c o m*/ // Create appearance object for textured cube Appearance app = new Appearance(); Texture tex = new TextureLoader(texImage, this).getTexture(); app.setTexture(tex); TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); app.setTextureAttributes(texAttr); // Create textured cube and add it to the scene graph. Box textureCube = new Box(0.4f, 0.4f, 0.4f, Box.GENERATE_TEXTURE_COORDS, app); objTrans.addChild(textureCube); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }