Example usage for org.apache.commons.math3.util FastMath atan2

List of usage examples for org.apache.commons.math3.util FastMath atan2

Introduction

In this page you can find the example usage for org.apache.commons.math3.util FastMath atan2.

Prototype

public static double atan2(double y, double x) 

Source Link

Document

Two arguments arctangent function

Usage

From source file:gentracklets.conversions.java

public static double[] geo2radec(PVCoordinates obj, TopocentricFrame staF, Frame inertialFrame,
        AbsoluteDate epoch) {//from  w  w  w  . ja v  a  2  s  .  c  o m

    Vector3D rho = new Vector3D(0, 0, 0);

    try {
        rho = obj.getPosition().subtract(staF.getPVCoordinates(epoch, inertialFrame).getPosition());
    } catch (OrekitException ex) {
        Logger.getLogger(conversions.class.getName()).log(Level.SEVERE, null, ex);
    }

    double rho_mag = rho.getNorm();
    double DEC = FastMath.asin(rho.getZ() / rho_mag);
    double cosRA = 0.0;
    double sinRA = 0.0;
    double RA = 0.0;

    Vector3D v_site = new Vector3D(0, 0, 0);
    try {
        v_site = staF.getPVCoordinates(epoch, inertialFrame).getVelocity();
    } catch (OrekitException ex) {
        Logger.getLogger(conversions.class.getName()).log(Level.SEVERE, null, ex);
    }

    Vector3D rhoDot = obj.getVelocity().subtract(v_site);

    if (FastMath.sqrt(FastMath.pow(rho.getX(), 2) + FastMath.pow(rho.getY(), 2)) != 0) {
        cosRA = rho.getX() / FastMath.sqrt(FastMath.pow(rho.getX(), 2) + FastMath.pow(rho.getY(), 2));
        sinRA = rho.getY() / FastMath.sqrt(FastMath.pow(rho.getX(), 2) + FastMath.pow(rho.getY(), 2));
        RA = FastMath.atan2(sinRA, cosRA);
        if (RA <= 0) {
            RA = RA + 2 * FastMath.PI;
        }
    } else {
        sinRA = rhoDot.getY() / FastMath.sqrt(FastMath.pow(rhoDot.getX(), 2) + FastMath.pow(rhoDot.getY(), 2));
        cosRA = rhoDot.getX() / FastMath.sqrt(FastMath.pow(rhoDot.getX(), 2) + FastMath.pow(rhoDot.getY(), 2));
        RA = FastMath.atan2(sinRA, cosRA);
        if (RA <= 0) {
            RA = RA + 2 * FastMath.PI;
        }
    }

    double rhoDot_mag = rho.dotProduct(rhoDot) / rho_mag;
    double RAdot = (rhoDot.getX() * rho.getY() - rhoDot.getY() * rho.getX())
            / (-1 * FastMath.pow(rho.getY(), 2) - FastMath.pow(rho.getX(), 2));
    double DECdot = (rhoDot.getZ() - rhoDot_mag * FastMath.sin(DEC))
            / FastMath.sqrt(FastMath.pow(rho.getX(), 2) + FastMath.pow(rho.getY(), 2));

    double[] out = { RA, RAdot, DEC, DECdot, rho_mag, rhoDot_mag };

    return out;
}

From source file:com.tussle.main.Utility.java

public static double angle(double x, double y) {
    return FastMath.toDegrees(FastMath.atan2(y, x));
}

From source file:com.tussle.collision.CollisionCorner.java

public void draw(ShapeRenderer drawer) {
    double minAngle = FastMath.toDegrees(FastMath.atan2(minVec.yNorm(), minVec.xNorm()));
    double maxAngle = FastMath.toDegrees(FastMath.atan2(maxVec.yNorm(), maxVec.xNorm()));
    drawer.arc((float) x, (float) y, 12, (float) minAngle, (float) (maxAngle - minAngle));
    drawer.line((float) x, (float) y, (float) (x + minVec.xNorm() * 20), (float) (y + minVec.yNorm() * 20));
    drawer.line((float) x, (float) y, (float) (x + maxVec.xNorm() * 20), (float) (y + maxVec.yNorm() * 20));
}

From source file:com.jhlabs.awt.TextStroke.java

