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:chiliad.parser.pdf.extractor.vectorgraphics.operator.Invoke.java

/**
 * process : Do : Paint the specified XObject (section 4.7).
 *
 * @param operator The operator that is being executed.
 * @param arguments List/*w  ww.  j a  va2 s.c om*/
 * @throws IOException If there is an error invoking the sub object.
 */
@Override
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException {
    VectorGraphicsExtractor extractor = (VectorGraphicsExtractor) context;

    PDPage page = extractor.getPage();
    COSName objectName = (COSName) arguments.get(0);
    Map<String, PDXObject> xobjects = extractor.getResources().getXObjects();
    PDXObject xobject = (PDXObject) xobjects.get(objectName.getName());
    if (xobject == null) {
        LOG.warn("Can't find the XObject for '" + objectName.getName() + "'");
    } else if (xobject instanceof PDXObjectImage) {
        PDXObjectImage image = (PDXObjectImage) xobject;
        try {
            if (image.getImageMask()) {
                // set the current non stroking colorstate, so that it can
                // be used to create a stencil masked image
                image.setStencilColor(extractor.getGraphicsState().getNonStrokingColor());
            }
            BufferedImage awtImage = image.getRGBImage();
            if (awtImage == null) {
                LOG.warn("getRGBImage returned NULL");
                return;//TODO PKOCH
            }
            int imageWidth = awtImage.getWidth();
            int imageHeight = awtImage.getHeight();
            double pageHeight = extractor.getPageSize().getHeight();

            LOG.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight);

            Matrix ctm = extractor.getGraphicsState().getCurrentTransformationMatrix();
            float yScaling = ctm.getYScale();
            float angle = (float) Math.acos(ctm.getValue(0, 0) / ctm.getXScale());
            if (ctm.getValue(0, 1) < 0 && ctm.getValue(1, 0) > 0) {
                angle = (-1) * angle;
            }
            ctm.setValue(2, 1, (float) (pageHeight - ctm.getYPosition() - Math.cos(angle) * yScaling));
            ctm.setValue(2, 0, (float) (ctm.getXPosition() - Math.sin(angle) * yScaling));
            // because of the moved 0,0-reference, we have to shear in the opposite direction
            ctm.setValue(0, 1, (-1) * ctm.getValue(0, 1));
            ctm.setValue(1, 0, (-1) * ctm.getValue(1, 0));
            AffineTransform ctmAT = ctm.createAffineTransform();
            ctmAT.scale(1f / imageWidth, 1f / imageHeight);
            extractor.drawImage(awtImage, ctmAT);
        } catch (Exception e) {
            LOG.error(e, e);
        }
    } else if (xobject instanceof PDXObjectForm) {
        // save the graphics state
        context.getGraphicsStack().push((PDGraphicsState) context.getGraphicsState().clone());

        PDXObjectForm form = (PDXObjectForm) xobject;
        COSStream formContentstream = form.getCOSStream();
        // find some optional resources, instead of using the current resources
        PDResources pdResources = form.getResources();
        // if there is an optional form matrix, we have to map the form space to the user space
        Matrix matrix = form.getMatrix();
        if (matrix != null) {
            Matrix xobjectCTM = matrix.multiply(context.getGraphicsState().getCurrentTransformationMatrix());
            context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM);
        }
        if (form.getBBox() != null) {
            PDGraphicsState graphicsState = context.getGraphicsState();
            PDRectangle bBox = form.getBBox();

            float x1 = bBox.getLowerLeftX();
            float y1 = bBox.getLowerLeftY();
            float x2 = bBox.getUpperRightX();
            float y2 = bBox.getUpperRightY();

            Point2D p0 = extractor.transformedPoint(x1, y1);
            Point2D p1 = extractor.transformedPoint(x2, y1);
            Point2D p2 = extractor.transformedPoint(x2, y2);
            Point2D p3 = extractor.transformedPoint(x1, y2);

            GeneralPath bboxPath = new GeneralPath();
            bboxPath.moveTo((float) p0.getX(), (float) p0.getY());
            bboxPath.lineTo((float) p1.getX(), (float) p1.getY());
            bboxPath.lineTo((float) p2.getX(), (float) p2.getY());
            bboxPath.lineTo((float) p3.getX(), (float) p3.getY());
            bboxPath.closePath();

            Area resultClippingArea = new Area(graphicsState.getCurrentClippingPath());
            Area newArea = new Area(bboxPath);
            resultClippingArea.intersect(newArea);

            graphicsState.setCurrentClippingPath(resultClippingArea);
        }
        getContext().processSubStream(page, pdResources, formContentstream);

        // restore the graphics state
        context.setGraphicsState((PDGraphicsState) context.getGraphicsStack().pop());
    }
}

