Example usage for java.lang Math asin

List of usage examples for java.lang Math asin

Introduction

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

Prototype

public static double asin(double a) 

Source Link

Document

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

Usage

From source file:nz.co.fortytwo.signalk.util.Util.java

public static double haversineMeters(double lat, double lon, double anchorLat, double anchorLon) {
    double dLat = Math.toRadians(anchorLat - lat);
    double dLon = Math.toRadians(anchorLon - lon);
    lat = Math.toRadians(lat);/*from  w  ww  . ja  va  2 s  .  c o  m*/
    anchorLat = Math.toRadians(anchorLat);

    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
            + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat) * Math.cos(anchorLat);
    double c = 2 * Math.asin(Math.sqrt(a));
    return R * c;
}

From source file:msi.gaml.operators.Maths.java

@operator(value = "asin", can_be_const = true, category = { IOperatorCategory.ARITHMETIC })
@doc(value = "the arcsin of the operand", masterDoc = true, examples = @example(value = "asin (90)", equals = "#nan"), see = {
        "acos", "atan" })
public static Double asin(final Integer rv) {
    return Math.asin(rv) * toDeg;
}

From source file:msi.gama.common.geometry.Rotation3D.java

/**
 * Get the angle of the rotation in radians
 * /*  ww  w.  java2s.  c  o  m*/
 * @return angle of the rotation (between 0 and π)
 * @see #Rotation(GamaPoint, double)
 */
public double getAngle() {
    if (q0 < -0.1 || q0 > 0.1) {
        return 2 * Math.asin(Math.sqrt(q1 * q1 + q2 * q2 + q3 * q3));
    } else if (q0 < 0) {
        return 2 * Math.acos(-q0);
    }
    return 2 * Math.acos(q0);
}

From source file:org.opensha.commons.geo.LocationUtils.java

