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.jennifer.ui.util.MathUtil.java
public static double radian(double degree) { return degree * Math.PI / 180; }
From source file:com.bleedobsidian.datawave.utils.Sinewave.java
/** * Produce sound data from a sine wave./*from w w w. j a v a 2 s . co m*/ * * @param sampleRate Sample rate. * @param frequency Frequency in Hertz. * @param duration Duration in seconds. * @param amplitude Volume scale. * * @return Samples. */ public static double[] generateSound(double sampleRate, double frequency, double duration, double amplitude) { int n = (int) (sampleRate * duration); double[] a = new double[n + 1]; for (int i = 0; i <= n; i++) { a[i] = amplitude * Math.sin(2 * Math.PI * i * frequency / sampleRate); } return a; }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle(""); Group root = new Group(); Scene scene = new Scene(root, 300, 250, Color.WHITE); int w = 220;//ww w. j a v a2 s . c o m int h = 100; FloatMap map = new FloatMap(); map.setWidth(w); map.setHeight(h); for (int i = 0; i < w; i++) { double v = (Math.sin(i / 20.0 * Math.PI) - 0.5) / 40.0; for (int j = 0; j < h; j++) { map.setSamples(i, j, 0.0f, (float) v); } } Group g = new Group(); DisplacementMap dm = new DisplacementMap(); dm.setMapData(map); g.setEffect(dm); g.setCache(true); Rectangle r = new Rectangle(); r.setX(20.0); r.setY(20.0); r.setWidth(w); r.setHeight(h); r.setFill(Color.BLUE); g.getChildren().add(r); Text t = new Text(); t.setX(40.0); t.setY(80.0); t.setText("Wavy Text"); t.setFill(Color.YELLOW); t.setFont(Font.font(null, FontWeight.BOLD, 36)); g.getChildren().add(t); root.getChildren().add(g); primaryStage.setScene(scene); primaryStage.show(); }
From source file:RollingText.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); String s = "Java Source and Support."; Font font = new Font("Serif", Font.PLAIN, 24); FontRenderContext frc = g2.getFontRenderContext(); g2.translate(40, 80);//from w ww . j av a2 s .c o 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:TextRendering.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Dimension d = getSize();/*from www.jav a 2 s .c o m*/ AffineTransform ct = AffineTransform.getTranslateInstance(d.width / 2, d.height * 3 / 4); g2.transform(ct); String s = "www.java2s.com"; Font f = new Font("Serif", Font.PLAIN, 128); g2.setFont(f); int count = 6; for (int i = 1; i <= count; i++) { AffineTransform oldTransform = g2.getTransform(); float ratio = (float) i / (float) count; g2.transform(AffineTransform.getRotateInstance(Math.PI * (ratio - 1.0f))); float alpha = ((i == count) ? 1.0f : ratio / 3); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); g2.drawString(s, 0, 0); g2.setTransform(oldTransform); } }
From source file:com.jennifer.ui.util.MathUtil.java
public static double degree(double radian) { return radian * 180 / Math.PI; }
From source file:PriorityCompete.java
private void runWork() { Thread.yield();//from w w w .j av a 2s. c o m while (noStopRequested) { if (yield) { Thread.yield(); } count++; for (int i = 0; i < 1000; i++) { double x = i * Math.PI / Math.E; } } }
From source file:com.opengamma.analytics.financial.model.finitedifference.ChebyshevMeshing.java
@Override public Double evaluate(final Integer i) { Validate.isTrue(i >= 0 && i < getNumberOfPoints(), "i out of range"); return _a + _r * (1 - Math.cos(i * Math.PI / _n)); }
From source file:RotatedText.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); String s = "111111111111111111111111111111"; Font font = new Font("Courier", Font.PLAIN, 12); g2d.translate(20, 20);//from w w w. j a v a 2 s . c om FontRenderContext frc = g2d.getFontRenderContext(); GlyphVector gv = font.createGlyphVector(frc, s); int length = gv.getNumGlyphs(); for (int i = 0; i < length; i++) { Point2D p = gv.getGlyphPosition(i); AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY()); at.rotate((double) i / (double) (length - 1) * Math.PI / 3); Shape glyph = gv.getGlyphOutline(i); Shape transformedGlyph = at.createTransformedShape(glyph); g2d.fill(transformedGlyph); } }
From source file:Main.java
/** * Normalize an angle in a 2&pi wide interval around a center value. * This method has three main uses://from w w w.j ava 2 s .com * <ul> * <li>normalize an angle between 0 and 2π:<br/> * <code>a = MathUtils.normalizeAngle(a, Math.PI);</code></li> * <li>normalize an angle between -π and +π<br/> * <code>a = MathUtils.normalizeAngle(a, 0.0);</code></li> * <li>compute the angle between two defining angular positions:<br> * <code>angle = MathUtils.normalizeAngle(end, start) - start;</code></li> * </ul> * Note that due to numerical accuracy and since π cannot be represented * exactly, the result interval is <em>closed</em>, it cannot be half-closed * as would be more satisfactory in a purely mathematical view. * @param a angle to normalize * @param center center of the desired 2π interval for the result * @return a-2kπ with integer k and center-π <= a-2kπ <= center+π * @since 1.2 */ public static double normalizeAngle(double a, double center) { return a - TWO_PI * Math.floor((a + Math.PI - center) / TWO_PI); }