Example usage for java.lang Math atan

List of usage examples for java.lang Math atan

Introduction

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

Prototype

public static double atan(double a) 

Source Link

Document

Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2.

Usage

From source file:org.apache.sysml.runtime.functionobjects.Builtin.java

public double execute(double in) throws DMLRuntimeException {
    switch (bFunc) {
    case SIN:// w w w. j  a va  2  s  .  c o m
        return FASTMATH ? FastMath.sin(in) : Math.sin(in);
    case COS:
        return FASTMATH ? FastMath.cos(in) : Math.cos(in);
    case TAN:
        return FASTMATH ? FastMath.tan(in) : Math.tan(in);
    case ASIN:
        return FASTMATH ? FastMath.asin(in) : Math.asin(in);
    case ACOS:
        return FASTMATH ? FastMath.acos(in) : Math.acos(in);
    case ATAN:
        return Math.atan(in); //faster in Math
    case CEIL:
        return FASTMATH ? FastMath.ceil(in) : Math.ceil(in);
    case FLOOR:
        return FASTMATH ? FastMath.floor(in) : Math.floor(in);
    case LOG:
        return FASTMATH ? FastMath.log(in) : Math.log(in);
    case LOG_NZ:
        return (in == 0) ? 0 : FASTMATH ? FastMath.log(in) : Math.log(in);
    case ABS:
        return Math.abs(in); //no need for FastMath         
    case SIGN:
        return FASTMATH ? FastMath.signum(in) : Math.signum(in);
    case SQRT:
        return Math.sqrt(in); //faster in Math      
    case EXP:
        return FASTMATH ? FastMath.exp(in) : Math.exp(in);
    case ROUND:
        return Math.round(in); //no need for FastMath

    case PLOGP:
        if (in == 0.0)
            return 0.0;
        else if (in < 0)
            return Double.NaN;
        else
            return (in * (FASTMATH ? FastMath.log(in) : Math.log(in)));

    case SPROP:
        //sample proportion: P*(1-P)
        return in * (1 - in);

    case SIGMOID:
        //sigmoid: 1/(1+exp(-x))
        return FASTMATH ? 1 / (1 + FastMath.exp(-in)) : 1 / (1 + Math.exp(-in));

    case SELP:
        //select positive: x*(x>0)
        return (in > 0) ? in : 0;

    default:
        throw new DMLRuntimeException("Builtin.execute(): Unknown operation: " + bFunc);
    }
}

From source file:org.kuali.coeus.common.impl.print.watermark.WatermarkServiceImpl.java

/**
 * This method is for setting the properties of watermark Text.
 *//*www .jav  a  2 s .  c o m*/
