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:org.marinemc.util.Location.java

/**
 * Face the yaw towards the specified location
 *
 * @param p//from  www. 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;
}

From source file:fr.amap.lidar.amapvox.commons.LeafAngleDistribution.java

/**
 * Get the density probability from angle
 * @param angle must be in radians from in [0,2pi]
 * @return pdf function//w  w  w  .jav a 2s.  co m
 */
public double getDensityProbability(double angle) {

    double density = 0;

    double tmp = Math.PI / 2.0;
    if (angle == tmp) {
        angle = tmp - 0.000001;
    }

    //angle = Math.PI/2.0 - angle; ??inversion des coefficients

    switch (type) {

    //warning : in wang paper there is an inversion between planophile, and erectophile
    case PLANOPHILE:
        density = (2.0 / Math.PI) * (1 + Math.cos(2 * angle));
        break;
    case ERECTOPHILE:
        density = (2.0 / Math.PI) * (1 - Math.cos(2 * angle));
        break;
    case PLAGIOPHILE:
        density = (2.0 / Math.PI) * (1 - Math.cos(4 * angle));
        break;
    case EXTREMOPHILE:
        density = (2.0 / Math.PI) * (1 + Math.cos(4 * angle));
        break;
    case SPHERIC:
        density = Math.sin(angle);
        break;
    case UNIFORM:
        density = 2.0 / Math.PI;
        break;
    case HORIZONTAL:
        break;
    case VERTICAL:
        break;
    case ELLIPTICAL:
        break;
    case ELLIPSOIDAL:

        double res;

        if (x == 1) {
            res = Math.sin(angle);
        } else {

            double eps, lambda = 0;

            if (x < 1) {
                eps = Math.sqrt(1 - (x * x));
                lambda = x + (Math.asin(eps) / eps);
            }
            if (x > 1) {
                eps = Math.sqrt(1 - Math.pow(x, -2));
                lambda = x + Math.log((1 + eps) / (1 + eps)) / (2 * eps * x);
            }

            res = (2 * Math.pow(x, 3) * Math.sin(angle)) / (lambda
                    * Math.pow((Math.pow(Math.cos(angle), 2)) + (x * x * Math.pow(Math.sin(angle), 2)), 2));
        }

        return res;

    case TWO_PARAMETER_BETA:

        //angle = Math.PI/2.0 - angle;
        double te = 2 * angle / Math.PI;
        te = Double.max(te, 1E-09);
        te = Double.min(te, 1 - 1E-09);

        density = distribution.density(te) / (Math.PI / 2.0);

        break;
    }

    return density;
}

From source file:edu.umd.cfar.lamp.viper.geometry.Circle.java

/**
 * Approximates the shared area of two circles.
 * @param other the circle to intersect with
 * @return the area of the region overlapped by both circles
 *///from  www .  j a v a2s.co  m
public double intersectArea(Circle other) {
    double centerDistance = center.minus(other.center).length();
    if (centerDistance >= (radius + other.radius))
        return 0;

    // Check for inscription
    if ((centerDistance + other.radius) <= radius)
        return other.area();
    if ((centerDistance + radius) <= other.radius)
        return area();

    // for simplicity
    double cDsq = centerDistance * centerDistance;
    double r1sq = radius * radius;
    double r2sq = other.radius * other.radius;

    // for formula, see http://www.oswego.edu/~baloglou/circles.html
    return Math.PI * ((r1sq + r2sq) / 2)
            + r2sq * Math.asin((r1sq - r2sq - cDsq) / (2 * centerDistance * other.radius))
            - r1sq * Math.asin((r1sq - r2sq + cDsq) / (2 * centerDistance * radius)) - .5 * Math.sqrt(
                    2 * (r1sq * r2sq + cDsq * r1sq + cDsq * r2sq) - r1sq * r1sq - r2sq * r2sq - cDsq * cDsq);
}

From source file:com.alvermont.terraj.planet.project.ConicalProjection.java

/**
 * Carry out the projection/*from   w  w  w  . j  ava2  s  .  c o m*/
 */
