Example usage for java.lang Math toRadians

List of usage examples for java.lang Math toRadians

Introduction

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

Prototype

public static double toRadians(double angdeg) 

Source Link

Document

Converts an angle measured in degrees to an approximately equivalent angle measured in radians.

Usage

From source file:com.google.appinventor.components.runtime.GoogleMap.java

@SimpleFunction
public String getBoundingBox(double latitudeInDegrees, double longitudeInDegrees, double halfSideInKm) {
    // Semi-axes of WGS-84 geoidal reference
    double WGS84_a = 6378137.0; // Major semiaxis [m]
    double WGS84_b = 6356752.3; // Minor semiaxis [m]

    // Bounding box surrounding the point at given coordinates,
    // assuming local approximation of Earth surface as a sphere
    // of radius given by WGS84
    double lat = Math.toRadians(latitudeInDegrees);
    double lon = Math.toRadians(longitudeInDegrees);
    double halfSide = 1000 * halfSideInKm;

    // Radius of Earth at given latitude
    // Earth radius at a given latitude, according to the WGS-84 ellipsoid [m]
    // http://en.wikipedia.org/wiki/Earth_radius
    double An = WGS84_a * WGS84_a * Math.cos(lat);
    double Bn = WGS84_b * WGS84_b * Math.sin(lat);
    double Ad = WGS84_a * Math.cos(lat);
    double Bd = WGS84_b * Math.sin(lat);
    double radius = Math.sqrt((An * An + Bn * Bn) / (Ad * Ad + Bd * Bd));

    // Radius of the parallel at given latitude
    double pradius = radius * Math.cos(lat);

    double latMin = lat - halfSide / radius;
    double latMax = lat + halfSide / radius;
    double lonMin = lon - halfSide / pradius;
    double lonMax = lon + halfSide / pradius;

    String coordinates = Math.toDegrees(latMin) + "," + Math.toDegrees(lonMin) + "," + Math.toDegrees(latMax)
            + "," + Math.toDegrees(lonMax);
    return coordinates;
}

From source file:paintbasico2d.VentanaPrincipal.java

private void jButton180gradosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton180gradosActionPerformed
    VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
    if (vi != null) {
        BufferedImage ImgSource = vi.getLienzo().getImage();

        if (ImgSource != null) {
            double r = Math.toRadians(180);
            Point p = new Point(ImgSource.getWidth() / 2, ImgSource.getHeight() / 2);
            AffineTransform at = AffineTransform.getRotateInstance(r, p.x, p.y);

            try {

                AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
                BufferedImage imgdest = atop.filter(ImgSource, null);
                vi.getLienzo().setImage(imgdest);
                vi.getLienzo().repaint();
            } catch (Exception e) {
                System.err.println("error");
            }/*from   w  w w. j av  a  2  s .  c  o  m*/
        }
    }
}

From source file:paintbasico2d.VentanaPrincipal.java

private void jButton270gradosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton270gradosActionPerformed
    // TODO add your handling code here:
    VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
    if (vi != null) {
        BufferedImage ImgSource = vi.getLienzo().getImage();

        if (ImgSource != null) {
            double r = Math.toRadians(270);
            Point p = new Point(ImgSource.getWidth() / 2, ImgSource.getHeight() / 2);
            AffineTransform at = AffineTransform.getRotateInstance(r, p.x, p.y);

            try {

                AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
                BufferedImage imgdest = atop.filter(ImgSource, null);
                vi.getLienzo().setImage(imgdest);
                vi.getLienzo().repaint();
            } catch (Exception e) {
                System.err.println("error");
            }/* w  w  w .java2 s.  c o  m*/
        }
    }
}

From source file:paintbasico2d.VentanaPrincipal.java

private void jButton90gradosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton90gradosActionPerformed
    VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
    if (vi != null) {
        BufferedImage ImgSource = vi.getLienzo().getImage();

        if (ImgSource != null) {
            double r = Math.toRadians(90);
            Point p = new Point(ImgSource.getWidth() / 2, ImgSource.getHeight() / 2);
            AffineTransform at = AffineTransform.getRotateInstance(r, p.x, p.y);

            try {

                AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
                BufferedImage imgdest = atop.filter(ImgSource, null);
                vi.getLienzo().setImage(imgdest);
                vi.getLienzo().repaint();
            } catch (Exception e) {
                System.err.println("error");
            }//from  w ww  .  j  a va  2 s .  c  o  m
        }
    }
}

From source file:paintbasico2d.VentanaPrincipal.java

