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:Main.java

static Path getWavePath(float width, float height, float amplitude, float shift, float divide) {
    Path path = new Path();
    float quadrant = height - amplitude;
    float x, y;/*from   w ww. j  av a 2 s .com*/
    path.moveTo(0, 0);
    path.lineTo(0, quadrant);
    for (int i = 0; i < width + 10; i = i + 10) {
        x = (float) i;
        y = quadrant + amplitude * (float) Math.sin(((i + 10) * Math.PI / 180) / divide + shift);
        path.lineTo(x, y);
    }
    path.lineTo(width, 0);
    path.close();
    return path;
}

From source file:Main.java

/**
 * generate a CW signal with the given properties
 * @param frequency the frequency/*from ww  w. j  a  va2  s .com*/
 * @param length sample length
 * @param amplitude maximum amplitude
 * @param sampleRate sample rate to use
 * @return data as double[]
 */
public static double[] generateSignal(double frequency, int length, double amplitude, double sampleRate) {

    double[] signal = new double[length];

    for (int i = 0; i < length; i++) {
        signal[i] = amplitude * Math.sin(frequency * 2.0 * Math.PI * (i / sampleRate));
    }

    return signal;
}

From source file:Main.java

private static double rad(double d) {
    return d * Math.PI / 180.0;
}

From source file:Main.java

private static double deg2rad(double deg) {
    return (deg * Math.PI / 180.0);
}

From source file:Main.java

public static double rad(double d) {
    return d * Math.PI / 180.0;
}

From source file:Main.java

/**
 * Will return a list of random location from the given position & radius
 * @param amount/*from w ww.  j a v a2s. c  o  m*/
 * @param lat
 * @param lng
 * @param radius
 * @return ArrayList<Location> 
 */
public static ArrayList<Location> randomLocations(int amount, double lat, double lng, double radius) {
    ArrayList<Location> locations = new ArrayList<Location>(0);
    Location centerLocation = new Location("local");
    centerLocation.setLatitude(lat);
    centerLocation.setLongitude(lng);

    final double lngScale = Math.cos((Math.PI / 180.0) * lat);
    final double radiusDeg = radius / 111.2; // radius converted to degrees (square)

    while (locations.size() < amount) {
        Location l = new Location("local");
        double dLat = (Math.random() * radiusDeg * 2) - radiusDeg;
        double dLng = (Math.random() * radiusDeg * 2 / lngScale) - (radiusDeg / lngScale);

        l.setLatitude(centerLocation.getLatitude() + dLat);
        l.setLongitude(centerLocation.getLongitude() + dLng);
        double dist = l.distanceTo(centerLocation) / 1000.0;

        if (dist < (radius)) {
            locations.add(l);
        }
    }
    return locations;
}

From source file:Main.java

public static double radToDeg(double angleRad) {
    return angleRad / Math.PI * 180;
}

From source file:Main.java

private static double rad2deg(double rad) {
    return (rad * 180.0 / Math.PI);
}

From source file:Main.java

/**
 * Returns the lat/lng as an "Offset Normalized Mercator" pixel coordinate,
 * this is a coordinate that runs from 0..1 in latitude and longitude with 0,0 being
 * top left. Normalizing means that this routine can be used at any zoom level and
 * then multiplied by a power of two to get actual pixel coordinates.
 *//*w w  w .j a v  a2  s  .c  o  m*/
public static Point2D toNormalisedPixelCoords(double lat, double lng) {
    // first convert to Mercator projection
    // first convert the lat lon to mercator coordintes.
    if (lng > 180) {
        lng -= 360;
    }

    lng /= 360;
    lng += 0.5;

    lat = 0.5 - ((Math.log(Math.tan((Math.PI / 4) + ((0.5 * Math.PI * lat) / 180))) / Math.PI) / 2.0);

    return new Point2D.Double(lng, lat);
}

From source file:Main.java

/**
 * Function: arcToCurves//from  ww w  .j  a v a 2  s.c o  m
 * 
 * Converts the given arc to a series of curves.
 */