public void project() {
    setcolours();

    final int width = getParameters().getProjectionParameters().getWidth();
    final int height = getParameters().getProjectionParameters().getHeight();

    final double lat = getParameters().getProjectionParameters().getLatitudeRadians();
    final double lon = getParameters().getProjectionParameters().getLongitudeRadians();

    final double scale = getParameters().getProjectionParameters().getScale();

    final double hgrid = getParameters().getProjectionParameters().getHgrid();
    final double vgrid = getParameters().getProjectionParameters().getVgrid();

    final boolean doShade = getParameters().getProjectionParameters().isDoShade();

    cacheParameters();

    colours = new short[width][height];
    shades = new short[width][height];

    final double sla = Math.sin(lat);
    final double cla = Math.cos(lat);
    final double slo = Math.sin(lon);
    final double clo = Math.cos(lon);

    depth = (3 * ((int) (log2(scale * height)))) + 6;

    double k1;
    double c;
    double y2;
    double x;
    double y;
    double zz;
    double x1;
    double y1;
    double z1;
    double theta1;
    double theta2;
    double ymin;
    double ymax;
    double cos2;
    int i;
    int j;

    ymin = 2.0;
    ymax = -2.0;

    if (lat > 0) {
        k1 = 1.0 / Math.sin(lat);
        c = k1 * k1;

        y2 = Math.sqrt((c * (1.0 - Math.sin(lat / k1))) / (1.0 + Math.sin(lat / k1)));

        progress.progressStart(height, "Generating Terrain");

        for (j = 0; j < height; ++j) {
            progress.progressStep(j);

            for (i = 0; i < width; ++i) {
                x = ((2.0 * i) - width) / height / scale;
                y = (((2.0 * j) - height) / height / scale) + y2;
                zz = (x * x) + (y * y);

                if (zz == 0.0) {
                    theta1 = 0.0;
                } else {
                    theta1 = k1 * Math.atan2(x, y);
                }

                if ((theta1 < -Math.PI) || (theta1 > Math.PI)) {
                    colours[i][j] = backgroundColour;

                    if (doShade) {
                        shades[i][j] = 255;
                    }
                } else {
                    /* theta1 is longitude */
                    theta1 += (lon - (0.5 * Math.PI));
                    theta2 = k1 * Math.asin((zz - c) / (zz + c));

                    /* theta2 is latitude */
                    if ((theta2 > (0.5 * Math.PI)) || (theta2 < (-0.5 * Math.PI))) {
                        colours[i][j] = backgroundColour;

                        if (doShade) {
                            shades[i][j] = 255;
                        }
                    } else {
                        cos2 = Math.cos(theta2);
                        y = Math.sin(theta2);

                        if (y < ymin) {
                            ymin = y;
                        }

                        if (y > ymax) {
                            ymax = y;
                        }

                        colours[i][j] = (short) planet0(Math.cos(theta1) * cos2, y, -Math.sin(theta1) * cos2);

                        if (doShade) {
                            shades[i][j] = shade;
                        }
                    }
                }
            }
        }

        progress.progressComplete("Terrain Generated");

        if (hgrid != 0.0) {
            /* draw horizontal gridlines */
            for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid)
                ;

            for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) {
                y = Math.sin(Math.toRadians(theta1));

                if ((ymin <= y) && (y <= ymax)) {
                    zz = Math.sqrt((c * (1.0 + Math.sin(Math.toRadians(theta1) / k1)))
                            / (1.0 - Math.sin(Math.toRadians(theta1) / k1)));

                    for (theta2 = -Math.PI + lon; theta2 < (Math.PI + lon); theta2 += (0.5 / width / scale)) {
                        z1 = theta2 - lon;
                        x1 = zz * Math.sin(z1 / k1);
                        y1 = zz * Math.cos(z1 / k1);

                        i = (int) (0.5 * ((height * scale * x1) + width));
                        j = (int) (0.5 * ((height * scale * (y1 - y2)) + height));

                        if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) {
                            colours[i][j] = BLACK;
                        }
                    }
                }
            }
        }

        if (vgrid != 0.0) {
            /* draw vertical gridlines */
            for (theta1 = -0.5 * Math.PI; theta1 < (0.5 * Math.PI); theta1 += (0.5 / width / scale)) {
                y = Math.sin(theta1);

                if ((ymin <= y) && (y <= ymax)) {
                    zz = Math.sqrt((c * (1.0 + Math.sin(theta1 / k1))) / (1.0 - Math.sin(theta1 / k1)));

                    for (theta2 = 0.0; theta2 > (-180.0 + Math.toDegrees(lon)); theta2 -= vgrid)
                        ;

                    for (theta2 = theta2; theta2 < (180.0 + Math.toDegrees(lon)); theta2 += vgrid) {
                        z1 = Math.toRadians(theta2) - lon;
                        x1 = zz * Math.sin(z1 / k1);
                        y1 = zz * Math.cos(z1 / k1);

                        i = (int) (0.5 * ((height * scale * x1) + width));
                        j = (int) (0.5 * ((height * scale * (y1 - y2)) + height));

                        if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) {
                            colours[i][j] = BLACK;
                        }
                    }
                }
            }
        }
    } else {
        k1 = 1.0 / Math.sin(lat);
        c = k1 * k1;
        y2 = Math.sqrt((c * (1.0 - Math.sin(lat / k1))) / (1.0 + Math.sin(lat / k1)));

        progress.progressStart(height, "Generating Terrain");

        for (j = 0; j < height; ++j) {
            progress.progressStep(j);

            for (i = 0; i < width; ++i) {
                x = ((2.0 * i) - width) / height / scale;
                y = (((2.0 * j) - height) / height / scale) - y2;
                zz = (x * x) + (y * y);

                if (zz == 0.0) {
                    theta1 = 0.0;
                } else {
                    theta1 = -k1 * Math.atan2(x, -y);
                }

                if ((theta1 < -Math.PI) || (theta1 > Math.PI)) {
                    colours[i][j] = backgroundColour;

                    if (doShade) {
                        shades[i][j] = 255;
                    }
                } else {
                    /* theta1 is longitude */
                    theta1 += (lon - (0.5 * Math.PI));
                    theta2 = k1 * Math.asin((zz - c) / (zz + c));

                    /* theta2 is latitude */
                    if ((theta2 > (0.5 * Math.PI)) || (theta2 < (-0.5 * Math.PI))) {
                        colours[i][j] = backgroundColour;

                        if (doShade) {
                            shades[i][j] = 255;
                        }
                    } else {
                        cos2 = Math.cos(theta2);
                        y = Math.sin(theta2);

                        if (y < ymin) {
                            ymin = y;
                        }

                        if (y > ymax) {
                            ymax = y;
                        }

                        colours[i][j] = (short) planet0(Math.cos(theta1) * cos2, y, -Math.sin(theta1) * cos2);

                        if (doShade) {
                            shades[i][j] = shade;
                        }
                    }
                }
            }
        }

        progress.progressComplete("Terrain Generated");

        if (hgrid != 0.0) {
            /* draw horizontal gridlines */
            for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid)
                ;

            for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) {
                y = Math.sin(Math.toRadians(theta1));

                if ((ymin <= y) && (y <= ymax)) {
                    zz = Math.sqrt((c * (1.0 + Math.sin(Math.toRadians(theta1) / k1)))
                            / (1.0 - Math.sin(Math.toRadians(theta1) / k1)));

                    for (theta2 = -Math.PI + lon; theta2 < (Math.PI + lon); theta2 += (0.5 / width / scale)) {
                        z1 = theta2 - lon;
                        x1 = -zz * Math.sin(z1 / k1);
                        y1 = -zz * Math.cos(z1 / k1);

                        i = (int) (0.5 * ((height * scale * x1) + width));
                        j = (int) (0.5 * ((height * scale * (y1 + y2)) + height));

                        if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) {
                            colours[i][j] = BLACK;
                        }
                    }
                }
            }
        }

        if (vgrid != 0.0) {
            /* draw vertical gridlines */
            for (theta1 = -0.5 * Math.PI; theta1 < (0.5 * Math.PI); theta1 += (0.5 / width / scale)) {
                y = Math.sin(theta1);

                if ((ymin <= y) && (y <= ymax)) {
                    zz = Math.sqrt((c * (1.0 + Math.sin(theta1 / k1))) / (1.0 - Math.sin(theta1 / k1)));

                    for (theta2 = 0.0; theta2 > (-180.0 + Math.toDegrees(lon)); theta2 -= vgrid)
                        ;

                    for (theta2 = theta2; theta2 < (180.0 + Math.toDegrees(lon)); theta2 += vgrid) {
                        z1 = Math.toRadians(theta2) - lon;
                        x1 = -zz * Math.sin(z1 / k1);
                        y1 = -zz * Math.cos(z1 / k1);

                        i = (int) (0.5 * ((height * scale * x1) + width));
                        j = (int) (0.5 * ((height * scale * (y1 + y2)) + height));

                        if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) {
                            colours[i][j] = BLACK;
                        }
                    }
                }
            }
        }
    }

    if (doShade) {
        smoothshades();
    }

    doOutlining();
}