private void decoratePdfWatermarkText(PdfContentByte pdfContentByte, Rectangle rectangle,
        WatermarkBean watermarkBean) {
    float x, y, x1, y1, angle;
    final float OPACITY = 0.3f;
    PdfGState pdfGState = new PdfGState();
    pdfGState.setFillOpacity(OPACITY);
    int pageWidth = (int) rectangle.getWidth();
    int pageHeight = (int) rectangle.getHeight();
    try {
        if (watermarkBean.getType().equalsIgnoreCase(WatermarkConstants.WATERMARK_TYPE_TEXT)) {
            pdfContentByte.beginText();
            pdfContentByte.setGState(pdfGState);
            Color fillColor = watermarkBean.getFont().getColor() == null
                    ? WatermarkConstants.DEFAULT_WATERMARK_COLOR
                    : watermarkBean.getFont().getColor();
            pdfContentByte.setColorFill(fillColor);

            if (watermarkBean.getPosition().equals(WatermarkConstants.WATERMARK_POSITION_FOOTER)) {

                pdfContentByte.setFontAndSize(watermarkBean.getFont().getBaseFont(),
                        watermarkBean.getPositionFont().getSize());
                if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_CENTER)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_CENTER, watermarkBean.getText(),
                            (rectangle.getLeft(rectangle.getBorderWidthLeft())
                                    + rectangle.getRight(rectangle.getBorderWidthRight())) / 2,
                            rectangle.getBottom(rectangle.getBorderWidthBottom()
                                    + watermarkBean.getPositionFont().getSize()),
                            0);
                } else if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_RIGHT)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_RIGHT, watermarkBean.getText(),
                            rectangle.getRight(rectangle.getBorderWidthRight()),
                            rectangle.getBottom(rectangle.getBorderWidthBottom()
                                    + watermarkBean.getPositionFont().getSize()),
                            0);
                } else if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_LEFT)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_LEFT, watermarkBean.getText(),
                            rectangle.getLeft(rectangle.getBorderWidthLeft()),
                            rectangle.getBottom(rectangle.getBorderWidthBottom()
                                    + watermarkBean.getPositionFont().getSize()),
                            0);
                }
            } else if (watermarkBean.getPosition().equals(WatermarkConstants.WATERMARK_POSITION_HEADER)) {
                pdfContentByte.setFontAndSize(watermarkBean.getFont().getBaseFont(),
                        watermarkBean.getPositionFont().getSize());
                if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_CENTER)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_CENTER, watermarkBean.getText(),
                            (rectangle.getLeft(rectangle.getBorderWidthLeft())
                                    + rectangle.getRight(rectangle.getBorderWidthRight())) / 2,
                            rectangle.getTop(
                                    rectangle.getBorderWidthTop() + watermarkBean.getPositionFont().getSize()),
                            0);
                } else if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_RIGHT)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_RIGHT, watermarkBean.getText(),
                            rectangle.getRight(rectangle.getBorderWidthRight()),
                            rectangle.getTop(
                                    rectangle.getBorderWidthTop() + watermarkBean.getPositionFont().getSize()),
                            0);
                } else if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_LEFT)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_LEFT, watermarkBean.getText(),
                            rectangle.getLeft(rectangle.getBorderWidthLeft()),
                            rectangle.getTop(
                                    rectangle.getBorderWidthTop() + watermarkBean.getPositionFont().getSize()),
                            0);
                }
            } else {
                pdfContentByte.setFontAndSize(watermarkBean.getFont().getBaseFont(),
                        watermarkBean.getFont().getSize());
                int textWidth = (int) pdfContentByte.getEffectiveStringWidth(watermarkBean.getText(), false);
                int diagonal = (int) Math.sqrt((pageWidth * pageWidth) + (pageHeight * pageHeight));
                int pivotPoint = (diagonal - textWidth) / 2;

                angle = (float) Math.atan((float) pageHeight / pageWidth);

                x = (float) (pivotPoint * pageWidth) / diagonal;
                y = (float) (pivotPoint * pageHeight) / diagonal;

                x1 = (float) (((float) watermarkBean.getFont().getSize() / 2) * Math.sin(angle));
                y1 = (float) (((float) watermarkBean.getFont().getSize() / 2) * Math.cos(angle));

                pdfContentByte.showTextAligned(Element.ALIGN_LEFT, watermarkBean.getText(), x + x1, y - y1,
                        (float) Math.toDegrees(angle));
            }
            pdfContentByte.endText();
        }
    } catch (Exception exception) {
        LOG.error("Exception occured in WatermarkServiceImpl. Water mark Exception: " + exception.getMessage());
    }

}

From source file:org.vast.stt.provider.tiling.TiledMapProvider.java

protected double yToLat(double y) {
    double lat = 0;
    if (Math.abs(y) < Math.PI - (1e-4))
        //lat = 2 * Math.atan(Math.exp(y)) - Math.PI/2;
        lat = Math.PI / 2 - 2 * Math.atan(Math.exp(-y));
    else/*from   w  w  w.ja  v a  2 s. com*/
        lat = Math.signum(y) * Math.PI / 2;

    return lat;
}

From source file:com.itemanalysis.psychometrics.distribution.BivariateNormalDistribution.java