public static double[] arcToCurves(double x0, double y0, double r1, double r2, double angle,
        double largeArcFlag, double sweepFlag, double x, double y) {
    x -= x0;
    y -= y0;

    if (r1 == 0 || r2 == 0) {
        return new double[0];
    }

    double fS = sweepFlag;
    double psai = angle;
    r1 = Math.abs(r1);
    r2 = Math.abs(r2);
    double ctx = -x / 2;
    double cty = -y / 2;
    double cpsi = Math.cos(psai * Math.PI / 180);
    double spsi = Math.sin(psai * Math.PI / 180);
    double rxd = cpsi * ctx + spsi * cty;
    double ryd = -1 * spsi * ctx + cpsi * cty;
    double rxdd = rxd * rxd;
    double rydd = ryd * ryd;
    double r1x = r1 * r1;
    double r2y = r2 * r2;
    double lamda = rxdd / r1x + rydd / r2y;
    double sds;

    if (lamda > 1) {
        r1 = Math.sqrt(lamda) * r1;
        r2 = Math.sqrt(lamda) * r2;
        sds = 0;
    } else {
        double seif = 1;

        if (largeArcFlag == fS) {
            seif = -1;
        }

        sds = seif * Math.sqrt((r1x * r2y - r1x * rydd - r2y * rxdd) / (r1x * rydd + r2y * rxdd));
    }

    double txd = sds * r1 * ryd / r2;
    double tyd = -1 * sds * r2 * rxd / r1;
    double tx = cpsi * txd - spsi * tyd + x / 2;
    double ty = spsi * txd + cpsi * tyd + y / 2;
    double rad = Math.atan2((ryd - tyd) / r2, (rxd - txd) / r1) - Math.atan2(0, 1);
    double s1 = (rad >= 0) ? rad : 2 * Math.PI + rad;
    rad = Math.atan2((-ryd - tyd) / r2, (-rxd - txd) / r1) - Math.atan2((ryd - tyd) / r2, (rxd - txd) / r1);
    double dr = (rad >= 0) ? rad : 2 * Math.PI + rad;

    if (fS == 0 && dr > 0) {
        dr -= 2 * Math.PI;
    } else if (fS != 0 && dr < 0) {
        dr += 2 * Math.PI;
    }

    double sse = dr * 2 / Math.PI;
    int seg = (int) Math.ceil(sse < 0 ? -1 * sse : sse);
    double segr = dr / seg;
    double t = 8 / 3 * Math.sin(segr / 4) * Math.sin(segr / 4) / Math.sin(segr / 2);
    double cpsir1 = cpsi * r1;
    double cpsir2 = cpsi * r2;
    double spsir1 = spsi * r1;
    double spsir2 = spsi * r2;
    double mc = Math.cos(s1);
    double ms = Math.sin(s1);
    double x2 = -t * (cpsir1 * ms + spsir2 * mc);
    double y2 = -t * (spsir1 * ms - cpsir2 * mc);
    double x3 = 0;
    double y3 = 0;

    double[] result = new double[seg * 6];

    for (int n = 0; n < seg; ++n) {
        s1 += segr;
        mc = Math.cos(s1);
        ms = Math.sin(s1);

        x3 = cpsir1 * mc - spsir2 * ms + tx;
        y3 = spsir1 * mc + cpsir2 * ms + ty;
        double dx = -t * (cpsir1 * ms + spsir2 * mc);
        double dy = -t * (spsir1 * ms - cpsir2 * mc);

        // CurveTo updates x0, y0 so need to restore it
        int index = n * 6;
        result[index] = x2 + x0;
        result[index + 1] = y2 + y0;
        result[index + 2] = x3 - dx + x0;
        result[index + 3] = y3 - dy + y0;
        result[index + 4] = x3 + x0;
        result[index + 5] = y3 + y0;

        x2 = x3 + dx;
        y2 = y3 + dy;
    }

    return result;
}