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:fungus.VisualizerTransformers.java
public static Shape createRegularPolygon(int sides, int radius) { Polygon p = new Polygon(); double a = 2 * Math.PI / sides; for (int i = 0; i < sides; i++) p.addPoint((int) (radius * Math.sin(a * i)), (int) (radius * -Math.cos(a * i))); return p;/*from w w w . ja va 2 s .c om*/ }
From source file:com.opengamma.analytics.math.function.special.GammaFunction.java
@Override public Double evaluate(final Double x) { if (x > 0.0) { return Math.exp(Gamma.logGamma(x)); }/*from ww w .j ava 2s.co m*/ return Math.PI / Math.sin(Math.PI * x) / evaluate(1 - x); }
From source file:com.opengamma.strata.math.impl.function.special.GammaFunction.java
@Override public double applyAsDouble(double x) { if (x > 0.0) { return Math.exp(Gamma.logGamma(x)); }/*from ww w . j a v a 2s.co m*/ return Math.PI / Math.sin(Math.PI * x) / applyAsDouble(1 - x); }
From source file:edu.columbia.sel.grout.util.TileUtils.java
/** * For a description see:// w ww . ja va 2s.c o m * * @see http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames For a * code-description see: * @see http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames# * compute_bounding_box_for_tile_number * @param aLat * latitude to get the {@link OSMTileInfo} for. * @param aLon * longitude to get the {@link OSMTileInfo} for. * @return The {@link OSMTileInfo} providing 'x' 'y' and 'z'(oom) for the * coordinates passed. */ public static OSMTileInfo getMapTileFromCoordinates(final double aLat, final double aLon, final int zoom) { final int y = (int) Math .floor((1 - Math.log(Math.tan(aLat * Math.PI / 180) + 1 / Math.cos(aLat * Math.PI / 180)) / Math.PI) / 2 * (1 << zoom)); final int x = (int) Math.floor((aLon + 180) / 360 * (1 << zoom)); return new OSMTileInfo(x, y, zoom); }
From source file:Utils.java
public static Shape generatePolygon(int sides, int outsideRadius, int insideRadius) { if (sides < 3) { return new Ellipse2D.Float(0, 0, 10, 10); }/*from w w w . ja va 2 s . c om*/ AffineTransform trans = new AffineTransform(); Polygon poly = new Polygon(); for (int i = 0; i < sides; i++) { trans.rotate(Math.PI * 2 / (float) sides / 2); Point2D out = trans.transform(new Point2D.Float(0, outsideRadius), null); poly.addPoint((int) out.getX(), (int) out.getY()); trans.rotate(Math.PI * 2 / (float) sides / 2); if (insideRadius > 0) { Point2D in = trans.transform(new Point2D.Float(0, insideRadius), null); poly.addPoint((int) in.getX(), (int) in.getY()); } } return poly; }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int cx = getSize().width / 2; int cy = getSize().height / 2; g2.translate(cx, cy);/*from www . ja v a 2s.c o m*/ g2.rotate(theta * Math.PI / 180); Shape oldClip = g2.getClip(); Shape e = new Ellipse2D.Float(-cx, -cy, cx * 2, cy * 2); g2.clip(e); Shape c = new Ellipse2D.Float(-cx, -cy, cx * 3 / 4, cy * 2); g2.setPaint(new GradientPaint(40, 40, Color.blue, 60, 50, Color.white, true)); g2.fill(c); g2.setPaint(Color.yellow); g2.fillOval(cx / 4, 0, cx, cy); g2.setClip(oldClip); g2.setFont(new Font("Times New Roman", Font.PLAIN, 64)); g2.setPaint(new GradientPaint(-cx, 0, Color.red, cx, 0, Color.black, false)); g2.drawString("Hello, 2D!", -cx * 3 / 4, cy / 4); AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) .75); g2.setComposite(ac); Shape r = new RoundRectangle2D.Float(0, -cy * 3 / 4, cx * 3 / 4, cy * 3 / 4, 20, 20); g2.setStroke(new BasicStroke(4)); g2.setPaint(Color.magenta); g2.fill(r); g2.setPaint(Color.green); g2.draw(r); g2.drawImage(image, -cx / 2, -cy / 2, this); }
From source file:com.opengamma.analytics.math.function.special.OrthonormalHermitePolynomialFunctionTest.java
@Test public void test() { final int n = 15; final DoubleFunction1D[] f1 = HERMITE.getPolynomials(n); final DoubleFunction1D[] f2 = ORTHONORMAL.getPolynomials(n); final double x = 3.4; for (int i = 0; i < f1.length; i++) { assertEquals(//from w w w . j a va 2 s . c om f1[i].evaluate(x) / Math.sqrt(MathUtils.factorialDouble(i) * Math.pow(2, i) * Math.sqrt(Math.PI)), f2[i].evaluate(x), EPS); } }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); String s = "www.java2s.com www.java2s.com"; Font font = new Font("Serif", Font.PLAIN, 24); FontRenderContext frc = g2.getFontRenderContext(); g2.translate(40, 80);//w w w .ja va 2 s .co m GlyphVector gv = font.createGlyphVector(frc, s); int length = gv.getNumGlyphs(); for (int i = 0; i < length; i++) { Point2D p = gv.getGlyphPosition(i); double theta = (double) i / (double) (length - 1) * Math.PI / 4; AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY()); at.rotate(theta); Shape glyph = gv.getGlyphOutline(i); Shape transformedGlyph = at.createTransformedShape(glyph); g2.fill(transformedGlyph); } }
From source file:Main.java
protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawLine(10, 100, 380, 100);//from ww w. jav a 2 s . c om g.drawLine(200, 30, 200, 190); g.drawLine(380, 100, 370, 90); g.drawLine(380, 100, 370, 110); g.drawLine(200, 30, 190, 40); g.drawLine(200, 30, 210, 40); g.drawString("X", 360, 80); g.drawString("Y", 220, 40); Polygon p = new Polygon(); Polygon p2 = new Polygon(); for (int x = -170; x <= 170; x++) { p.addPoint(x + 200, 100 - (int) (50 * f((x / 100.0) * 2 * Math.PI))); } for (int x = -170; x <= 170; x++) { p2.addPoint(x + 200, 100 - (int) (50 * gCos((x / 100.0) * 2 * Math.PI))); } g.setColor(Color.red); g.drawPolyline(p.xpoints, p.ypoints, p.npoints); g.drawString("-2\u03c0", 95, 115); g.drawString("-\u03c0", 147, 115); g.drawString("\u03c0", 253, 115); g.drawString("2\u03c0", 305, 115); g.drawString("0", 200, 115); g.setColor(Color.blue); g.drawPolyline(p2.xpoints, p2.ypoints, p2.npoints); }
From source file:Main.java
/** * <p>This function converts decimal degrees to radians.</p> * * @param deg - the decimal to convert to radians * @return the decimal converted to radians *//*from w w w .jav a2 s .c o m*/ private static final double deg2rad(double deg) { return (deg * Math.PI / 180.0); }