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:edu.jhuapl.graphs.jfreechart.utils.RotatedTickDateAxis.java

@Override
protected double findMaximumTickLabelHeight(List ticks, Graphics2D g2, Rectangle2D drawArea, boolean vertical) {
    double heightScalingFactor = Math.abs(Math.sin(Math.toRadians(tickLabelAngle)));
    return super.findMaximumTickLabelHeight(ticks, g2, drawArea, vertical) * heightScalingFactor;
}

From source file:com.github.mfpdev.marketing.StoreCategorySegmentResolverResource.java

private double distance(double lon1, double lat1, double lon2, double lat2) {
    double dLat = Math.toRadians(lat2 - lat1); // Javascript functions in radians
    double dLon = Math.toRadians(lon2 - lon1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1))
            * Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    return EARTH_RADIUS * c; // Distance in km
}

From source file:com.laex.cg2d.model.joints.BEPrismaticJoint.java

@Override
public void setPropertyValue(Object id, Object value) {
    if (isWorldAnchorProp(id)) {
        this.worldAnchor = (Vector2) value;
    } else if (isWorldAxisProp(id)) {
        this.worldAxis = (Vector2) value;
    } else if (isReferenceAngleProp(id)) {
        prismaticJointDef.referenceAngle = (float) Math.toRadians(FloatUtil.toFloat(value));
    } else if (isEnableLimitProp(id)) {
        prismaticJointDef.enableLimit = BooleanUtil.toBool(value);
    } else if (isLowerTranslationProp(id)) {
        prismaticJointDef.lowerTranslation = FloatUtil.toFloat(value);
    } else if (isUpperTranslationProp(id)) {
        prismaticJointDef.upperTranslation = FloatUtil.toFloat(value);
    } else if (isEnableMotorProp(id)) {
        prismaticJointDef.enableMotor = BooleanUtil.toBool(value);
    } else if (isMaxMotorForceProp(id)) {
        prismaticJointDef.maxMotorForce = FloatUtil.toFloat(value);
    } else if (isMotorSpeedProp(id)) {
        prismaticJointDef.motorSpeed = FloatUtil.toFloat(value);
    } else {//from   ww  w  .  j  ava 2 s  .c om
        super.setPropertyValue(id, value);
    }
}

From source file:magma.agent.worldmodel.impl.VisibleObjectTest.java

/**
 * Test method for//from  www.  j a va  2  s. c o  m
 * {@link magma.agent.worldmodel.impl.VisibleObject#update(magma.agent.perception.impl.VisibleObjectPerceptor, float, IThisPlayer)}
 * .
 */
@Test
public void testUpdateRotation45() {
    VisibleObjectPerceptor vision = new VisibleObjectPerceptor("test", new Vector3D(2.0, 2.0, 0.0));
    thisPlayer.setPosition(new Vector3D(0.0, 0.0, 0.0));
    thisPlayer.setHorizontalAngle(Angle.deg(-45.0));
    double x = 2.0 / Math.cos(Math.toRadians(-45.0));

    testee.update(vision, 1.0f, thisPlayer);
    Vector3D position = testee.getPosition();
    testVector(new Vector3D(x, 0.0, 0.0), position);
}

From source file:VrmlPickingTest.java

public TransformGroup[] getViewTransformGroupArray() {
    TransformGroup[] tgArray = new TransformGroup[1];
    tgArray[0] = new TransformGroup();

    Transform3D viewTrans = new Transform3D();
    Transform3D eyeTrans = new Transform3D();

    BoundingSphere sceneBounds = (BoundingSphere) m_SceneBranchGroup.getBounds();

    // point the view at the center of the object
    Point3d center = new Point3d();
    sceneBounds.getCenter(center);/*from   ww  w .j  a  va2  s.  c o m*/
    double radius = sceneBounds.getRadius();
    Vector3d temp = new Vector3d(center);
    viewTrans.set(temp);

    // pull the eye back far enough to see the whole object
    double eyeDist = 1.4 * radius / Math.tan(Math.toRadians(40) / 2.0);
    temp.x = 0.0;
    temp.y = 0.0;
    temp.z = eyeDist;
    eyeTrans.set(temp);
    viewTrans.mul(eyeTrans);

    // set the view transform
    tgArray[0].setTransform(viewTrans);

    return tgArray;
}

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

/**
 * @param p  WGS84 lat/lon (ellipsoid GRS80) (in degree)
 * @return eastnorth projection in Lambert Zone (ellipsoid Clark)
 *//*from   ww w  .j  a v  a  2  s . c  o  m*/