private void jSliderRotacionStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSliderRotacionStateChanged
    VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
    if (vi != null) {
        BufferedImage ImgSource = vi.getLienzo().getImage();
        if (img == null)
            img = ImgSource;//from www.  j  a  va2  s .com
        if (ImgSource != null) {

            try {
                double r = Math.toRadians(jSliderRotacion.getValue());
                Point p = new Point(img.getWidth(null) / 2, img.getWidth(null) / 2);
                AffineTransform at = AffineTransform.getRotateInstance(r, p.x, p.y);
                AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
                BufferedImage imgdest = atop.filter(img, null);
                vi.getLienzo().setImage(imgdest);
                vi.getLienzo().repaint();
            } catch (Exception e) {
                System.err.println("error");
            }
        }
    }
}

From source file:lineage2.gameserver.model.Skill.java

/**
 * Method addTargetsToList.//from   w  w  w  .  j a  va2  s.  co  m
 * @param targets List<Creature>
 * @param aimingTarget Creature
 * @param activeChar Creature
 * @param forceUse boolean
 */
private void addTargetsToList(List<Creature> targets, Creature aimingTarget, Creature activeChar,
        boolean forceUse) {
    int count = 0;
    Polygon terr = null;
    if (_targetType == SkillTargetType.TARGET_TUNNEL) {
        int radius = 100;
        int zmin1 = activeChar.getZ() - 200;
        int zmax1 = activeChar.getZ() + 200;
        int zmin2 = aimingTarget.getZ() - 200;
        int zmax2 = aimingTarget.getZ() + 200;
        double angle = PositionUtils.convertHeadingToDegree(activeChar.getHeading());
        double radian1 = Math.toRadians(angle - 90);
        double radian2 = Math.toRadians(angle + 90);
        terr = new Polygon()
                .add(activeChar.getX() + (int) (Math.cos(radian1) * radius),
                        activeChar.getY() + (int) (Math.sin(radian1) * radius))
                .add(activeChar.getX() + (int) (Math.cos(radian2) * radius),
                        activeChar.getY() + (int) (Math.sin(radian2) * radius))
                .add(aimingTarget.getX() + (int) (Math.cos(radian2) * radius),
                        aimingTarget.getY() + (int) (Math.sin(radian2) * radius))
                .add(aimingTarget.getX() + (int) (Math.cos(radian1) * radius),
                        aimingTarget.getY() + (int) (Math.sin(radian1) * radius))
                .setZmin(Math.min(zmin1, zmin2)).setZmax(Math.max(zmax1, zmax2));
    }
    for (Creature target : aimingTarget.getAroundCharacters(_skillRadius, 300)) {
        if ((terr != null) && !terr.isInside(target.getX(), target.getY(), target.getZ())) {
            continue;
        }
        if ((target == null) || (activeChar == target)
                || ((activeChar.getPlayer() != null) && (activeChar.getPlayer() == target.getPlayer()))) {
            continue;
        }
        if (getId() == SKILL_DETECTION) {
            target.checkAndRemoveInvisible();
        }
        if (checkTarget(activeChar, target, aimingTarget, forceUse, false) != null) {
            continue;
        }
        if (!(activeChar instanceof DecoyInstance) && activeChar.isNpc() && target.isNpc()) {
            continue;
        }
        targets.add(target);
        count++;
        if (isOffensive() && (count >= 20) && !activeChar.isRaid()) {
            break;
        }
    }
}

From source file:cc.flydev.launcher.Page.java

