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.jlab.clas.swimtools.Swim.java

/**
 *
 * @param direction/*from  w  ww.  jav a 2s.  c  o  m*/
 *            +1 for out -1 for in
 * @param x0
 * @param y0
 * @param z0
 * @param thx
 * @param thy
 * @param p
 * @param charge
 */
public void SetSwimParameters(int direction, double x0, double y0, double z0, double thx, double thy, double p,
        int charge) {

    // x,y,z in m = swimmer units
    _x0 = x0 / 100;
    _y0 = y0 / 100;
    _z0 = z0 / 100;
    this.checkR(_x0, _y0, _z0);
    double pz = direction * p / Math.sqrt(thx * thx + thy * thy + 1);
    double px = thx * pz;
    double py = thy * pz;
    _phi = Math.toDegrees(FastMath.atan2(py, px));
    _pTot = Math.sqrt(px * px + py * py + pz * pz);
    _theta = Math.toDegrees(Math.acos(pz / _pTot));

    _charge = direction * charge;
}

From source file:com.github.aptd.simulation.elements.common.CMath.java

/**
 * returns the angel// w  ww  .j a  v a 2 s  .  c o m
 *
 * @param p_first first vector
 * @param p_second second vector
 * @return pair of angel in radians and boolean for calulation correctness
 */
public static Pair<Double, Boolean> angle(final DoubleMatrix1D p_first, final DoubleMatrix1D p_second) {
    final double l_first = ALGEBRA.norm2(p_first);
    final double l_second = ALGEBRA.norm2(p_second);

    return (l_first == 0) || (l_second == 0) ? new ImmutablePair<>(0.0, false)
            : new ImmutablePair<>(
                    Math.acos(ALGEBRA.mult(p_first, p_second) / (Math.sqrt(l_first) * Math.sqrt(l_second))),
                    true);
}

From source file:org.apache.flink.table.runtime.functions.SqlFunctionUtils.java

public static double acos(Decimal a) {
    return Math.acos(a.doubleValue());
}

From source file:com.nextbreakpoint.nextfractal.mandelbrot.core.Expression.java

public static double funcAcos(double x) {
    return Math.acos(x);
}

From source file:edu.umass.cs.iesl.pdf2meta.cli.extract.pdfbox.pagedrawer.Invoke.java

/**
 * process : Do : Paint the specified XObject (section 4.7).
 * @param operator The operator that is being executed.
 * @param arguments List/*from  w w  w .j  a v  a 2  s.  c  o  m*/
 * @throws java.io.IOException If there is an error invoking the sub object.
 */
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException {
    GraphicsAwarePDFStreamEngine drawer = (GraphicsAwarePDFStreamEngine) context;
    PDPage page = drawer.getPage();
    COSName objectName = (COSName) arguments.get(0);
    Map xobjects = drawer.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 {
            image.setGraphicsState(drawer.getGraphicsState());
            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 = drawer.getPageSize().getHeight();

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

            Matrix ctm = drawer.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);
            drawer.drawImage(awtImage, ctmAT);
        } catch (Exception e) {
            e.printStackTrace();
            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 invoke = (COSStream) form.getCOSObject();
        PDResources pdResources = form.getResources();
        if (pdResources == null) {
            pdResources = page.findResources();
        }
        // 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);
        }
        getContext().processSubStream(page, pdResources, invoke);

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

From source file:org.jlab.clas.swimtools.Swim.java

/**
 * Sets the parameters used by swimmer based on the input track state vector
 * parameters swimming outwards/*from w ww .ja v a  2s  .com*/
 *
 * @param superlayerIdx
 * @param layerIdx
 * @param x0
 * @param y0
 * @param thx
 * @param thy
 * @param p
 * @param charge
 */
public void SetSwimParameters(int superlayerIdx, int layerIdx, double x0, double y0, double z0, double thx,
        double thy, double p, int charge) {
    // z at a given DC plane in the tilted coordinate system
    // x,y,z in m = swimmer units
    _x0 = x0 / 100;
    _y0 = y0 / 100;
    _z0 = z0 / 100;
    this.checkR(_x0, _y0, _z0);
    double pz = p / Math.sqrt(thx * thx + thy * thy + 1);
    double px = thx * pz;
    double py = thy * pz;
    _phi = Math.toDegrees(FastMath.atan2(py, px));
    _pTot = Math.sqrt(px * px + py * py + pz * pz);
    _theta = Math.toDegrees(Math.acos(pz / _pTot));

    _charge = charge;

}