From source file:main.java.gov.wa.wsdot.candidate.evaluation.App.java

/**
 * Using the Haversine formula this method calculates the distance in miles
 * between two latitude and longitude points.
 * //from ww w  .  j  ava 2s . c om
 * Formula from: https://en.wikipedia.org/wiki/Haversine_formula
 * 
 * @param lat1  latitude of point 1 (user)
 * @param long1 longitude of point 1 (user)
 * @param lat2  latitude of point 2 (camera)
 * @param long2 longitude of point 2 (camera)
 * @return      distance in miles between two points given
 */
private double getDistance(double lat1, double long1, double lat2, double long2) {

    double deltaLong;
    double deltaLat;
    double hav2;
    double hav1;

    lat1 = Math.toRadians(lat1);
    lat2 = Math.toRadians(lat2);
    long1 = Math.toRadians(long1);
    long2 = Math.toRadians(long2);

    deltaLong = Math.toRadians(long2 - long1);
    deltaLat = Math.toRadians(lat2 - lat1);

    hav1 = (Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2));
    hav2 = (Math.sin(deltaLong / 2) * Math.sin(deltaLong / 2));

    return Math.toDegrees(2 * R * Math.asin(Math.sqrt(hav1 + Math.cos(lat1) * Math.cos(lat2) * hav2)));
}

