Example usage for java.lang Math PI

List of usage examples for java.lang Math PI

Introduction

In this page you can find the example usage for java.lang Math PI.

Prototype

double PI

To view the source code for java.lang Math PI.

Click Source Link

Document

The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.

Usage

From source file:beast.math.distributions.NormalDistribution.java

/**
 * probability density function//from w ww.  jav a  2s .  c  o  m
 *
 * @param x  argument
 * @param m  mean
 * @param sd standard deviation
 * @return pdf at x
 */
public static double pdf(double x, double m, double sd) {
    double a = 1.0 / (Math.sqrt(2.0 * Math.PI) * sd);
    double b = -(x - m) * (x - m) / (2.0 * sd * sd);

    return a * Math.exp(b);
}

From source file:net.sf.dsp4j.octave.packages.signal_1_2_0.Cheb2Ord.java

private void calcCheb2Ord(double[] Wp, double[] Ws, double Rp, double Rs) {
    double T = 2;

    // returned frequency is the same as the input frequency
    Wc = Arrays.copyOf(Ws, Ws.length);

    // warp the target frequencies according to the bilinear transform
    for (int i = 0; i < Wp.length; i++) {
        Ws[i] = 2.0 / T * Math.tan(Math.PI * Ws[i] / T);
        Wp[i] = 2.0 / T * Math.tan(Math.PI * Wp[i] / T);
    }//  w w  w  .j  a v a2s .  c o  m
    double Wa;

    if (Wp[0] < Ws[0]) {
        // low pass
        if (Wp.length == 1) {
            Wa = Wp[0] / Ws[0];
        } else {
            // band reject
            throw new RuntimeException("band reject is not implement yet.");
        }
    } else {
        // if high pass, reverse the sense of the test
        if (Wp.length == 1) {
            Wa = Ws[0] / Wp[0];
        } else {
            // band pass 
            Wa = Double.MAX_VALUE;
            for (int i = 0; i < Wp.length; i++) {
                Wa = Math.min(Wa, Math.abs((Math.pow(Wp[i], 2) - Ws[0] * Ws[1]) / (Wp[i] * (Ws[0] - Ws[1]))));
            }
        }
    }

    // compute minimum n which satisfies all band edge conditions
    final double stop_atten = Math.pow(10, Math.abs(Rs) / 10.0);
    final double pass_atten = Math.pow(10, Math.abs(Rp) / 10.0);
    n = (int) Math.ceil(
            FastMath.acosh(Math.sqrt((stop_atten - 1.0) / (pass_atten - 1.0))) / FastMath.acosh(1.0 / Wa));

}

From source file:eu.crisis_economics.abm.markets.clearing.heterogeneous.LineSearchTest.java

@Test
/**/*from w  w w . j  a  v  a  2  s . c om*/
  * Test the Brent line search algorithm by minimizing a one-dimensional
  * cosine function. The starting point of the minimization is the origin,
  * and the maximum distance to travel in the positive x direction is 2*Pi.
  * The expected solution is therefor the local minimum at Pi.
  */
public void testOneDimensionalCosMinimization() {
    final MultivariateFunction meritFunction = new MultivariateFunction() {
        @Override
        public double value(final double[] x) {
            return Math.cos(x[0]);
        }
    };
    final double[] lineDirection = new double[] { 1.0 };
    double distanceToTravel = Math.PI * 2.;
    final LineSearchResult solution = BrentLineSearch.doLineSearch(meritFunction, new double[] { 0.0 },
            lineDirection, distanceToTravel);
    Assert.assertTrue(Math.abs(solution.getEvaluationAtSolution() + 1.) < 1.e-10);
    Assert.assertEquals(solution.getSolutionPoint()[0], Math.PI, 1.e-10);
}

From source file:hivemall.utils.math.StatsUtils.java

/**
 * @return value of probabilistic density function
 *///from w  ww .ja v  a  2 s .c  o  m
public static double pdf(final double x, final double x_hat, final double sigma) {
    if (sigma == 0.d) {
        return 0.d;
    }
    double diff = x - x_hat;
    double numerator = Math.exp(-0.5d * diff * diff / sigma);
    double denominator = Math.sqrt(2.d * Math.PI) * Math.sqrt(sigma);
    return numerator / denominator;
}

From source file:com.orange.atk.results.logger.log.Action.java

