Example usage for java.lang Math acos

List of usage examples for java.lang Math acos

Introduction

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

Prototype

public static double acos(double a) 

Source Link

Document

Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi.

Usage

From source file:org.apache.hadoop.hive.ql.udf.UDFAcos.java

public DoubleWritable evaluate(DoubleWritable a) {
    if (a == null) {
        return null;
    } else {// w w w  .  java 2 s.c o  m
        result.set(Math.acos(a.get()));
        return result;
    }
}

From source file:org.jcurl.model.PathSegmentTest.java

public void testTrafo() throws NoninvertibleTransformException {
    final Point2D x0 = new Point2D.Double(1.5, 2.5);
    // final Point2D x0 = new Point2D.Double(0, 0);
    final Point2D v0 = new Point2D.Double(2, 1);
    // build the trafo
    final AffineTransform rc2wc = new AffineTransform();
    {/*from  w  ww.  j a v  a2 s.co m*/
        rc2wc.rotate(-Math.acos((v0.getX() * 0 + v0.getY() * 1) / v0.distance(0, 0)), x0.getX(), x0.getY());
        rc2wc.translate(x0.getX(), x0.getY());
    }
    // check some points.
    // wc(x0) -> rc(0,0)
    Point2D tmp = rc2wc.inverseTransform(x0, null);
    assertEquals("", 0, tmp.getX(), 1e-9);
    assertEquals("", 0, tmp.getY(), 1e-9);

    // rc(0,1) -> wc(x0)
    tmp = rc2wc.transform(new Point2D.Double(0, 1), null);
    assertEquals("", x0.getX() + 0.8944271909999, tmp.getX(), 1e-6);
    assertEquals("", x0.getY() + 0.4472135954999, tmp.getY(), 1e-6);
}

From source file:com.opengamma.analytics.math.rootfinding.CubicRootFinder.java

/**
 * {@inheritDoc}//from  ww  w  .  j  a v  a2s. c  om
 * @throws IllegalArgumentException If the function is not cubic
 */
@Override
public ComplexNumber[] getRoots(final RealPolynomialFunction1D function) {
    Validate.notNull(function, "function");
    final double[] coefficients = function.getCoefficients();
    Validate.isTrue(coefficients.length == 4, "Function is not a cubic");
    final double divisor = coefficients[3];
    final double a = coefficients[2] / divisor;
    final double b = coefficients[1] / divisor;
    final double c = coefficients[0] / divisor;
    final double aSq = a * a;
    final double q = (aSq - 3 * b) / 9;
    final double r = (2 * a * aSq - 9 * a * b + 27 * c) / 54;
    final double rSq = r * r;
    final double qCb = q * q * q;
    final double constant = a / 3;
    if (rSq < qCb) {
        final double mult = -2 * Math.sqrt(q);
        final double theta = Math.acos(r / Math.sqrt(qCb));
        return new ComplexNumber[] { new ComplexNumber(mult * Math.cos(theta / 3) - constant, 0),
                new ComplexNumber(mult * Math.cos((theta + TWO_PI) / 3) - constant, 0),
                new ComplexNumber(mult * Math.cos((theta - TWO_PI) / 3) - constant, 0) };
    }
    final double s = -Math.signum(r) * Math.cbrt(Math.abs(r) + Math.sqrt(rSq - qCb));
    final double t = CompareUtils.closeEquals(s, 0, 1e-16) ? 0 : q / s;
    final double sum = s + t;
    final double real = -0.5 * sum - constant;
    final double imaginary = Math.sqrt(3) * (s - t) / 2;
    return new ComplexNumber[] { new ComplexNumber(sum - constant, 0), new ComplexNumber(real, imaginary),
            new ComplexNumber(real, -imaginary) };
}

From source file:org.netxilia.functions.MathFunctions.java

public double ACOS(double number) {
    return Math.acos(number);
}

From source file:resources.common.MathUtilities.java

public static boolean fov(Point3D o, Quaternion a, Point3D t, float fov) {
    return (Math.abs(Math.acos(Vector3D.dotProduct((new Vector3D(a.x, a.y, a.z)).normalize(),
            (new Vector3D(t.x - o.x, t.z - o.z, t.y - o.y)).normalize()))) <= (((int) fov) / 2));
}

From source file:Main.java

public static void cosineSimilarityCW() {
    Iterator<Integer> ids = CommentWordCount.keySet().iterator();
    while (ids.hasNext()) {
        int com_id = ids.next();
        Set<String> words1;
        words1 = CommentWordCount.get(com_id).keySet();
        Iterator<Integer> com_iter = CommentWordCount.keySet().iterator();
        while (com_iter.hasNext()) {
            int id = com_iter.next();
            if (com_id < id) {
                Set<String> words2;
                words2 = CommentWordCount.get(id).keySet();

                Vector<Integer> vecA = new Vector<Integer>();
                Vector<Integer> vecB = new Vector<Integer>();

                Iterator<String> w1 = words1.iterator();
                Iterator<String> w2 = words2.iterator();

                HashSet<String> imp = new HashSet<String>();
                while (w1.hasNext()) {
                    String s = w1.next();
                    imp.add(s);//from w ww.  j  a v a 2 s.c  om
                }
                while (w2.hasNext()) {
                    String s = w2.next();
                    imp.add(s);
                }
                for (String s : imp) {
                    if (CommentWordCount.get(com_id).containsKey(s)) {
                        vecA.add(CommentWordCount.get(com_id).get(s));
                    } else
                        vecA.add(0);

                    if (CommentWordCount.get(id).containsKey(s)) {
                        vecB.add(CommentWordCount.get(id).get(s));
                    } else
                        vecB.add(0);
                }

                //System.out.println("Size : A"+vecA.size()+" Size: B"+vecB.size()+"maxLen:"+maxlength);
                double similarity;
                int product = 0;
                double sumA = 0;
                double sumB = 0;
                for (int i = 0; i < vecA.size(); i++) {
                    product += vecA.elementAt(i) * vecB.elementAt(i);
                    sumA += vecA.elementAt(i) * vecA.elementAt(i);
                    sumB += vecB.elementAt(i) * vecB.elementAt(i);
                }
                sumA = Math.sqrt(sumA);
                sumB = Math.sqrt(sumB);
                similarity = product / (sumA * sumB);
                similarity = Math.acos(similarity) * 180 / Math.PI;
                //System.out.println("Result "+com_id+" "+id+" :"+similarity);

                if (similarity < 75) {
                    //System.out.println("Result "+com_id+" "+id);
                    if (Topic.containsKey(com_id)) {
                        int val = Topic.get(com_id);
                        val++;
                        Topic.put(com_id, val);
                    } else
                        Topic.put(com_id, 1);
                    if (Topic.containsKey(id)) {
                        int val = Topic.get(id);
                        val++;
                        Topic.put(id, val);
                    } else
                        Topic.put(id, 1);
                }

            }
        }
    }
}

From source file:org.esa.beam.util.math.FastMathTest.java

@Test
public void testMathACos() {
    for (double i = 0; i < numItr; ++i) {
        double val = Math.acos(i);
    }/*from  ww w . j av  a 2 s  .co m*/
}

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

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

From source file:com.example.blockcanary_demo.DemoFragment.java

private static double compute() {
    double result = 0;
    for (int i = 0; i < 1000000; ++i) {
        result += Math.acos(Math.cos(i));
        result -= Math.asin(Math.sin(i));
    }//from   w w  w  .j  a v a  2  s . c om
    return result;
}

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 ww  . j a  va  2  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;
}