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:com.opengamma.strata.math.impl.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. co m*/ f1[i].applyAsDouble(x) / Math .sqrt(CombinatoricsUtils.factorialDouble(i) * Math.pow(2, i) * Math.sqrt(Math.PI)), f2[i].applyAsDouble(x), EPS); } }
From source file:Main.java
/** * Given two angles in degrees, determine the smallest angle between them. * * For example, given angles 90 and 170, the smallest angle difference would be 80 * and the larger angle difference would be 280. * * @param firstAngleDeg/*from w w w . ja va2 s . c om*/ * @param secondAngleDeg * @return smallest angle */ public static double smallestAngularDifferenceDegrees(double firstAngleDeg, double secondAngleDeg) { double rawDiffDeg = firstAngleDeg - secondAngleDeg; double rawDiffRad = rawDiffDeg * Math.PI / 180; double wrappedDiffRad = Math.atan2(Math.sin(rawDiffRad), Math.cos(rawDiffRad)); double wrappedDiffDeg = wrappedDiffRad * 180 / Math.PI; return wrappedDiffDeg; }
From source file:com.cloudmade.api.Utils.java
/** * Convert latitude, longitude pair to tile coordinates * //from www . j a va2 s . co m * @param latitude * @param longitude * @param zoom * @return Tile coordinates [x, y] */ public static final int[] latlon2tilenums(double latitude, double longitude, int zoom) { int factor = 1 << (zoom - 1); latitude = Math.toRadians(latitude); longitude = Math.toRadians(longitude); double xtile = 1 + longitude / Math.PI; double ytile = 1 - Math.log(Math.tan(latitude) + (1 / Math.cos(latitude))) / Math.PI; return new int[] { (int) (xtile * factor), (int) (ytile * factor) }; }
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);//from w w w . j av a 2 s.c o m GlyphVector gv = font.createGlyphVector(frc, s); System.out.println(gv.getFont()); 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
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);//from w w w . ja v a2s . c om GlyphVector gv = font.createGlyphVector(frc, s); System.out.println(gv.getOutline()); 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
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);/*from w w w . j a va 2 s .com*/ GlyphVector gv = font.createGlyphVector(frc, s); System.out.println(gv.getVisualBounds()); 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
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);//from w w w . ja v a2 s. c o m GlyphVector gv = font.createGlyphVector(frc, s); System.out.println(gv.getLogicalBounds()); 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:com.insightml.math.distributions.GaussianDistribution.java
public GaussianDistribution(final double mean, final double stddev) { this.mean = mean; this.stddev = stddev; sigmaSquare = stddev * stddev;/*w w w . j a va2 s. c om*/ factor = 1. / Math.sqrt(2 * Math.PI * sigmaSquare); }
From source file:com.atomiton.watermanagement.ngo.util.WaterMgmtNGOUtility.java
public static double deg2rad(double deg) { return deg * (Math.PI / 180); }
From source file:Main.java
private static BufferedImage createRotatedImage(Object src, int width, int height, int angle) { angle = angle % 360;/*from www. j a va 2 s . c o m*/ if (angle < 0) { angle += 360; } if (angle == 0) { return renderRotatedObject(src, 0, width, height, 0, 0); } else if (angle == 90) { return renderRotatedObject(src, -Math.PI / 2, height, width, -width, 0); } else if (angle == 180) { return renderRotatedObject(src, Math.PI, width, height, -width, -height); } else if (angle == 270) { return renderRotatedObject(src, Math.PI / 2, height, width, 0, -height); } else if (angle > 0 && angle < 90) { double angleInRadians = ((-angle * Math.PI) / 180.0); double cosTheta = Math.abs(Math.cos(angleInRadians)); double sineTheta = Math.abs(Math.sin(angleInRadians)); int dW = (int) (width * cosTheta + height * sineTheta); int dH = (int) (width * sineTheta + height * cosTheta); return renderRotatedObject(src, angleInRadians, dW, dH, -width * sineTheta * sineTheta, width * sineTheta * cosTheta); } else if (angle > 90 && angle < 180) { double angleInRadians = ((-angle * Math.PI) / 180.0); double cosTheta = Math.abs(Math.cos(angleInRadians)); double sineTheta = Math.abs(Math.sin(angleInRadians)); int dW = (int) (width * cosTheta + height * sineTheta); int dH = (int) (width * sineTheta + height * cosTheta); return renderRotatedObject(src, angleInRadians, dW, dH, -(width + height * sineTheta * cosTheta), -height / 2); } else if (angle > 180 && angle < 270) { double angleInRadians = ((-angle * Math.PI) / 180.0); double cosTheta = Math.abs(Math.cos(angleInRadians)); double sineTheta = Math.abs(Math.sin(angleInRadians)); int dW = (int) (width * cosTheta + height * sineTheta); int dH = (int) (width * sineTheta + height * cosTheta); return renderRotatedObject(src, angleInRadians, dW, dH, -(width * cosTheta * cosTheta), -(height + width * cosTheta * sineTheta)); } else if (angle > 270 && angle < 360) { double angleInRadians = ((-angle * Math.PI) / 180.0); double cosTheta = Math.abs(Math.cos(angleInRadians)); double sineTheta = Math.abs(Math.sin(angleInRadians)); int dW = (int) (width * cosTheta + height * sineTheta); int dH = (int) (width * sineTheta + height * cosTheta); return renderRotatedObject(src, angleInRadians, dW, dH, (height * cosTheta * sineTheta), -(height * sineTheta * sineTheta)); } return renderRotatedObject(src, 0, width, height, 0, 0); }