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.eclipse.swt.snippets.Snippet209.java
static void drawTorus(GL gl, float r, float R, int nsides, int rings) { float ringDelta = 2.0f * (float) Math.PI / rings; float sideDelta = 2.0f * (float) Math.PI / nsides; float theta = 0.0f, cosTheta = 1.0f, sinTheta = 0.0f; for (int i = rings - 1; i >= 0; i--) { float theta1 = theta + ringDelta; float cosTheta1 = (float) Math.cos(theta1); float sinTheta1 = (float) Math.sin(theta1); gl.glBegin(GL.GL_QUAD_STRIP);/* w ww . j ava 2s . c om*/ float phi = 0.0f; for (int j = nsides; j >= 0; j--) { phi += sideDelta; float cosPhi = (float) Math.cos(phi); float sinPhi = (float) Math.sin(phi); float dist = R + r * cosPhi; gl.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); gl.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); gl.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); gl.glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi); } gl.glEnd(); theta = theta1; cosTheta = cosTheta1; sinTheta = sinTheta1; } }
From source file:com.example.PJS.java
public static double N(double z) { /**/*from w ww . j av a 2 s .c o m*/ * Normal Distribution Function, PDF probability density function *Odegaard Dic 2003, page 129 */ double n = 1 / Math.sqrt(2 * Math.PI) * Math.exp(-0.5 * z * z); return n; }
From source file:info.financialecology.finance.utilities.sandbox.SimpleStrategyFSM.java
public static void main(String[] args) { try {//from w ww. j av a 2 s . co m // Build FSM SimpleStrategyFSM strategyFSM = new SimpleStrategyFSM(); StateMachine sm = strategyFSM.getStateMachine(); int nTicks = 200; // Number of ticks double sinus_shift = 10.0; double sinus_amplitude = 10.0; double sinus_lambda = 50.0; double threshold5 = 0.05 * 2 * sinus_amplitude; double threshold50 = 0.5 * 2 * sinus_amplitude; double threshold95 = 0.95 * 2 * sinus_amplitude; logger.info( "Thresholds: [5%, " + threshold5 + "], [50%, " + threshold50 + "], [95%, " + threshold95 + "]"); //double sinus_t_prev = sinus_amplitude + sinus_shift + sinus_amplitude * Math.sin(2 * 0 * Math.PI / sinus_lambda); double sinus_t_prev = sinus_shift + sinus_amplitude * Math.sin(2 * 0 * Math.PI / sinus_lambda); strategyFSM.start(); for (int i = 1; i < nTicks; i++) { double sinus_t = sinus_amplitude + sinus_shift + sinus_amplitude * Math.sin(2 * i * Math.PI / sinus_lambda); //double sinus_t = sinus_shift + sinus_amplitude * Math.sin(2 * i * Math.PI / sinus_lambda); logger.info("Tick: " + i + ", value: " + sinus_t); if ((sinus_t >= threshold95) && (sinus_t_prev < threshold95)) strategyFSM.crossing95(); if ((sinus_t >= threshold50) && (sinus_t_prev < threshold50) || (sinus_t <= threshold50) && (sinus_t_prev > threshold50)) strategyFSM.crossing50(); if ((sinus_t <= threshold5) && (sinus_t_prev > threshold5)) strategyFSM.crossing5(); sinus_t_prev = sinus_t; } /* int window = 10; // Window for the calculation of percentiles int nTicks = 200; // Number of ticks double[] sinus = new double[nTicks]; // Price series (= sinus process) double sinus_shift = 100.0; // Parameters of the sinus process double sinus_amplitude = 20.0; double sinus_lambda = 50.0; // Create a sinus price process to test the strategy for (int i = 0; i < nTicks; i++) { sinus[i] = sinus_shift + sinus_amplitude * Math.sin(2*i*Math.PI / sinus_lambda); } for (int i = 0; i < nTicks; i++) { if (i < window) positions.add(0); else { DescriptiveStatistics stats = new DescriptiveStatistics(); for (int j = i-window+1; j <= i; j++) { stats.addValue(sinus[j]); } double perc_95 = stats.getPercentile(95); double perc_5 = stats.getPercentile(5); double perc_50 = stats.getPercentile(50); if (sinus[i-1]<perc_95 && sinus[i]>=perc_95) sm.applyEvent(new Event("Buy")); if (sinus[i-1]>perc_5 && sinus[i]<=perc_5) sm.applyEvent(new Event("Sell")); // TODO: Add liquidation events } } */ // Terminate FSM strategyFSM.stop(); } catch (FiniteStateException e) { logger.error("Unexpected state transition processing error", e); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); } }
From source file:Rotate.java
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(new Color(150, 150, 150)); g2d.fillRect(20, 20, 80, 50);/*w w w .ja v a 2s . c o m*/ g2d.translate(180, -150); g2d.rotate(Math.PI / 4); g2d.fillRect(20, 20, 80, 50); }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; int w = getSize().width - 1; int h = getSize().height - 1; for (int i = 0; i < 12; i++) { double angle = Math.PI / 2 - i * Math.PI / 6; double x = Math.cos(angle); double y = Math.sin(angle); Line2D l = new Line2D.Double(100 + 55.0 * x, 100 - 55.0 * y, 100 + 65.0 * x, 100 - 65.0 * y); g2.draw(l);/*w w w.ja v a 2s . c o m*/ } }
From source file:edu.gmu.cs.sim.util.media.chart.ScatterPlotSeriesAttributes.java
static Shape[] buildShapes() { Shape[] s = new Shape[7]; GeneralPath g = null;//from w ww. j a va 2s .co m // Circle s[0] = new Ellipse2D.Double(-3, -3, 6, 6); // Rectangle Rectangle2D.Double r = new Rectangle2D.Double(-3, -3, 6, 6); s[1] = r; // Diamond s[2] = AffineTransform.getRotateInstance(Math.PI / 4.0).createTransformedShape(r); // Cross + g = new GeneralPath(); g.moveTo(-0.5f, -3); g.lineTo(-0.5f, -0.5f); g.lineTo(-3, -0.5f); g.lineTo(-3, 0.5f); g.lineTo(-0.5f, 0.5f); g.lineTo(-0.5f, 3); g.lineTo(0.5f, 3); g.lineTo(0.5f, 0.5f); g.lineTo(3, 0.5f); g.lineTo(3, -0.5f); g.lineTo(0.5f, -0.5f); g.lineTo(0.5f, -3); g.closePath(); s[3] = g; // X s[4] = g.createTransformedShape(AffineTransform.getRotateInstance(Math.PI / 4.0)); // Up Triangle g = new GeneralPath(); g.moveTo(0f, -3); g.lineTo(-3, 3); g.lineTo(3, 3); g.closePath(); s[5] = g; // Down Triangle s[6] = g.createTransformedShape(AffineTransform.getRotateInstance(Math.PI)); return s; }
From source file:Main.java
public void paint(Graphics g) { g.fillRect(0, 0, 20, 20);// w w w . j a v a 2 s. co m Graphics2D g2 = (Graphics2D) g; g2.shear(5.3, 5.4); g2.rotate(30.0 * Math.PI / 180.0); g2.scale(2.0, 2.0); g.setColor(Color.red); g.fillRect(0, 0, 20, 20); }
From source file:Main.java
public void paint(Graphics g) { g.fillRect(0, 0, 20, 20);/* w ww.j a v a 2 s .c o m*/ Graphics2D g2 = (Graphics2D) g; g2.translate(50, 50); g2.rotate(30.0 * Math.PI / 180.0); g2.scale(2.0, 2.0); g.setColor(Color.red); g.fillRect(0, 0, 20, 20); }
From source file:Main.java
public void paint(Graphics g) { g.fillRect(0, 0, 20, 20);/*from w ww . ja v a2 s .c o m*/ Graphics2D g2 = (Graphics2D) g; g2.translate(5.3, 5.4); g2.rotate(30.0 * Math.PI / 180.0); g2.scale(2.0, 2.0); g.setColor(Color.red); g.fillRect(0, 0, 20, 20); }
From source file:Main.java
public void paint(Graphics g) { super.paintComponent(g); int radius = 40; int centerX = 50; int centerY = 100; Polygon p = new Polygon(); centerX = 150;// w w w.j ava 2s .c o m for (int i = 0; i < 5; i++) p.addPoint((int) (centerX + radius * Math.cos(i * 2 * Math.PI / 5)), (int) (centerY + radius * Math.sin(i * 2 * Math.PI / 5))); g.fillPolygon(p); }