public double bivnor(double ah, double ak, double r) {
    double a2;/*from w w w  .  ja  v  a  2  s  .c  o m*/
    double ap;
    double b;
    double cn;
    double con;
    double conex;
    double ex;
    double g2;
    double gh;
    double gk;
    double gw = 0;
    double h2;
    double h4;
    int i;
    int idig = 15;
    int is = 0;
    double rr;
    double s1;
    double s2;
    double sgn;
    double sn;
    double sp;
    double sqr;
    double t;
    double twopi = 6.283185307179587;
    double w2 = 0;
    double wh = 0;
    double wk = 0;

    b = 0.0;

    gh = gauss(-ah) / 2.0;
    gk = gauss(-ak) / 2.0;

    if (r == 0.0) {
        b = 4.00 * gh * gk;
        b = r8_max(b, 0.0);
        b = r8_min(b, 1.0);
        return b;
    }

    rr = (1.0 + r) * (1.0 - r);

    if (rr < 0.0) {
        throw new IllegalStateException("BIVNOR - Fatal error!");
        //    cerr << "\n";
        //    cerr << "BIVNOR - Fatal error!\n";
        //    cerr << "  1 < |R|.\n";
        //    exit ( 0 );
    }

    if (rr == 0.0) {
        if (r < 0.0) {
            if (ah + ak < 0.0) {
                b = 2.0 * (gh + gk) - 1.0;
            }
        } else {
            if (ah - ak < 0.0) {
                b = 2.0 * gk;
            } else {
                b = 2.0 * gh;
            }
        }
        b = r8_max(b, 0.0);
        b = r8_min(b, 1.0);
        return b;
    }

    sqr = Math.sqrt(rr);

    if (idig == 15) {
        con = twopi * 1.0E-15 / 2.0;
    } else {
        con = twopi / 2.0;
        for (i = 1; i <= idig; i++) {
            con = con / 10.0;
        }
    }
    //
    //  (0,0)
    //
    if (ah == 0.0 && ak == 0.0) {
        b = 0.25 + Math.asin(r) / twopi;
        b = r8_max(b, 0.0);
        b = r8_min(b, 1.0);
        return b;
    }
    //
    //  (0,nonzero)
    //
    if (ah == 0.0 && ak != 0.0) {
        b = gk;
        wh = -ak;
        wk = (ah / ak - r) / sqr;
        gw = 2.0 * gk;
        is = 1;
    }
    //
    //  (nonzero,0)
    //
    else if (ah != 0.0 && ak == 0.0) {
        b = gh;
        wh = -ah;
        wk = (ak / ah - r) / sqr;
        gw = 2.0 * gh;
        is = -1;
    }
    //
    //  (nonzero,nonzero)
    //
    else if (ah != 0.0 && ak != 0.0) {
        b = gh + gk;
        if (ah * ak < 0.0) {
            b = b - 0.5;
        }
        wh = -ah;
        wk = (ak / ah - r) / sqr;
        gw = 2.0 * gh;
        is = -1;
    }

    for (;;) {
        sgn = -1.0;
        t = 0.0;

        if (wk != 0.0) {
            if (r8_abs(wk) == 1.0) {
                t = wk * gw * (1.0 - gw) / 2.0;
                b = b + sgn * t;
            } else {
                if (1.0 < r8_abs(wk)) {
                    sgn = -sgn;
                    wh = wh * wk;
                    g2 = gauss(wh);
                    wk = 1.0 / wk;

                    if (wk < 0.0) {
                        b = b + 0.5;
                    }
                    b = b - (gw + g2) / 2.0 + gw * g2;
                }
                h2 = wh * wh;
                a2 = wk * wk;
                h4 = h2 / 2.0;
                ex = Math.exp(-h4);
                w2 = h4 * ex;
                ap = 1.0;
                s2 = ap - ex;
                sp = ap;
                s1 = 0.0;
                sn = s1;
                conex = r8_abs(con / wk);

                for (;;) {
                    cn = ap * s2 / (sn + sp);
                    s1 = s1 + cn;

                    if (r8_abs(cn) <= conex) {
                        break;
                    }
                    sn = sp;
                    sp = sp + 1.0;
                    s2 = s2 - w2;
                    w2 = w2 * h4 / sp;
                    ap = -ap * a2;
                }
                t = (Math.atan(wk) - wk * s1) / twopi;
                b = b + sgn * t;
            }
        }
        if (0 <= is) {
            break;
        }
        if (ak == 0.0) {
            break;
        }
        wh = -ak;
        wk = (ah / ak - r) / sqr;
        gw = 2.0 * gk;
        is = 1;
    }

    b = r8_max(b, 0.0);
    b = r8_min(b, 1.0);

    return b;
}

From source file:es.emergya.geo.util.Lambert.java