From source file:com.grayfox.server.service.PoiService.java

private double distanceBetween(Location location1, Location location2) {
    double fi1 = Math.toRadians(location1.getLatitude());
    double fi2 = Math.toRadians(location2.getLatitude());
    double deltaLambda = Math.toRadians(location2.getLongitude() - location1.getLongitude());
    return Math.acos(Math.sin(fi1) * Math.sin(fi2) + Math.cos(fi1) * Math.cos(fi2) * Math.cos(deltaLambda))
            * Constants.Ints.EARTH_RADIUS;
}

From source file:org.renjin.primitives.MathGroup.java

@Deferrable
@Builtin/*from   w ww  . j  av a 2s . c o m*/
@DataParallel(value = PreserveAttributeStyle.ALL, passNA = true)
public static double acos(double val) {
    return Math.acos(val);
}

From source file:ch.algotrader.option.SABR.java

private static double getSmallestRoot(double cubic, double quadratic, double linear, double constant) {

    double a = quadratic / cubic;
    double b = linear / cubic;
    double C = constant / cubic;
    double Q = (Math.pow(a, 2) - 3 * b) / 9.0;
    double r = (2 * Math.pow(a, 3) - 9 * a * b + 27 * C) / 54.0;

    double root = 0;

    if (Math.pow(r, 2) - Math.pow(Q, 3) >= 0) {

        double capA = -Math.signum(r)
                * Math.pow(Math.abs(r) + Math.sqrt(Math.pow(r, 2) - Math.pow(Q, 3)), 1.0 / 3.0);
        double capB = 0;
        if (capA != 0) {
            capB = Q / capA;/*  w ww .ja va2  s  .c  o m*/
        }
        root = capA + capB - a / 3.0;

    } else {

        double theta = Math.acos(r / Math.pow(Q, 1.5));
        double root1 = -2 * Math.sqrt(Q) * Math.cos(theta / 3.0) - a / 3.0;
        double root2 = -2 * Math.sqrt(Q) * Math.cos(theta / 3.0 + 2.0943951023932) - a / 3.0;
        double root3 = -2 * Math.sqrt(Q) * Math.cos(theta / 3.0 - 2.0943951023932) - a / 3.0;

        // find the smallest positive one
        if (root1 > 0) {
            root = root1;
        } else if (root2 > 0) {
            root = root2;
        } else if (root3 > 0) {
            root = root3;
        }

        if (root2 > 0 && root2 < root) {
            root = root2;
        }
        if (root3 > 0 && root3 < root) {
            root = root3;
        }
    }

    return root;
}

From source file:org.helioviewer.jhv.plugins.hekplugin.HEKPlugin.java

/**
 * The actual rendering routine//  ww  w .j  ava2  s  . co  m
 * 
 * @param g
 *            - PhysicalRenderGraphics to render to
 * @param evt
 *            - Event to draw
 * @param now
 *            - Current point in time
 */