public EastNorth latlon2eastNorth(LatLon p) {
    // translate ellipsoid GRS80 (WGS83) => Clark
    LatLon geo = GRS802Clark(p);
    double lt = geo.lat(); // in radian
    double lg = geo.lon();

    // check if longitude and latitude are inside the French Lambert zones
    currentZone = 0;
    boolean outOfLambertZones = false;
    if (lt >= zoneLimits[3] && lt <= cMaxLatZone1 && lg >= cMinLonZones && lg <= cMaxLonZones) {
        // zone I
        if (lt > zoneLimits[0])
            currentZone = 0;
        // zone II
        else if (lt > zoneLimits[1])
            currentZone = 1;
        // zone III
        else if (lt > zoneLimits[2])
            currentZone = 2;
        // zone III or IV
        else if (lt > zoneLimits[3])
            // Note: zone IV is dedicated to Corsica island and extends from 47.8 to
            // 45.9 degrees of latitude. There is an overlap with zone III that can be
            // solved only with longitude (covers Corsica if lon > 7.2 degree)
            if (lg < Math.toRadians(8 * 0.9))
                currentZone = 2;
            else
                currentZone = 3;
    } else {
        outOfLambertZones = true; // possible when MAX_LAT is used
    }
    if (!outOfLambertZones) {
        if (layoutZone == -1) {
            layoutZone = currentZone;
            dontDisplayErrors = false;
        } else if (layoutZone != currentZone) {
            if ((currentZone < layoutZone && Math.abs(zoneLimits[currentZone] - lt) > cMaxOverlappingZones)
                    || (currentZone > layoutZone
                            && Math.abs(zoneLimits[layoutZone] - lt) > cMaxOverlappingZones)) {
                JOptionPane.showMessageDialog(Main.parent,
                        tr("IMPORTANT : data positioned far away from\n" + "the current Lambert zone limits.\n"
                                + "Do not upload any data after this message.\n"
                                + "Undo your last action, save your work\n"
                                + "and start a new layer on the new zone."));
                layoutZone = -1;
                dontDisplayErrors = true;
            } else {
                LOG.debug("temporarily extend Lambert zone " + layoutZone + " projection at lat,lon:" + lt + ","
                        + lg);
            }
        }
    }
    if (layoutZone == -1) {
        return ConicProjection(lt, lg, Xs[currentZone], Ys[currentZone], c[currentZone], n[currentZone]);
    } // else
    return ConicProjection(lt, lg, Xs[layoutZone], Ys[layoutZone], c[layoutZone], n[layoutZone]);
}

From source file:com.esri.geoevent.solutions.processor.geometry.RangeFanProcessor.java

private Geometry constructRangeFan(double x, double y, double range, String unit, double bearing,
        double traversal) throws GeometryException {
    Polygon fan = new Polygon();
    Point center = new Point();
    center.setX(x);/*from   w  w  w  .jav a 2s .  c om*/
    center.setY(y);
    // SpatialReference srIn = SpatialReference.create(wkidin);
    // SpatialReference srBuffer = SpatialReference.create(wkidbuffer);
    // SpatialReference srOut = SpatialReference.create(wkidout);
    Point centerProj = (Point) GeometryEngine.project(center, srIn, srBuffer);

    double centerX = centerProj.getX();
    double centerY = centerProj.getY();
    bearing = GeometryUtility.Geo2Arithmetic(bearing);
    double leftAngle = bearing - (traversal / 2);
    double rightAngle = bearing + (traversal / 2);
    int count = (int) Math.round(Math.abs(leftAngle - rightAngle));
    fan.startPath(centerProj);
    UnitConverter uc = new UnitConverter();
    range = uc.Convert(range, unit, srBuffer);
    for (int i = 0; i < count; ++i) {
        double d = Math.toRadians(leftAngle + i);
        double arcX = centerX + (range * Math.cos(d));
        double arcY = centerY + (range * Math.sin(d));
        Point arcPt = new Point(arcX, arcY);
        // arcPt = (Point) GeometryEngine.project(arcPt, srBuffer, srOut);
        fan.lineTo(arcPt);
    }
    fan.closeAllPaths();
    return fan;
}

From source file:com.liusoft.dlog4j.util.ImageUtils.java