/**
 * initializes from cartesian coordinates
 *
 * @param X//from www .  jav  a  2 s.c o  m
 *            1st coordinate in meters
 * @param Y
 *            2nd coordinate in meters
 * @param Z
 *            3rd coordinate in meters
 * @param ell
 *            reference ellipsoid
 */
private LatLon Geographic(double X, double Y, double Z, Ellipsoid ell) {
    double norm = Math.sqrt(X * X + Y * Y);
    double lg = 2.0 * Math.atan(Y / (X + norm));
    double lt = Math.atan(Z / (norm * (1.0 - (ell.a * ell.e2 / Math.sqrt(X * X + Y * Y + Z * Z)))));
    double delta = 1.0;
    while (delta > epsilon) {
        double s2 = Math.sin(lt);
        s2 *= s2;
        double l = Math.atan(
                (Z / norm) / (1.0 - (ell.a * ell.e2 * Math.cos(lt) / (norm * Math.sqrt(1.0 - ell.e2 * s2)))));
        delta = Math.abs(l - lt);
        lt = l;
    }
    double s2 = Math.sin(lt);
    s2 *= s2;
    // h = norm / Math.cos(lt) - ell.a / Math.sqrt(1.0 - ell.e2 * s2);
    return new LatLon(lt, lg);
}

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

public void testAtan() {
    System.gc();//w ww  . jav  a2s .  c o  m
    double x = 0;
    long time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        x += StrictMath.atan(i * F1);
    long strictTime = System.nanoTime() - time;

    System.gc();
    double y = 0;
    time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        y += FastMath.atan(i * F1);
    long fastTime = System.nanoTime() - time;

    System.gc();
    double z = 0;
    time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        z += Math.atan(i * F1);
    long mathTime = System.nanoTime() - time;

    report("atan", x + y + z, strictTime, fastTime, mathTime);
}

From source file:org.geowebcache.service.wmts.WMTSGetCapabilities.java

private void layerWGS84BoundingBox(XMLBuilder xml, TileLayer layer) throws IOException {
    GridSubset subset = layer.getGridSubsetForSRS(SRS.getEPSG4326());
    if (subset != null) {
        double[] coords = subset.getOriginalExtent().getCoords();
        xml.indentElement("ows:WGS84BoundingBox");
        xml.simpleElement("ows:LowerCorner", coords[0] + " " + coords[1], true);
        xml.simpleElement("ows:UpperCorner", coords[2] + " " + coords[3], true);
        xml.endElement("ows:WGS84BoundingBox");
        return;/*from ww w .  j a  v  a2 s  .  c o m*/
    }
    subset = layer.getGridSubsetForSRS(SRS.getEPSG900913());
    if (subset != null) {
        double[] coords = subset.getOriginalExtent().getCoords();
        double originShift = 2 * Math.PI * 6378137 / 2.0;
        double mx = coords[0];
        double my = coords[1];
        double lon = (mx / originShift) * 180.0;
        double lat = (my / originShift) * 180.0;

        lat = 180 / Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180.0)) - Math.PI / 2.0);
        xml.indentElement("ows:WGS84BoundingBox");
        xml.simpleElement("ows:LowerCorner", lon + " " + lat, true);

        mx = coords[2];
        my = coords[3];
        lon = (mx / originShift) * 180.0;
        lat = (my / originShift) * 180.0;

        lat = 180 / Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180.0)) - Math.PI / 2.0);

        xml.simpleElement("ows:UpperCorner", lon + " " + lat, true);
        xml.endElement("ows:WGS84BoundingBox");
        return;
    }
}

From source file:com.ibm.bi.dml.runtime.functionobjects.Builtin.java