public Shape createStrokedShape(Shape shape) {
    FontRenderContext frc = new FontRenderContext(null, true, true);
    GlyphVector glyphVector = font.createGlyphVector(frc, text);

    GeneralPath result = new GeneralPath();
    PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS);
    float points[] = new float[6];
    float moveX = 0, moveY = 0;
    float lastX = 0, lastY = 0;
    float thisX = 0, thisY = 0;
    int type = 0;
    float next = 0;
    int currentChar = 0;
    int length = glyphVector.getNumGlyphs();

    if (length == 0)
        return result;

    float factor = stretchToFit ? measurePathLength(shape) / (float) glyphVector.getLogicalBounds().getWidth()
            : 1.0f;//  w  ww  .  j a  v a  2 s .c om
    float height = (float) glyphVector.getLogicalBounds().getHeight();
    float nextAdvance = 0;

    while (currentChar < length && !it.isDone()) {
        type = it.currentSegment(points);
        switch (type) {
        case PathIterator.SEG_MOVETO:
            moveX = lastX = points[0];
            moveY = lastY = points[1];
            result.moveTo(moveX, moveY);
            nextAdvance = glyphVector.getGlyphMetrics(currentChar).getAdvance() * 0.5f;
            next = nextAdvance;
            break;

        case PathIterator.SEG_CLOSE:
            points[0] = moveX;
            points[1] = moveY;
            // Fall into....

        case PathIterator.SEG_LINETO:
            thisX = points[0];
            thisY = points[1];
            float dx = thisX - lastX;
            float dy = thisY - lastY;
            float distance = (float) FastMath.sqrt(dx * dx + dy * dy);
            if (distance >= next) {
                float r = 1.0f / distance;
                float angle = (float) FastMath.atan2(dy, dx);
                while (currentChar < length && distance >= next) {
                    Shape glyph = glyphVector.getGlyphOutline(currentChar);
                    Point2D p = glyphVector.getGlyphPosition(currentChar);
                    float px = (float) p.getX();
                    float py = (float) p.getY();
                    float x = lastX + next * dx * r;
                    float y = lastY + next * dy * r;
                    float advance = nextAdvance;
                    nextAdvance = currentChar < length - 1
                            ? glyphVector.getGlyphMetrics(currentChar + 1).getAdvance() * 0.5f
                            : 0;
                    t.setToTranslation(x, y);
                    t.rotate(angle);
                    t.translate(-px - advance, -py + height * factor / 2.0f);
                    result.append(t.createTransformedShape(glyph), false);
                    next += (advance + nextAdvance) * factor;
                    currentChar++;
                    if (repeat)
                        currentChar %= length;
                }
            }
            next -= distance;
            lastX = thisX;
            lastY = thisY;
            break;
        }
        it.next();
    }

    return result;
}

From source file:cc.redberry.core.number.Complex.java

/**
 * Returns natural logarithm of this/*  ww w  . j  a  v a  2s .c o m*/
 *
 * @return natural logarithm of this
 */
public Complex logNumeric() {
    if (isNaN()) {
        return ComplexNaN;
    }

    final double real = this.real.doubleValue();
    final double imaginary = this.imaginary.doubleValue();

    return new Complex(FastMath.log(absNumeric(real, imaginary)), FastMath.atan2(imaginary, real));
}

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

public void testAtan2() {
    System.gc();//from   w ww  .j  a  va 2s . c om
    double x = 0;
    long time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        x += StrictMath.atan2(i * F1, i * F1);
    long strictTime = System.nanoTime() - time;

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

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

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

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

@Test
public void testMathATan2Fast() {
    for (double i = 0; i < numItr; ++i) {
        double val = FastMath.atan2(i, i);
    }/*from   ww  w  .ja  v  a2s .c  o  m*/
}

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

/**
 *
 * @param direction//ww  w . jav  a2 s.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:org.jlab.clas.swimtools.Swim.java

/**
 * Sets the parameters used by swimmer based on the input track state vector
 * parameters swimming outwards/* w  w w  . j  a v  a  2 s.  c  o m*/
 *
 * @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.jlab.clas.swimtools.Swim.java

/**
 * Sets the parameters used by swimmer based on the input track parameters
 *
 * @param x0//from   w w w  . ja v  a 2 s  .  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;

}