/**
 * Set Annotation properties  used in Analysis Tool (keypress,log,screenshot...) 
 * For each action a marker and an Annotation is related
 * @param Xvalue StartTime of Marker Action
 * @param Yvalue Position where to display the comment 1 for the top 0 for the bottom
 * @param color Color of Marker/*w ww .  j a  v a 2  s.  c  o  m*/
 */

public void setAnnotation(double Xvalue, Paint color) {
    if (szActionName != null) {
        annotation = new XYTextAnnotation(szActionName, Xvalue, 0.05);
        annotation.setFont(new Font("SansSerif", Font.PLAIN, 12));
        annotation.setRotationAngle(3 * Math.PI / 2);
        annotation.setRotationAnchor(TextAnchor.BOTTOM_LEFT);
        annotation.setTextAnchor(TextAnchor.BOTTOM_LEFT);
        annotation.setToolTipText(szActionName);
        annotation.setPaint(color);
    }
}

From source file:dsp.unige.figures.ChannelHelper.java

/**
 * Returns the rain attenuation in dB given the state s, using procedure
 * from [1]. [1]. A prediction model that combines Rain Attenuation and
 * Other Propagation Impairments Along Earth- Satellinte Paths
 * //w w w  .ja  v a2s .  c  o  m
 * @param s
 * @return rain attenuation in dB.
 */
public static double getRainAttenuation(Station s) {

    // ==================== step 1 ===========================
    // calculate freezing height (in km) from the absolute value of station
    // latitude
    double hFr;
    if (s.stationLatitude >= 0 && s.stationLatitude < 23)
        hFr = 5.0d;
    else
        hFr = 5.0 - 0.075 * (s.stationLatitude - 23);

    // ==================== step 2 ===========================
    // calculate slant-path length Ls below the freezing height
    double Ls = (hFr - s.stationAltitude) / Math.sin(s.elevationAngle * Math.PI / 180);

    // ==================== step 3 ===========================
    // calculate horizontal projection Lg of the slant path length
    double Lg = Ls * Math.cos(s.elevationAngle * Math.PI / 180);

    // ==================== step 4 ===========================
    // obtain rain attenuation
    double gamma = s.getRainK() * Math.pow(s.R001, s.getRainAlpha());

    // ==================== step 5 ===========================
    // calculate horizontal path adjustment
    double rh001 = 1 / (1 + 0.78 * Math.sqrt(Lg * gamma / s.frequency) - 0.38 * (1 - Math.exp(-2 * Lg)));

    // ==================== step 6 ===========================
    // calculate the adjusted rainy path length
    double ZETA = Math.atan((hFr - s.stationAltitude) / (Lg * rh001));
    double Lr;

    if (ZETA > s.elevationAngle) {
        Lr = (Lg * rh001) / (Math.cos(s.elevationAngle * Math.PI / 180));
    } else {
        Lr = (hFr - s.stationAltitude) / (Math.sin(s.elevationAngle * Math.PI / 180));
    }

    // ==================== step 7 ===========================
    // calculate vertical path adjustment
    double CHI;
    if (Math.abs(s.elevationAngle) < 36) {
        CHI = 36 - s.elevationAngle;
    } else {
        CHI = 0;
    }
    double rv001 = 1 / (1 + Math.sqrt(Math.sin(s.elevationAngle * Math.PI / 180))
            * (31 * (1 - Math.exp(-s.elevationAngle / (1 + CHI)))
                    * (Math.sqrt(Lr * gamma) / Math.pow(s.frequency, 2)) - 0.45));

    // ==================== step 8 ===========================
    // effective path length through rain
    double Le = Lr * rv001;

    // ==================== step 9 ===========================
    // get the attenuation exceded in 0.01% of average year time
    double A001 = gamma * Le;

    return A001;
}

From source file:net.sf.dsp4j.octave.packages.signal_1_2_0.Cheb1Ord.java