private PointF isFlingingToDelete() {
    ViewConfiguration config = ViewConfiguration.get(getContext());
    mVelocityTracker.computeCurrentVelocity(1000, config.getScaledMaximumFlingVelocity());

    if (mVelocityTracker.getYVelocity() < mFlingToDeleteThresholdVelocity) {
        // Do a quick dot product test to ensure that we are flinging upwards
        PointF vel = new PointF(mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
        PointF upVec = new PointF(0f, -1f);
        float theta = (float) Math
                .acos(((vel.x * upVec.x) + (vel.y * upVec.y)) / (vel.length() * upVec.length()));
        if (theta <= Math.toRadians(FLING_TO_DELETE_MAX_FLING_DEGREES)) {
            return vel;
        }//from  ww  w.j a v a2s.  c  om
    }
    return null;
}

From source file:lineage2.gameserver.model.Creature.java

/**
 * Method getIntersectionPoint./*  w  w w  .j  a va  2  s  .  c o  m*/
 * @param target Creature
 * @return Location
 */
public Location getIntersectionPoint(Creature target) {
    if (!PositionUtils.isFacing(this, target, 90)) {
        return new Location(target.getX(), target.getY(), target.getZ());
    }
    double angle = PositionUtils.convertHeadingToDegree(target.getHeading());
    double radian = Math.toRadians(angle - 90);
    double range = target.getMoveSpeed() / 2;
    return new Location((int) (target.getX() - (range * Math.sin(radian))),
            (int) (target.getY() + (range * Math.cos(radian))), target.getZ());
}

From source file:com.n2hsu.launcher.Page.java

private PointF isFlingingToDelete() {
    ViewConfiguration config = ViewConfiguration.get(getContext());
    mVelocityTracker.computeCurrentVelocity(1000, config.getScaledMaximumFlingVelocity());

    if (mVelocityTracker.getYVelocity() < mFlingToDeleteThresholdVelocity) {
        // Do a quick dot product test to ensure that we are flinging
        // upwards
        PointF vel = new PointF(mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
        PointF upVec = new PointF(0f, -1f);
        float theta = (float) Math
                .acos(((vel.x * upVec.x) + (vel.y * upVec.y)) / (vel.length() * upVec.length()));
        if (theta <= Math.toRadians(FLING_TO_DELETE_MAX_FLING_DEGREES)) {
            return vel;
        }//from  w  ww  .  j  a va2s .c  om
    }
    return null;
}

From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java

private void setCategoryItemLabelsData(AbstractCategoryItemRenderer renderer, cfCHARTSERIESData seriesData)
        throws cfmRunTimeException {
    // Set them as visible
    renderer.setItemLabelsVisible(true);

    // Set their color
    renderer.setItemLabelPaint(convertStringToColor(seriesData.getDataLabelColor()));

    // Set their font
    renderer.setItemLabelFont(getFont(seriesData.getDataLabelFont(), seriesData.getDataLabelFontBold(),
            seriesData.getDataLabelFontItalic(), seriesData.getDataLabelFontSize()));

    // Set the item label position for negative data values
    double degrees = seriesData.getDataLabelAngle();
    double radians = Math.toRadians(degrees);
    String negPosition = seriesData.getNegativeDataLabelPosition();
    if (negPosition.equals("top"))
        renderer.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, radians));
    else if (negPosition.equals("top_inside"))
        renderer.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE12,
                TextAnchor.TOP_CENTER, TextAnchor.CENTER, radians));
    else if (negPosition.equals("left"))
        renderer.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9,
                TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, radians));
    else if (negPosition.equals("left_inside"))
        renderer.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE9,
                TextAnchor.CENTER_LEFT, TextAnchor.CENTER, radians));
    else if (negPosition.equals("center"))
        renderer.setNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, radians));
    else if (negPosition.equals("right"))
        renderer.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3,
                TextAnchor.CENTER_LEFT, TextAnchor.CENTER, radians));
    else if (negPosition.equals("right_inside"))
        renderer.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE3,
                TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, radians));
    else if (negPosition.equals("bottom_inside"))
        renderer.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE6,
                TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, radians));
    else if (negPosition.equals("bottom"))
        renderer.setNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                TextAnchor.TOP_CENTER, TextAnchor.CENTER, radians));

    // Set the item label position for positive data values
    String posPosition = seriesData.getPositiveDataLabelPosition();
    if (posPosition.equals("top"))
        renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, radians));
    else if (posPosition.equals("top_inside"))
        renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE12,
                TextAnchor.TOP_CENTER, TextAnchor.CENTER, radians));
    else if (posPosition.equals("left"))
        renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9,
                TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, radians));
    else if (posPosition.equals("left_inside"))
        renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE9,
                TextAnchor.CENTER_LEFT, TextAnchor.CENTER, radians));
    else if (posPosition.equals("center"))
        renderer.setPositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, radians));
    else if (posPosition.equals("right"))
        renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3,
                TextAnchor.CENTER_LEFT, TextAnchor.CENTER, radians));
    else if (posPosition.equals("right_inside"))
        renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE3,
                TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, radians));
    else if (posPosition.equals("bottom_inside"))
        renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE6,
                TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, radians));
    else if (posPosition.equals("bottom"))
        renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                TextAnchor.TOP_CENTER, TextAnchor.CENTER, radians));

    // With Bar graphs and an inside position, we want to force the item labels
    // to be drawn even if they don't fit inside the bar graph.
    if (renderer instanceof BarRenderer) {
        ((BarRenderer) renderer).setNegativeItemLabelPositionFallback(renderer.getNegativeItemLabelPosition());
        ((BarRenderer) renderer).setPositiveItemLabelPositionFallback(renderer.getPositiveItemLabelPosition());
    }//from   w w  w.j  av a 2  s.  c om
}