Example usage for java.lang Math cos

List of usage examples for java.lang Math cos

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double cos(double a) 

Source Link

Document

Returns the trigonometric cosine of an angle.

Usage

From source file:naftoreiclag.villagefive.util.math.Vec2.java

public Vec2(Angle angle) {
    this.x = Math.cos(angle.getX());
    this.y = Math.sin(angle.getX());
}

From source file:com.ables.pix.utility.PictureOps.java

public static BufferedImage tilt(BufferedImage image, double rotation) {
    double sin = Math.abs(Math.sin(getAngle()));
    double cos = Math.abs(Math.cos(getAngle()));
    int w = image.getWidth(), h = image.getHeight();

    int neww = (int) Math.floor(w * cos + sin * h), newh = (int) Math.floor(h * cos + sin * w);
    GraphicsConfiguration gc = getDefaultConfiguration();
    BufferedImage rotated = gc.createCompatibleImage(neww, newh);
    Graphics2D g = rotated.createGraphics();
    g.translate((neww - w) / 2, (newh - h / 2));
    g.rotate(getAngle(), w / 2, h / 2);/*from  ww w  . j  av  a  2  s .  c o  m*/
    g.drawRenderedImage(image, null);
    g.dispose();
    return rotated;
}

From source file:net.nicoulaj.benchmarks.math.DoubleCos.java

@GenerateMicroBenchmark
public void math(BlackHole hole) {
    for (int i = 0; i < data.length - 1; i++)
        hole.consume(Math.cos(data[i]));
}

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

@Test
/**/*from   w w  w  .j  a v a2 s . co m*/
  * 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:de.tuberlin.uebb.jdae.diff.partial.PDOperations.java

public final void cos(final double[] values, final double[] target) {
    compose(Math.cos(values[0]), -Math.sin(values[0]), values, target);
}

From source file:Quaternion.java

/**
 * Return a quaternion representing a rotation of theta radians about the given n axis
 * @param theta/*  ww w.  j a va  2 s. co  m*/
 * @param n
 * @return
 */
public static Quaternion rotation(double theta, Vector3 n) {
    return new Quaternion((double) Math.cos(theta / 2.0f), n.multiply((double) Math.sin(theta / 2.0f)));
}

From source file:controller.JsonController.java

public ArrayList<JsonModel> ReadJsonCalc() throws FileNotFoundException, IOException, ParseException {

    FileInputStream fstream = new FileInputStream("gistfile1.txt");
    BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
    String strLine;//  w  w w .ja  v a2  s. c om
    ArrayList<JsonModel> result = new ArrayList<>();
    JsonModel model;

    double L1, G1, L2, G2;

    //Read File Line By Line
    while ((strLine = br.readLine()) != null) {
        model = new JsonModel();
        JSONParser parser = new JSONParser();
        Object obj = parser.parse(strLine);
        JSONObject jsonObject = (JSONObject) obj;

        model.setLatitude((double) Double.parseDouble((String) jsonObject.get("latitude")));
        model.setLongitude((double) Double.parseDouble((String) jsonObject.get("longitude")));
        model.setUserIid((int) Integer.parseInt((String) jsonObject.get("user_id").toString()));
        model.setName(((String) jsonObject.get("name")));

        L1 = Math.toRadians(model.getLatitudeDefault());
        G1 = Math.toRadians(model.getLongitudeDefault());
        L2 = Math.toRadians(model.getLatitude());
        G2 = Math.toRadians(model.getLongitude());

        // do the spherical trig calculation
        double angle = Math.acos(Math.sin(L1) * Math.sin(L2) + Math.cos(L1) * Math.cos(L2) * Math.cos(G1 - G2));
        // convert back to degrees
        angle = Math.toDegrees(angle);

        // each degree on a great circle of Earth is 69.1105 miles
        double distance = (69.1105 * angle) * 1.609344;

        if (distance <= 100)
            result.add(model);
    }
    Collections.sort(result);

    return result;
}

From source file:demo.support.NavUtils.java

/**
 * Returns bearing of position 2 from position 1.
 * @param pt1/*from  w  w w.j  av a2s  . c  o  m*/
 * @param pt2
 * @return
 */
public static double getBearing(Point pt1, Point pt2) {
    double longitude1 = pt1.getLongitude();
    double longitude2 = pt2.getLongitude();
    double latitude1 = Math.toRadians(pt1.getLatitude());
    double latitude2 = Math.toRadians(pt2.getLatitude());
    double longDiff = Math.toRadians(longitude2 - longitude1);
    double y = Math.sin(longDiff) * Math.cos(latitude2);
    double x = Math.cos(latitude1) * Math.sin(latitude2)
            - Math.sin(latitude1) * Math.cos(latitude2) * Math.cos(longDiff);
    return (Math.toDegrees(Math.atan2(y, x)) + 360) % 360;
}

From source file:DrawShapes_2008.java

/**
 * Generates a star Shape from the given location, radii, and points
 * parameters. The Shape is created by constructing a GeneralPath
 * that moves between the inner and outer rings.
 *//*from  w ww.jav  a 2 s  . c  o m*/
private static Shape generateStar(double x, double y, double innerRadius, double outerRadius, int pointsCount) {
    GeneralPath path = new GeneralPath();

    double outerAngleIncrement = 2 * Math.PI / pointsCount;

    double outerAngle = 0.0;
    double innerAngle = outerAngleIncrement / 2.0;

    x += outerRadius;
    y += outerRadius;

    float x1 = (float) (Math.cos(outerAngle) * outerRadius + x);
    float y1 = (float) (Math.sin(outerAngle) * outerRadius + y);

    float x2 = (float) (Math.cos(innerAngle) * innerRadius + x);
    float y2 = (float) (Math.sin(innerAngle) * innerRadius + y);

    path.moveTo(x1, y1);
    path.lineTo(x2, y2);

    outerAngle += outerAngleIncrement;
    innerAngle += outerAngleIncrement;

    for (int i = 1; i < pointsCount; i++) {
        x1 = (float) (Math.cos(outerAngle) * outerRadius + x);
        y1 = (float) (Math.sin(outerAngle) * outerRadius + y);

        path.lineTo(x1, y1);

        x2 = (float) (Math.cos(innerAngle) * innerRadius + x);
        y2 = (float) (Math.sin(innerAngle) * innerRadius + y);

        path.lineTo(x2, y2);

        outerAngle += outerAngleIncrement;
        innerAngle += outerAngleIncrement;
    }

    path.closePath();
    return path;
}

From source file:org.eclipse.swt.examples.graphics.StarPolyTab.java

@Override
public void paint(GC gc, int width, int height) {
    int centerX = width / 2;
    int centerY = height / 2;
    int pos = 0;/*from  w  ww  .jav  a 2 s. c om*/
    for (int i = 0; i < POINTS; ++i) {
        double r = Math.PI * 2 * pos / POINTS;
        radial[i * 2] = (int) ((1 + Math.cos(r)) * centerX);
        radial[i * 2 + 1] = (int) ((1 + Math.sin(r)) * centerY);
        pos = (pos + POINTS / 2) % POINTS;
    }
    gc.setFillRule(fillRuleCb.getSelectionIndex() != 0 ? SWT.FILL_WINDING : SWT.FILL_EVEN_ODD);
    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_YELLOW));
    gc.fillPolygon(radial);
    gc.drawPolygon(radial);
}