From source file:com.google.publicalerts.cap.validator.MapVisualizer.java

/**
 * Computes the end point of an arc of a great circle given a starting point
 * and arc length.// www  . ja va 2 s .c o m
 * See http://williams.best.vwh.net/avform.htm#LL
 *
 * @param heading the direction of the arc, in radians
 * @param arcLength the length of the arc, in kilometers
 * @param latitude latitude of the starting point of the arc
 * @param longitude longitude of the starting point of the arc
 * @return the end point
 */
private JSONArray getRadialEndpoint(double heading, double arcLength, double latitude, double longitude)
        throws JSONException {
    // the angle of the great circle arc
    double earthAngle = arcLength / EARTH_RADIUS_KM;
    // convert decimal degrees to radians for the calculation
    double lat = latitude * DEG_TO_RAD;
    double lng = Math.abs(longitude) * DEG_TO_RAD;
    double asinArg = Math.sin(lat) * Math.cos(earthAngle)
            + Math.cos(lat) * Math.sin(earthAngle) * Math.cos(heading);

    double destLat = Math.asin(asinArg);
    double y = Math.sin(heading) * Math.sin(earthAngle) * Math.cos(lat);
    double x = Math.cos(earthAngle) - Math.sin(lat) * Math.sin(destLat);
    double destLng = (lng - Math.atan2(y, x) + Math.PI) % (2 * Math.PI) - Math.PI;

    return toJsPoint(destLat * RAD_TO_DEG, destLng * RAD_TO_DEG * (longitude < 0 ? -1 : 1));
}

From source file:com.tsroad.map.CalculateDistanceActivity.java

public double calculateJWD(double lng_a, double lat_a, double lng_b, double lat_b) {
    double radLat1 = (lat_a * Math.PI / 180.0);
    double radLat2 = (lat_b * Math.PI / 180.0);
    double a = radLat1 - radLat2;
    double b = (lng_a - lng_b) * Math.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  ww  .  java 2 s  .  co  m*/
    s = Math.round(s * 10000) / 10000;
    return s;
}

From source file:magma.agent.worldmodel.localizer.impl.LocalizerTriangulation.java

/**
 * Calculates absolute position and directions from the two flags passed
 * using triangulation. Absolute means with respect to the game fields
 * coordinate system.//from   w w w  .  j a v a 2s.c om
 * @param flag1 first visible landmark with known position
 * @param flag2 second visible landmark with known position (has to be right
 *        of first)
 * @param neckAngle the horizontal neck angle of the viewer
 * @return an array of two Vector3Ds, the first containing the absolute x,y,z
 *         position of the viewer on the field, the second containing no real
 *         vector, but the horizontal, latitudal and rotational absolute body
 *         angles of the viewer
 */