/**
 * ???//from  w  w  w .j a  v a2  s  .c  om
 * ?????
 * 3: 180
 * 6: 90
 * 8: 27090
 * @param img_fn
 * @param orient
 * @throws IOException 
 */
public static boolean rotateImage(String img_fn, int orient, String dest_fn) throws IOException {
    double radian = 0;
    switch (orient) {
    case 3:
        radian = 180.0;
        break;
    case 6:
        radian = 90.0;
        break;
    case 8:
        radian = 270.0;
        break;
    default:
        return false;
    }
    BufferedImage old_img = (BufferedImage) ImageIO.read(new File(img_fn));
    int width = old_img.getWidth();
    int height = old_img.getHeight();

    BufferedImage new_img = new BufferedImage(height, width, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = new_img.createGraphics();

    AffineTransform origXform = g2d.getTransform();
    AffineTransform newXform = (AffineTransform) (origXform.clone());
    // center of rotation is center of the panel
    double xRot = 0;
    double yRot = 0;
    switch (orient) {
    case 3:
        xRot = width / 2.0;
        yRot = height / 2.0;
    case 6:
        xRot = height / 2.0;
        yRot = xRot;
        break;
    case 8:
        xRot = width / 2.0;
        yRot = xRot;
        break;
    default:
        return false;
    }
    newXform.rotate(Math.toRadians(radian), xRot, yRot);

    g2d.setTransform(newXform);
    // draw image centered in panel
    g2d.drawImage(old_img, 0, 0, null);
    // Reset to Original
    g2d.setTransform(origXform);

    FileOutputStream out = new FileOutputStream(dest_fn);
    try {
        ImageIO.write(new_img, "JPG", out);
    } finally {
        out.close();
    }
    return true;
}

From source file:com.bdb.weather.display.windplot.WindItemRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device./*  w w w.  ja va  2  s  .co  m*/
 * @param rendererState  the renderer state.
 * @param dataArea  the area within which the data is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  crosshair information for the plot
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState rendererState, Rectangle2D dataArea,
        PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
        int series, int item, CrosshairState crosshairState, int pass) {
    //
    // Let the base class handle drawing the line and the shapes (passes 0 and 1). This class will handle drawing the
    // wind direction lines.
    //
    if (pass < 2)
        super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
                crosshairState, pass);
    else {
        if (!(dataset instanceof TimeSeriesCollection) || !showWindDirectionLines)
            return;

        if (item == 0)
            state.resetLastDirection();

        RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
        RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

        TimeSeriesCollection collection = (TimeSeriesCollection) dataset;
        TimeSeries timeSeries = collection.getSeries(series);

        if (!(timeSeries instanceof WindSeries))
            return;

        WindSeries windSeries = (WindSeries) timeSeries;
        WindSeriesDataItem windItem = windSeries.getWindDataItem(item);
        double speed = windItem.getWindSpeed().doubleValue();
        double time = dataset.getXValue(series, item);
        double dir = windItem.getWindDirection().doubleValue();

        if (speed > 0.0 && dir != state.getLastDirection()) {
            state.setLastDirection(dir);
            double radians = Math.toRadians(dir - 90.0);
            double dirXOffset = directionLineLength * Math.cos(radians);
            double dirYOffset = directionLineLength * Math.sin(radians);

            double transTime = domainAxis.valueToJava2D(time, dataArea, xAxisLocation);
            double transSpeed = rangeAxis.valueToJava2D(speed, dataArea, yAxisLocation);
            double dirX = transTime + dirXOffset;
            double dirY = transSpeed + dirYOffset;

            // update path to reflect latest point
            if (!Double.isNaN(transTime) && !Double.isNaN(transSpeed)) {
                int x1 = (int) transTime;
                int y1 = (int) transSpeed;
                int x2 = (int) dirX;
                int y2 = (int) dirY;
                PlotOrientation orientation = plot.getOrientation();
                if (orientation == PlotOrientation.HORIZONTAL) {
                    x1 = (int) transSpeed;
                    y1 = (int) transTime;
                    x2 = (int) dirY;
                    y2 = (int) dirX;
                }
                g2.setPaint(windDirectionPaint);
                g2.setStroke(windDirectionStroke);
                g2.drawLine(x1, y1, x2, y2);
            }
        }
    }
}

From source file:AWTInteraction.java

public void processStimulus(Enumeration criteria) {
    angle += Math.toRadians(10.0);
    trans.rotY(angle);
    transformGroup.setTransform(trans);
    wakeupOn(criterion);
}