public void drawIcon(GL2 gl, HEKEvent evt, Date now) {
    if (evt == null || !evt.isVisible(now))
        return;

    boolean large = evt.getShowEventInfo();
    String type = evt.getString("event_type");
    int offSetFactor = -1;
    for (HEKIcon.HEKIcons hekIcon : HEKIcon.HEKIcons.values()) {
        if (hekIcon.name().startsWith(type)) {
            offSetFactor = hekIcon.ordinal();
            break;
        }
    }
    if (offSetFactor >= 0) {
        SphericalCoord heliographicCoordinate = evt.getStony(now);
        Vector3d coords = HEKEvent.convertToSceneCoordinates(heliographicCoordinate, now);
        double x = coords.x;
        double y = coords.y;
        double z = coords.z;

        gl.glEnable(GL2.GL_TEXTURE_2D);
        gl.glBindTexture(GL2.GL_TEXTURE_2D, HEKIcon.getOpenGLTextureId());
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);

        float imageScaleFactorH = HEKIcon.getImageScaleFactorHeight();

        double scale = large ? 0.0004 : 0.0002;
        double width2 = Plugins.getViewPortSize() * scale;
        double height2 = Plugins.getViewPortSize() * scale;

        Vector3d sourceDir = new Vector3d(0, 0, -1);
        Vector3d targetDir = new Vector3d(x, y, z);

        double angle = Math.acos(sourceDir.dot(targetDir) / (sourceDir.length() * targetDir.length()));
        Vector3d axis = sourceDir.cross(targetDir);
        Matrix4d r = Matrix4d.createRotationMatrix(angle, axis.normalized()).translatedAbsolute(x, y, z);

        Vector3d p0 = new Vector3d(-width2, -height2, 0);
        Vector3d p1 = new Vector3d(-width2, height2, 0);
        Vector3d p2 = new Vector3d(width2, height2, 0);
        Vector3d p3 = new Vector3d(width2, -height2, 0);

        p0 = r.multiply(p0);
        p1 = r.multiply(p1);
        p2 = r.multiply(p2);
        p3 = r.multiply(p3);

        gl.glColor4f(1, 1, 1, 1);

        gl.glBegin(GL2.GL_QUADS);

        gl.glTexCoord2f(0.0f, offSetFactor * imageScaleFactorH);
        gl.glVertex3d(p0.x, p0.y, p0.z);
        gl.glTexCoord2f(0.0f, (offSetFactor + 1) * imageScaleFactorH);
        gl.glVertex3d(p1.x, p1.y, p1.z);
        gl.glTexCoord2f(1.0f, (offSetFactor + 1) * imageScaleFactorH);
        gl.glVertex3d(p2.x, p2.y, p2.z);
        gl.glTexCoord2f(1.0f, offSetFactor * imageScaleFactorH);
        gl.glVertex3d(p3.x, p3.y, p3.z);

        gl.glEnd();
        gl.glDisable(GL2.GL_TEXTURE_2D);
    }
}

From source file:org.apache.drill.exec.fn.impl.TestNewMathFunctions.java