private PositionOrientation triangulate(ILocalizationFlag flag1, ILocalizationFlag flag2, float neckAngle) {
    float flag1Direction;
    float flag2Direction;
    double r1, r2; // the distance of the player to the flags
    double dist, dist2; // the distance (square) of the two flags
    double a; // distance from one flag to intersection
    // point P3
    double h; // distance from P3 to the intersection
    // Points P1 and P2 of the two circles
    double x, x1, x2, x3;
    double y, y1, y2, y3;
    double ratio;
    Angle horizontalAbsDirection;
    float beta;

    logger.log(Level.FINER, "Triangulation with flags 1:{0} 2:{1}", new Object[] { flag1, flag2 });

    // do the calculations
    flag1Direction = (float) flag1.getHorizontalDirection();
    flag2Direction = (float) flag2.getHorizontalDirection();

    r1 = flag1.getDistance();
    r2 = flag2.getDistance();

    x1 = flag1.getKnownPosition().getX();
    x2 = flag2.getKnownPosition().getX();

    y1 = flag1.getKnownPosition().getY();
    y2 = flag2.getKnownPosition().getY();

    // calculate the square distance of the two flags
    dist2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
    dist = Math.sqrt(dist2);
    if (dist > r1 + r2) {
        // the circles would not intersect
        dist = r1 + r2;
        dist2 = dist * dist;
    } else if ((r1 > r2) && (dist + r2 < r1)) {
        // the circles would not intersect
        dist = r1 - r2;
        dist2 = dist * dist;
    } else if ((r2 > r1) && (dist + r1 < r2)) {
        // the circles would not intersect
        dist = r2 - r1;
        dist2 = dist * dist;
    }

    r1 *= r1;
    r2 *= r2;

    // a = (r1^2 - r2^2 + d^2 ) / (2 d)
    // a = distance from flag1 to base point of height line
    a = (r1 - r2 + dist2) / (2.0 * dist);

    // h^2 = r1^2 - a^2
    // h = height of the triangle flag1, flag2 and my position
    h = r1 - a * a;
    if (h < 0.0)
        h = 0.0;
    else
        h = Math.sqrt(h);

    // calculate middle of intersection line
    // P3 = P1 + a ( P2 - P1 ) / d
    x3 = x1 + a * (x2 - x1) / dist;
    y3 = y1 + a * (y2 - y1) / dist;

    // two circles intersect usually in 2 points. Find out which one to
    // select
    if (flag1Direction > flag2Direction) {
        // result x = x3 + h ( y2 - y1 ) / d
        x = x3 + h * (y2 - y1) / dist;
        // result y = y3 - h ( x2 - x1 ) / d
        y = y3 - h * (x2 - x1) / dist;
    } else {
        x = x3 - h * (y2 - y1) / dist;
        y = y3 + h * (x2 - x1) / dist;
    }

    // TODO: add z position calculation
    Vector3D position = new Vector3D(x, y, 0);

    // calculate the absolute direction
    r1 = flag1.getDistance();
    ratio = (y1 - y) / r1;
    beta = (float) Math.asin(ratio);
    if (x > x1) {
        horizontalAbsDirection = Angle.RAD180.subtract(beta).subtract(flag1Direction);
    } else {
        horizontalAbsDirection = Angle.rad(beta).subtract(flag1Direction);
    }
    // adjust to head angle
    horizontalAbsDirection = horizontalAbsDirection.subtract(neckAngle);

    // TODO add vertical direction

    logger.log(Level.FINER, "Localize pos:({0}, {1}), angles:{2}, neck:{3}",
            new Object[] { x, y, horizontalAbsDirection, neckAngle });
    return new PositionOrientation(position, horizontalAbsDirection);
}

From source file:se.llbit.chunky.renderer.scene.Sky.java

/**
 * Calculate sky color for the ray, based on sky mode
 * @param ray/*from  ww  w  . j a  va 2 s.  c o m*/
 */