From source file:org.apache.pdfbox.util.operator.pagedrawer.Invoke.java

/**
 * process : Do : Paint the specified XObject (section 4.7).
 * @param operator The operator that is being executed.
 * @param arguments List/* w  ww . ja  v  a  2 s . c  o m*/
 * @throws IOException If there is an error invoking the sub object.
 */
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException {
    PageDrawer drawer = (PageDrawer) context;
    PDPage page = drawer.getPage();
    COSName objectName = (COSName) arguments.get(0);
    Map<String, PDXObject> xobjects = drawer.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(drawer.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 = drawer.getPageSize().getHeight();

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

            Matrix ctm = drawer.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);
            drawer.drawImage(awtImage, ctmAT);
        } catch (Exception e) {
            e.printStackTrace();
            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 invoke = (COSStream) form.getCOSObject();
        PDResources pdResources = form.getResources();
        if (pdResources == null) {
            pdResources = page.findResources();
        }
        // 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);
        }
        getContext().processSubStream(page, pdResources, invoke);

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

From source file:fr.ritaly.dungeonmaster.Utils.java

public static double angle(int x1, int y1, int x2, int y2) {
    // Composantes du vecteur ?
    final int x = x2 - x1;
    final int y = y2 - y1;

    // Module du vecteur ?
    final double hypothenus = Math.sqrt((x * x) + (y * y));

    if (y > 0) {
        return Math.acos(x / hypothenus);
    } else {//from w w w. j a  va  2s  .c om
        return -Math.acos(x / hypothenus);
    }
}

From source file:org.jlab.clas.swimtools.Swim.java

/**
 * Sets the parameters used by swimmer based on the input track parameters
 *
 * @param x0/*ww w  .j a  v a  2s .co  m*/
 * @param y0
 * @param z0
 * @param px
 * @param py
 * @param pz
 * @param charge
 */
public void SetSwimParameters(double x0, double y0, double z0, double px, double py, double pz, int charge) {
    _x0 = x0 / 100;
    _y0 = y0 / 100;
    _z0 = z0 / 100;
    this.checkR(_x0, _y0, _z0);
    _phi = Math.toDegrees(FastMath.atan2(py, px));
    _pTot = Math.sqrt(px * px + py * py + pz * pz);
    _theta = Math.toDegrees(Math.acos(pz / _pTot));

    _charge = charge;

}

From source file:de.thkwalter.et.betriebspunkt.Betriebspunkt.java

/**
 * Diese Methode berechnet auf Basis der Eingabewerte alle fehlenden Gren.
 *//*w w  w .j a v a  2  s .co m*/
private void rechnen() {
    // Die Scheinleistung (in kVA) wird berechnet.
    this.p_s = Math.sqrt(3.0) * this.getU_LL() * this.getI_L() / 1000.0;

    // Die Phasenverschiebung zwischen Strangstrom und Strangspannung wird berechnet.
    this.cosPhi = this.p_el / this.p_s;

    // Ein vom Schaltungstyp abhngiger Faktor wird berechnet.
    double faktor = this.schaltungstyp == Schaltungstyp.STERN ? 1.0 : 1.0 / Math.sqrt(3.0);

    // Der Realteil des Strangstroms (in A) wird berechnet.
    double i_s_re = faktor * this.i_L * this.cosPhi;

    // Der Imaginrteil des Strangstroms (in A) wird berechnet. Dabei ist zu beachten, dass fr elektrische Maschinen der
    // Phasenwinkel phi negativ ist.
    double i_s_im = faktor * this.i_L * Math.sin(-Math.acos(this.cosPhi));

    // Der komplexe Zeiger des Stnderstroms (in A) wird erzeugt.
    this.z_i_s = new Complex(i_s_re, i_s_im);
}