/**
 * Computes the shortest distance between a point and a line segment (i.e.
 * great-circle segment). Both the line and point are assumed to be at the
 * earth's surface; the depth component of each <code>Location</code> is
 * ignored. This method uses the true spherical geometric function for
 * 'off-track distance'; See <a/*  w  w w. ja va2  s .co  m*/
 * href="http://williams.best.vwh.net/avform.htm#XTE"> Aviation
 * Formulary</a> for source. This method always returns a positive result.<br/>
 * <br/>
 * This method, though more accurate over longer distances and line lengths,
 * is up to 20x slower than
 * {@link #distanceToLineSegmentFast(Location, Location, Location)}. However,
 * this method returns accurate results for values spanning #177;180&#176;. <br/>
 * <br/>
 * If the line should instead be treated as infinite, use
 * {@link #distanceToLine(Location, Location, Location)} instead.
 * 
 * @param p1 the first <code>Location</code> point on the line
 * @param p2 the second <code>Location</code> point on the line
 * @param p3 the <code>Location</code> point for which distance will be
 *        calculated
 * @return the shortest distance in km between the supplied point and line
 * @see #distanceToLineFast(Location, Location, Location)
 * @see #distanceToLine(Location, Location, Location)
 */
public static double distanceToLineSegment(Location p1, Location p2, Location p3) {

    // repeat calcs in distanceToLine() to cut down on replication of
    // expensive trig ops that would result from calling distanceToLine()

    // angular distance
    double ad13 = angle(p1, p3);
    // delta azimuth p1 to p3 and azimuth p1 to p2
    double Daz13az12 = azimuthRad(p1, p3) - azimuthRad(p1, p2);
    // cross-track distance (in radians)
    double xtd = Math.asin(Math.sin(ad13) * Math.sin(Daz13az12));
    // along-track distance (in km)
    double atd = Math.acos(Math.cos(ad13) / Math.cos(xtd)) * EARTH_RADIUS_MEAN;
    // check if beyond p3
    if (atd > horzDistance(p1, p2))
        return horzDistance(p2, p3);
    // check if before p1
    if (Math.cos(Daz13az12) < 0)
        return horzDistance(p1, p3);
    return (Math.abs(xtd) < TOLERANCE) ? 0.0 : Math.abs(xtd) * EARTH_RADIUS_MEAN;
}

From source file:org.dawnsci.plotting.tools.powdercheck.PowderCheckJob.java

public void updateCalibrantLines() {

    List<HKL> spacings = CalibrationFactory.getCalibrationStandards().getCalibrant().getHKLs();
    final double[] qVals = new double[spacings.size()];

    for (int i = 0; i < spacings.size(); i++) {

        if (xAxis == XAxis.ANGLE)
            qVals[i] = 2 * Math.toDegrees(Math.asin((metadata.getDiffractionCrystalEnvironment().getWavelength()
                    / (2 * spacings.get(i).getDNano() * 10))));
        else//from  ww w.j  a  v  a 2  s  .c om
            qVals[i] = (Math.PI * 2) / (spacings.get(i).getDNano() * 10);
    }

    Display.getDefault().syncExec(new Runnable() {

        @Override
        public void run() {

            if (system.getPlotComposite() == null)
                return;

            IAxis ax = system.getSelectedXAxis();

            double low = ax.getLower();
            double up = ax.getUpper();

            for (IRegion r : system.getRegions())
                system.removeRegion(r);
            for (int i = 0; i < qVals.length; i++) {
                if (qVals[i] < low || qVals[i] > up)
                    continue;

                try {
                    RectangularROI roi = new RectangularROI(qVals[i], 0, 1, 1, 0);
                    IRegion reg = system.getRegion("Q value: " + qVals[i]);
                    if (reg != null)
                        system.removeRegion(reg);

                    final IRegion area = system.createRegion("Q value: " + qVals[i], RegionType.XAXIS_LINE);
                    area.setROI(roi);
                    area.setRegionColor(ColorConstants.gray);
                    area.setUserRegion(false);
                    system.addRegion(area);
                    area.setMobile(false);
                } catch (Exception e) {
                    logger.error("Region is already there", e);
                }

            }
        }
    });
}

From source file:com.thalmic.android.sample.helloworld.HelloWorldActivity.java

public void calculateAngles(float[] result, float[] rVector, float[] accVector, float[] magVector) {
    //caculate temp rotation matrix from rotation vector first
    SensorManager.getRotationMatrix(rMatrix, null, accVector, magVector);
    SensorManager.getQuaternionFromVector(quaternion, rVector);

    roll = Math.atan2(2.0f * (quaternion[0] * quaternion[1] + quaternion[2] * quaternion[3]),
            1.0f - 2.0f * (quaternion[1] * quaternion[1] + quaternion[2] * quaternion[2]));
    pitch = Math.asin(2.0f * (quaternion[0] * quaternion[2] - quaternion[3] * quaternion[1]));
    yaw = Math.atan2(2.0f * (quaternion[0] * quaternion[3] + quaternion[1] * quaternion[2]),
            1.0f - 2.0f * (quaternion[2] * quaternion[2] + quaternion[3] * quaternion[3]));

    rollW = ((roll + Math.PI) / (Math.PI * 2.0) * SCALE);
    pitchW = ((pitch + Math.PI / 2.0) / Math.PI * SCALE);
    yawW = ((yaw + Math.PI) / (Math.PI * 2.0) * SCALE);

    //calculate Euler angles now
    SensorManager.getOrientation(rMatrix, result);

    //Now we can convert it to degrees
    convertToDegrees(result);/*from w  ww.  j av  a 2 s .co m*/
}

From source file:com.example.appf.CS3570.java

public void computerEuler() {

    //Quaternion describing orientation of sensor relative to earth.
    double ESq_1, ESq_2, ESq_3, ESq_4;
    //Quaternion describing orientation of sensor relative to auxiliary frame.
    double ASq_1, ASq_2, ASq_3, ASq_4;

    //Compute the quaternion conjugate.
    ESq_1 = SEq_1;/* w w w  .  j a va 2s  .c  o m*/
    ESq_2 = -SEq_2;
    ESq_3 = -SEq_3;
    ESq_4 = -SEq_4;

    //Compute the quaternion product.
    ASq_1 = ESq_1 * AEq_1 - ESq_2 * AEq_2 - ESq_3 * AEq_3 - ESq_4 * AEq_4;
    ASq_2 = ESq_1 * AEq_2 + ESq_2 * AEq_1 + ESq_3 * AEq_4 - ESq_4 * AEq_3;
    ASq_3 = ESq_1 * AEq_3 - ESq_2 * AEq_4 + ESq_3 * AEq_1 + ESq_4 * AEq_2;
    ASq_4 = ESq_1 * AEq_4 + ESq_2 * AEq_3 - ESq_3 * AEq_2 + ESq_4 * AEq_1;

    //Compute the Euler angles from the quaternion.
    phi = Math.atan2(2 * ASq_3 * ASq_4 - 2 * ASq_1 * ASq_2, 2 * ASq_1 * ASq_1 + 2 * ASq_4 * ASq_4 - 1);
    theta = Math.asin(2 * ASq_2 * ASq_3 - 2 * ASq_1 * ASq_3);
    psi = Math.atan2(2 * ASq_2 * ASq_3 - 2 * ASq_1 * ASq_4, 2 * ASq_1 * ASq_1 + 2 * ASq_2 * ASq_2 - 1);
}

From source file:ffx.algorithms.AbstractOSRW.java

public void setLambda(double lambda) {
    lambdaInterface.setLambda(lambda);
    this.lambda = lambda;
    theta = Math.asin(Math.sqrt(lambda));
}

From source file:com.ssn.currency.convertor.WheelView.java

/**
 * Calculates range for wheel items//from   ww  w.j a v a  2s. c  om
 * @return the items range
 */
private ItemsRange getItemsRange() {
    if (getItemHeight() == 0) {
        return null;
    }

    int first = currentItem;
    int count = 1;

    while (count * getItemHeight() < getHeight()) {
        first--;
        count += 2; // top + bottom items
    }

    if (scrollingOffset != 0) {
        if (scrollingOffset > 0) {
            first--;
        }
        count++;

        // process empty items above the first or below the second
        int emptyItems = scrollingOffset / getItemHeight();
        first -= emptyItems;
        count += Math.asin(emptyItems);
    }
    return new ItemsRange(first, count);
}

From source file:com.zl.bgec.basicapi.shop.service.impl.ShopServiceImpl.java

private double get_distance(double $lat1, double $lng1, double $lat2, double $lng2) {
    int $len_type = 1, $decimal = 2;
    double $PI = 3.1415926;
    double $EARTH_RADIUS = 6378.137;

    double $radLat1 = $lat1 * $PI / 180.0;
    double $radLat2 = $lat2 * $PI / 180.0;

    double $a = $radLat1 - $radLat2;
    double $b = ($lng1 * $PI / 180.0) - ($lng2 * $PI / 180.0);

    double $s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin($a / 2), 2)
            + Math.cos($radLat1) * Math.cos($radLat2) * Math.pow(Math.sin($b / 2), 2)));

    $s = $s * $EARTH_RADIUS;/*  w  w w. ja  va2s.  c o  m*/
    $s = Math.round($s * 1000);

    if ($len_type > 1) {
        $s /= 1000;
    }

    return Math.round($s);
}