public void getSkyDiffuseColorInner(Ray ray) {
    switch (mode) {
    case GRADIENT: {
        double angle = Math.asin(ray.d.y);
        int x = 0;
        if (gradient.size() > 1) {
            double pos = (angle + Constants.HALF_PI) / Math.PI;
            Vector4d c0 = gradient.get(x);
            Vector4d c1 = gradient.get(x + 1);
            double xx = (pos - c0.w) / (c1.w - c0.w);
            while (x + 2 < gradient.size() && xx > 1) {
                x += 1;
                c0 = gradient.get(x);
                c1 = gradient.get(x + 1);
                xx = (pos - c0.w) / (c1.w - c0.w);
            }
            xx = 0.5 * (Math.sin(Math.PI * xx - Constants.HALF_PI) + 1);
            double a = 1 - xx;
            double b = xx;
            ray.color.set(a * c0.x + b * c1.x, a * c0.y + b * c1.y, a * c0.z + b * c1.z, 1);
        }
        break;
    }
    case SIMULATED: {
        scene.sun().calcSkyLight(ray, horizonOffset);
        break;
    }
    case SKYMAP_PANORAMIC: {
        if (mirrored) {
            double theta = FastMath.atan2(ray.d.z, ray.d.x);
            theta += rotation;
            theta /= Constants.TAU;
            if (theta > 1 || theta < 0) {
                theta = (theta % 1 + 1) % 1;
            }
            double phi = Math.abs(Math.asin(ray.d.y)) / Constants.HALF_PI;
            skymap.getColor(theta, phi, ray.color);
        } else {
            double theta = FastMath.atan2(ray.d.z, ray.d.x);
            theta += rotation;
            theta /= Constants.TAU;
            theta = (theta % 1 + 1) % 1;
            double phi = (Math.asin(ray.d.y) + Constants.HALF_PI) / Math.PI;
            skymap.getColor(theta, phi, ray.color);
        }
        break;
    }
    case SKYMAP_SPHERICAL: {
        double cos = FastMath.cos(-rotation);
        double sin = FastMath.sin(-rotation);
        double x = cos * ray.d.x + sin * ray.d.z;
        double y = ray.d.y;
        double z = -sin * ray.d.x + cos * ray.d.z;
        double len = Math.sqrt(x * x + y * y);
        double theta = (len < Ray.EPSILON) ? 0 : Math.acos(-z) / (Constants.TAU * len);
        double u = theta * x + .5;
        double v = .5 + theta * y;
        skymap.getColor(u, v, ray.color);
        break;
    }
    case SKYBOX: {
        double cos = FastMath.cos(-rotation);
        double sin = FastMath.sin(-rotation);
        double x = cos * ray.d.x + sin * ray.d.z;
        double y = ray.d.y;
        double z = -sin * ray.d.x + cos * ray.d.z;
        double xabs = QuickMath.abs(x);
        double yabs = QuickMath.abs(y);
        double zabs = QuickMath.abs(z);
        if (y > xabs && y > zabs) {
            double alpha = 1 / yabs;
            skybox[SKYBOX_UP].getColor((1 + x * alpha) / 2.0, (1 + z * alpha) / 2.0, ray.color);
        } else if (-z > xabs && -z > yabs) {
            double alpha = 1 / zabs;
            skybox[SKYBOX_FRONT].getColor((1 + x * alpha) / 2.0, (1 + y * alpha) / 2.0, ray.color);
        } else if (z > xabs && z > yabs) {
            double alpha = 1 / zabs;
            skybox[SKYBOX_BACK].getColor((1 - x * alpha) / 2.0, (1 + y * alpha) / 2.0, ray.color);
        } else if (-x > zabs && -x > yabs) {
            double alpha = 1 / xabs;
            skybox[SKYBOX_LEFT].getColor((1 - z * alpha) / 2.0, (1 + y * alpha) / 2.0, ray.color);
        } else if (x > zabs && x > yabs) {
            double alpha = 1 / xabs;
            skybox[SKYBOX_RIGHT].getColor((1 + z * alpha) / 2.0, (1 + y * alpha) / 2.0, ray.color);
        } else if (-y > xabs && -y > zabs) {
            double alpha = 1 / yabs;
            skybox[SKYBOX_DOWN].getColor((1 + x * alpha) / 2.0, (1 - z * alpha) / 2.0, ray.color);
        }
        break;
    }
    default:
        break;
    }
}

From source file:com.facebook.presto.operator.scalar.MathFunctions.java

@Description("arc sine")
@ScalarFunction/*  w  w  w.  j ava 2  s.  co m*/
@SqlType(StandardTypes.DOUBLE)
public static double asin(@SqlType(StandardTypes.DOUBLE) double num) {
    return Math.asin(num);
}