public double execute(double in) throws DMLRuntimeException {
    switch (bFunc) {
    case SIN://from  ww w .  j  a v  a2  s  . c om
        return FASTMATH ? FastMath.sin(in) : Math.sin(in);
    case COS:
        return FASTMATH ? FastMath.cos(in) : Math.cos(in);
    case TAN:
        return FASTMATH ? FastMath.tan(in) : Math.tan(in);
    case ASIN:
        return FASTMATH ? FastMath.asin(in) : Math.asin(in);
    case ACOS:
        return FASTMATH ? FastMath.acos(in) : Math.acos(in);
    case ATAN:
        return Math.atan(in); //faster in Math
    case CEIL:
        return FASTMATH ? FastMath.ceil(in) : Math.ceil(in);
    case FLOOR:
        return FASTMATH ? FastMath.floor(in) : Math.floor(in);
    case LOG:
        //if ( in <= 0 )
        //   throw new DMLRuntimeException("Builtin.execute(): logarithm can only be computed for non-negative numbers (input = " + in + ").");
        // for negative numbers, Math.log will return NaN
        return FASTMATH ? FastMath.log(in) : Math.log(in);
    case LOG_NZ:
        return (in == 0) ? 0 : FASTMATH ? FastMath.log(in) : Math.log(in);

    case ABS:
        return Math.abs(in); //no need for FastMath

    case SQRT:
        //if ( in < 0 )
        //   throw new DMLRuntimeException("Builtin.execute(): squareroot can only be computed for non-negative numbers (input = " + in + ").");
        return Math.sqrt(in); //faster in Math

    case PLOGP:
        if (in == 0.0)
            return 0.0;
        else if (in < 0)
            return Double.NaN;
        else
            return (in * (FASTMATH ? FastMath.log(in) : Math.log(in)));

    case EXP:
        return FASTMATH ? FastMath.exp(in) : Math.exp(in);

    case ROUND:
        return Math.round(in); //no need for FastMath

    case SPROP:
        //sample proportion: P*(1-P)
        return in * (1 - in);

    case SIGMOID:
        //sigmoid: 1/(1+exp(-x))
        return FASTMATH ? 1 / (1 + FastMath.exp(-in)) : 1 / (1 + Math.exp(-in));

    case SELP:
        //select positive: x*(x>0)
        return (in > 0) ? in : 0;

    default:
        throw new DMLRuntimeException("Builtin.execute(): Unknown operation: " + bFunc);
    }
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.tree.NumberArithmetic.java

/**
 * Returns the arc tangent of the number.
 * // w w w  .  java  2s.  co  m
 * @param a the number
 * @return the arc tangent of the number
 * @see Math#atan(double)
 */
public static Number atan(Number a) {
    return Math.atan(a.doubleValue());
}

From source file:org.kuali.coeus.common.impl.print.watermark.WatermarkServiceImpl.java

/**
 * This method is for setting the properties of watermark Image.
 * /*w  w w. jav  a 2  s . c  o  m*/
 * @param pdfContentByte
 * @param pageWidth
 * @param pageHeight
 * @param watermarkBean
 */
private void decoratePdfWatermarkImage(PdfContentByte pdfContentByte, int pageWidth, int pageHeight,
        WatermarkBean watermarkBean) {
    PdfGState pdfGState = new PdfGState();
    final float OPACITY = 0.3f;
    float absPosX;
    float absPosY;
    try {
        if (watermarkBean.getType().equalsIgnoreCase(WatermarkConstants.WATERMARK_TYPE_IMAGE)) {
            Image watermarkImage = Image.getInstance(watermarkBean.getFileImage());
            if (watermarkImage != null) {
                pdfGState.setFillOpacity(OPACITY);
                pdfContentByte.setGState(pdfGState);
                float height = watermarkImage.getPlainHeight();
                float width = watermarkImage.getPlainWidth();
                int diagonal = (int) Math.sqrt((pageWidth * pageWidth) + (pageHeight * pageHeight));
                int pivotPoint = (diagonal - (int) width) / 2;
                float angle = (float) Math.atan((float) pageHeight / pageWidth);
                absPosX = (float) (pivotPoint * pageWidth) / diagonal;
                absPosY = (float) (pivotPoint * pageHeight) / diagonal;
                watermarkImage.setAbsolutePosition(absPosX, absPosY);
                if ((pageWidth / 2) < width) {
                    watermarkImage.scaleToFit(pageWidth / 2, pageHeight / 2);
                } else {
                    watermarkImage.scaleToFit(width, height);
                }
                pdfContentByte.addImage(watermarkImage);
            }

        }

    } catch (BadElementException badElementException) {

        LOG.error("WatermarkDecoratorImpl  Error found: " + badElementException.getMessage());
    } catch (DocumentException documentException) {

        LOG.error("WatermarkDecoratorImpl Error found: " + documentException.getMessage());
    }

}