@Test
public void testTrigoMathFunc() throws Throwable {
    final Object[] expected = new Object[] { Math.sin(45), Math.cos(45), Math.tan(45), Math.asin(45),
            Math.acos(45), Math.atan(45), Math.sinh(45), Math.cosh(45), Math.tanh(45) };
    runTest(expected, "functions/testTrigoMathFunctions.json");
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionMath.java

/**
 * data provider generator for single-value tests
 * @return data/*  ww  w.j av a 2  s.c om*/
 */
@DataProvider
public static Object[] singlevaluegenerate() {
    return Stream.concat(

            singlevaluetestcase(

                    Stream.of(2.5, 9.1, 111.7, 889.9),

                    Stream.of(CNextPrime.class),

                    (i) -> (double) Primes.nextPrime(i.intValue())),

            singlevaluetestcase(

                    Stream.of(-2, -6, 4, -1, -5, 3, 49, 30, 6, 5, 1.3, 2.8, 9.7, 1, 8, 180, Math.PI),

                    Stream.of(CAbs.class, CACos.class, CASin.class, CATan.class, CCeil.class, CCos.class,
                            CCosh.class, CDegrees.class, CExp.class, CIsPrime.class, CLog.class, CLog10.class,
                            CFloor.class, CRadians.class, CRound.class, CSignum.class, CSin.class, CSinh.class,
                            CSqrt.class, CTan.class, CTanh.class),

                    (i) -> Math.abs(i.doubleValue()), (i) -> Math.acos(i.doubleValue()),
                    (i) -> Math.asin(i.doubleValue()), (i) -> Math.atan(i.doubleValue()),
                    (i) -> Math.ceil(i.doubleValue()), (i) -> Math.cos(i.doubleValue()),
                    (i) -> Math.cosh(i.doubleValue()), (i) -> Math.toDegrees(i.doubleValue()),
                    (i) -> Math.exp(i.doubleValue()), (i) -> Primes.isPrime(i.intValue()),
                    (i) -> Math.log(i.doubleValue()), (i) -> Math.log10(i.doubleValue()),
                    (i) -> Math.floor(i.doubleValue()), (i) -> Math.toRadians(i.doubleValue()),
                    (i) -> Math.round(i.doubleValue()), (i) -> Math.signum(i.doubleValue()),
                    (i) -> Math.sin(i.doubleValue()), (i) -> Math.sinh(i.doubleValue()),
                    (i) -> Math.sqrt(i.doubleValue()), (i) -> Math.tan(i.doubleValue()),
                    (i) -> Math.tanh(i.doubleValue()))

    ).toArray();
}

From source file:outlineDescriptor.Transform.java

private void doTransform(double[][] pointData) {
    Array2DRowRealMatrix dataMatrix = transform(new Array2DRowRealMatrix(pointData), aSteps);
    Array2DRowRealMatrix v, s;// ww  w.  j ava2 s  .c  o  m
    double dim1X, dim1Y;
    double eigenVal1, eigenVal2;
    double aCos;

    /*
            
    calculating the SVD
    v - a non-singular matrix containing the eigenvectors of the input matrix
    s - a diagonal matrix containing the corresponding eigenvalues
            
    */

    SingularValueDecomposition svd = new SingularValueDecomposition(dataMatrix);

    v = (Array2DRowRealMatrix) svd.getV();
    s = (Array2DRowRealMatrix) svd.getS();
    dim1X = v.getEntry(0, 0);
    dim1Y = v.getEntry(1, 0);

    eigenVal1 = s.getEntry(0, 0);
    eigenVal2 = s.getEntry(1, 1);

    coherence = (eigenVal1 - eigenVal2) / (eigenVal2 + eigenVal1);
    aCos = dim1Y / Math.sqrt(dim1X * dim1X + dim1Y * dim1Y);
    svdMat = dataMatrix;
    angle = Math.acos(aCos);
    angle = Math.PI / 2 - angle;
}

From source file:edu.stanford.cfuller.imageanalysistools.filter.Kernel.java

public static Complex[][] getRandomSinglePlaneKernelMatrix(int size0, int size1) {

    Complex[][] toReturn = new Complex[size0][size1];
    for (int i = 0; i < size0; i++) {
        for (int j = 0; j < size1; j++) {
            double angle = Math.random() * 2 - 1;
            angle = Math.acos(angle);
            //toReturn[i][j] = new Complex(Math.cos(angle), Math.sin(angle));
            toReturn[i][j] = new Complex(Math.random() * 2 - 1, Math.random() * 2 - 1);
            //toReturn[i][j] = new Complex(1,0);
        }/*from   www  .j  av  a  2 s .  c om*/
    }

    return toReturn;
}

From source file:org.marinemc.util.Location.java

/**
 * Face the yaw towards the specified location
 *
 * @param p//w w  w  . ja v  a  2 s. c o  m
 *            Location too look towards
 * @return New Location (this)
 */
public Location lookAt(final Location p) {
    final double l = p.getX() - getX();
    final double w = p.getZ() - getX();
    final double c = Math.sqrt(l * l + w * w);
    final double alpha1 = -Math.asin(l / c) / Math.PI * 180;
    final double alpha2 = Math.acos(w / c) / Math.PI * 180;
    yaw = (float) (alpha2 > 90 ? 180 - alpha1 : alpha1);
    return this;
}