private void calcCheb1Ord(double[] Wp, double[] Ws, double Rp, double Rs) {

    double T = 2;

    // returned frequency is the same as the input frequency
    Wc = Arrays.copyOf(Wp, Wp.length);

    // warp the target frequencies according to the bilinear transform
    for (int i = 0; i < Wp.length; i++) {
        Ws[i] = 2.0 / T * Math.tan(Math.PI * Ws[i] / T);
        Wp[i] = 2.0 / T * Math.tan(Math.PI * Wp[i] / T);
    }//from w w  w  .  java  2  s.c o m
    double Wa;
    if (Wp[0] < Ws[0]) // low pass
    {
        if (Wp.length == 1) {
            Wa = Ws[0] / Wp[0];
        } else {
            // band reject
            throw new RuntimeException("band reject is not implement yet.");
        }
    } else {
        // if high pass, reverse the sense of the test
        if (Wp.length == 1) {
            Wa = Wp[0] / Ws[0];
        } else {
            // band pass
            Wa = Double.MAX_VALUE;
            for (int i = 0; i < Wp.length; i++) {
                Wa = Math.min(Wa, Math.abs((Math.pow(Ws[i], 2) - Wp[0] * Wp[1]) / (Ws[i] * (Wp[0] - Wp[1]))));
            }
        }
    }

    // compute minimum n which satisfies all band edge conditions
    final double stop_atten = Math.pow(10, Math.abs(Rs) / 10.0);
    final double pass_atten = Math.pow(10, Math.abs(Rp) / 10.0);
    n = (int) Math
            .ceil(FastMath.acosh(Math.sqrt((stop_atten - 1.0) / (pass_atten - 1.0))) / FastMath.acosh(Wa));

}

From source file:image.writer.ImageWriterExample1.java

/**
 * Paints a few things on a Graphics2D instance.
 * @param g2d the Graphics2D instance//ww  w .j  a v a 2s  .  c  om
 * @param pageNum a page number
 */
protected void paintSome(Graphics2D g2d, int pageNum) {
    //Paint a bounding box
    g2d.drawRect(0, 0, 400, 200);

    //A few rectangles rotated and with different color
    Graphics2D copy = (Graphics2D) g2d.create();
    int c = 12;
    for (int i = 0; i < c; i++) {
        float f = ((i + 1) / (float) c);
        Color col = new Color(0.0f, 1 - f, 0.0f);
        copy.setColor(col);
        copy.fillRect(70, 90, 50, 50);
        copy.rotate(-2 * Math.PI / (double) c, 70, 90);
    }
    copy.dispose();

    //Some text
    copy = (Graphics2D) g2d.create();
    copy.rotate(-0.25);
    copy.setColor(Color.RED);
    copy.setFont(new Font("sans-serif", Font.PLAIN, 36));
    copy.drawString("Hello world!", 140, 140);
    copy.setColor(Color.RED.darker());
    copy.setFont(new Font("serif", Font.PLAIN, 36));
    copy.drawString("Hello world!", 140, 180);
    copy.dispose();

    //Try attributed text
    AttributedString aString = new AttributedString("This is attributed text.");
    aString.addAttribute(TextAttribute.FAMILY, "SansSerif");
    aString.addAttribute(TextAttribute.FAMILY, "Serif", 8, 18);
    aString.addAttribute(TextAttribute.FOREGROUND, Color.orange, 8, 18);
    g2d.drawString(aString.getIterator(), 250, 170);

    g2d.drawString("Page: " + pageNum, 250, 190);
}

From source file:com.creapple.tms.mobiledriverconsole.utils.MDCUtils.java

/**
 * // http://www.movable-type.co.uk/scripts/latlong.html
 * // Under Creative Commons License http://creativecommons.org/licenses/by/3.0/
 * Calculate distance between two GPS co-ordinate
 * @param lat1/*  w w w . ja  v  a2s . c om*/
 * @param lon1
 * @param lat2
 * @param lon2
 * @return
 */
public static double getDistanceMeters(double lat1, double lon1, double lat2, double lon2) {
    int r = 6371;
    double dLat = Math.abs(lat2 - lat1) * (Math.PI / 180);
    double dLon = Math.abs(lon2 - lon1) * (Math.PI / 180);
    double a = (Math.sin(dLat / 2) * Math.sin(dLat / 2)) + (Math.cos(lat1 * (Math.PI / 180))
            * Math.cos(lat2 * (Math.PI / 180)) * Math.sin(dLon / 2) * Math.sin(dLon / 2));
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double d = r * c * 1000; // show as meters

    return Double.parseDouble(mDecimalFormat.format(d));
}

From source file:edu.esprit.pi.workshop.statistiques.BarChart.java

@Override
public JFreeChart construireChart3D() {
    graphe = ChartFactory.createBarChart3D("Pourcentage revenue par Dpartement", "", "Pourcentage du revenu",
            createDataset(), PlotOrientation.HORIZONTAL, true, true, true);
    final CategoryPlot plot = graphe.getCategoryPlot();
    final CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0));
    final CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setItemLabelsVisible(true);
    return graphe;
}