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.jjoe64.graphview.GridLabelRenderer.java

/**
 * draws the horizontal steps//from w  w w  .  j ava2  s  .  c  o m
 * vertical lines and horizontal labels
 *
 * @param canvas canvas
 */
protected void drawHorizontalSteps(Canvas canvas) {
    // draw horizontal steps (vertical lines and horizontal labels)
    mPaintLabel.setColor(getHorizontalLabelsColor());
    int i = 0;
    for (Map.Entry<Integer, Double> e : mStepsHorizontal.entrySet()) {
        // draw line
        if (mStyles.highlightZeroLines) {
            if (e.getValue() == 0d) {
                mPaintLine.setStrokeWidth(5);
            } else {
                mPaintLine.setStrokeWidth(0);
            }
        }
        if (mStyles.gridStyle.drawVertical()) {
            canvas.drawLine(mGraphView.getGraphContentLeft() + e.getKey(), mGraphView.getGraphContentTop(),
                    mGraphView.getGraphContentLeft() + e.getKey(),
                    mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight(), mPaintLine);
        }

        // draw label
        if (isHorizontalLabelsVisible()) {
            if (mStyles.horizontalLabelsAngle > 0f && mStyles.horizontalLabelsAngle <= 180f) {
                if (mStyles.horizontalLabelsAngle < 90f) {
                    mPaintLabel.setTextAlign((Paint.Align.RIGHT));
                } else if (mStyles.horizontalLabelsAngle <= 180f) {
                    mPaintLabel.setTextAlign((Paint.Align.LEFT));
                }
            } else {
                mPaintLabel.setTextAlign(Paint.Align.CENTER);
                if (i == mStepsHorizontal.size() - 1)
                    mPaintLabel.setTextAlign(Paint.Align.RIGHT);
                if (i == 0)
                    mPaintLabel.setTextAlign(Paint.Align.LEFT);
            }

            // multiline labels
            String label = mLabelFormatter.formatLabel(e.getValue(), true);
            if (label == null) {
                label = "";
            }
            String[] lines = label.split("\n");

            // If labels are angled, calculate adjustment to line them up with the grid
            int labelWidthAdj = 0;
            if (mStyles.horizontalLabelsAngle > 0f && mStyles.horizontalLabelsAngle <= 180f) {
                Rect textBounds = new Rect();
                mPaintLabel.getTextBounds(lines[0], 0, lines[0].length(), textBounds);
                labelWidthAdj = (int) Math
                        .abs(textBounds.width() * Math.cos(Math.toRadians(mStyles.horizontalLabelsAngle)));
            }
            for (int li = 0; li < lines.length; li++) {
                // for the last line y = height
                float y = (canvas.getHeight() - mStyles.padding - getHorizontalAxisTitleHeight())
                        - (lines.length - li - 1) * getTextSize() * 1.1f + mStyles.labelsSpace;
                float x = mGraphView.getGraphContentLeft() + e.getKey();
                if (mStyles.horizontalLabelsAngle > 0 && mStyles.horizontalLabelsAngle < 90f) {
                    canvas.save();
                    canvas.rotate(mStyles.horizontalLabelsAngle, x + labelWidthAdj, y);
                    canvas.drawText(lines[li], x + labelWidthAdj, y, mPaintLabel);
                    canvas.restore();
                } else if (mStyles.horizontalLabelsAngle > 0 && mStyles.horizontalLabelsAngle <= 180f) {
                    canvas.save();
                    canvas.rotate(mStyles.horizontalLabelsAngle - 180f, x - labelWidthAdj, y);
                    canvas.drawText(lines[li], x - labelWidthAdj, y, mPaintLabel);
                    canvas.restore();
                } else {
                    canvas.drawText(lines[li], x, y, mPaintLabel);
                }
            }
        }
        i++;
    }
}

From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java

/**
 * Returns a cartesian point from a polar angle, length and bounding box
 *
 * @param bounds  the area inside which the point needs to be.
 * @param angle  the polar angle, in degrees.
 * @param length  the relative length. Given in percent of maximum extend.
 *
 * @return The cartesian point./*from w w w.  jav a 2 s  .  co m*/
 */
protected Point2D getWebPoint(Rectangle2D bounds, double angle, double length) {

    double angrad = Math.toRadians(angle);
    double x = Math.cos(angrad) * length * bounds.getWidth() / 2;
    double y = -Math.sin(angrad) * length * bounds.getHeight() / 2;

    return new Point2D.Double(bounds.getX() + x + bounds.getWidth() / 2,
            bounds.getY() + y + bounds.getHeight() / 2);
}

From source file:org.chombo.util.BasicUtils.java

/**
 * geo location distance by Haversine formula
 * @param lat1/*from  w  w  w  .j a v a  2  s  .co m*/
 * @param long1
 * @param lat2
 * @param long2
 * @return distance in km
 */
public static double getGeoDistance(double lat1, double long1, double lat2, double long2) {
    double latDistance = Math.toRadians(lat1 - lat2);
    double longDistance = Math.toRadians(long1 - long2);

    double a = (Math.sin(latDistance / 2) * Math.sin(latDistance / 2)) + (Math.cos(Math.toRadians(lat1)))
            * (Math.cos(Math.toRadians(lat2))) * (Math.sin(longDistance / 2)) * (Math.sin(longDistance / 2));
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    return AVERAGE_RADIUS_OF_EARTH * c;

}

From source file:org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverter.java

/**
 * Formats the lines for one type of boundary condition (QC or HC or ... ).
 */// ww  w  .  j av  a2s  .  c om
private void formatBoundCondLines(final Formatter formatter, final Calendar stepCal,
        final String bcAbscissaComponentType, final String bcOrdinateComponentType)
        throws IOException, CoreException {
    if (!m_isBCTupleResultIndexCached)
        cacheBCTupleResultIndexes();

    for (final IBoundaryCondition boundaryCondition : m_unitBoundaryConditions) {
        if (boundaryCondition.getTypeByLocation().equals(IBoundaryCondition.PARENT_TYPE_ELEMENT1D2D)
                || boundaryCondition.getTypeByLocation().equals(IBoundaryCondition.PARENT_TYPE_LINE1D2D)) {
            final int ordinal = m_nativeIDProvider.getConversionID(boundaryCondition.getParentElementID());
            final IObservation<TupleResult> obs = boundaryCondition.getObservation();
            final TupleResult obsResult = obs.getResult();
            final IComponent abscissaComponent = TupleResultUtilities.findComponentById(obsResult,
                    bcAbscissaComponentType);
            IComponent ordinateComponent = TupleResultUtilities.findComponentById(obsResult,
                    bcOrdinateComponentType);

            // TODO: type of absolute element inflow must also become the type specificDischarge
            if (ordinateComponent == null
                    && (bcOrdinateComponentType
                            .equals(Kalypso1D2DDictConstants.DICT_COMPONENT_SPECIFIC_DISCHARGE_1D)
                            || bcOrdinateComponentType
                                    .equals(Kalypso1D2DDictConstants.DICT_COMPONENT_SPECIFIC_DISCHARGE_2D))
                    && (boundaryCondition.isAbsolute() != null))
                ordinateComponent = TupleResultUtilities.findComponentById(obsResult,
                        Kalypso1D2DDictConstants.DICT_COMPONENT_DISCHARGE);

            if (abscissaComponent != null && ordinateComponent != null) {
                final double stepValue = findStepValue(stepCal, bcAbscissaComponentType,
                        bcOrdinateComponentType, boundaryCondition, ordinateComponent);

                if (bcAbscissaComponentType.equals(Kalypso1D2DDictConstants.DICT_COMPONENT_TIME)
                        && bcOrdinateComponentType.equals(Kalypso1D2DDictConstants.DICT_COMPONENT_DISCHARGE)
                        && (boundaryCondition.isAbsolute() == null)) {
                    // TODO: @Nico This is very ugly, but it works for the moment!! It should be introduced to GMLLoader checks
                    final Boolean hasDirectionProperty = boundaryCondition.hasDirection();
                    if (hasDirectionProperty == null)
                        boundaryCondition.setHasDirection(true);
                    else if (hasDirectionProperty == false)
                        boundaryCondition.setHasDirection(true);

                    final double theta = Math.toRadians(boundaryCondition.getDirection().doubleValue());
                    formatter.format("QC *%12d%8d%16.3f%8.3f%8.3f%8.3f%8.3f%n", ordinal, 0, stepValue, theta, //$NON-NLS-1$
                            0.000, 20.000, 0.000);
                } else if (bcAbscissaComponentType.equals(Kalypso1D2DDictConstants.DICT_COMPONENT_WATERLEVEL)
                        && bcOrdinateComponentType.equals(Kalypso1D2DDictConstants.DICT_COMPONENT_DISCHARGE)) {
                    // TODO: @Nico This is very ugly, but it works for the moment!! It should be introduced to GMLLoader checks
                    final Boolean hasDirectionProperty = boundaryCondition.hasDirection();
                    if (hasDirectionProperty == false || hasDirectionProperty == null)
                        boundaryCondition.setHasDirection(true);
                    final double theta = Math.toRadians(boundaryCondition.getDirection().doubleValue());
                    formatter.format("SQC%13d%40.4f%8.3f%8.3f%8.3f%n", ordinal, theta, 0.000, 20.000, 0.000); //$NON-NLS-1$
                    m_WQboundaryConditionsIDProvider.put(ordinal, boundaryCondition);
                } else if (bcAbscissaComponentType.equals(Kalypso1D2DDictConstants.DICT_COMPONENT_TIME)
                        && bcOrdinateComponentType.equals(Kalypso1D2DDictConstants.DICT_COMPONENT_WATERLEVEL)) {
                    formatter.format("HC%14d%8d%8.3f%8.3f%8.3f%8.3f%n", ordinal, 0, stepValue, 0.0, 20.000, //$NON-NLS-1$
                            0.0);
                } else if (bcAbscissaComponentType.equals(Kalypso1D2DDictConstants.DICT_COMPONENT_TIME)
                        && bcOrdinateComponentType
                                .equals(Kalypso1D2DDictConstants.DICT_COMPONENT_SPECIFIC_DISCHARGE_1D)
                        && boundaryCondition.getParentElementID().startsWith("Element1D")) //$NON-NLS-1$
                {
                    // 1D Element
                    final Boolean isAbsoluteProperty = boundaryCondition.isAbsolute();
                    final Boolean hasDirectionProperty = boundaryCondition.hasDirection();

                    // TODO: @Nico This is very ugly, but it works for the moment!! It should be introduced to GMLLoader checks
                    if (hasDirectionProperty == null) {
                        boundaryCondition.setHasDirection(false);
                        boundaryCondition.setDirection(new BigInteger("0")); //$NON-NLS-1$
                    }
                    if (boundaryCondition.hasDirection() && boundaryCondition.getDirection() == null)
                        boundaryCondition.setDirection(new BigInteger("0")); //$NON-NLS-1$

                    final int isAbsolute = (isAbsoluteProperty != null && isAbsoluteProperty.booleanValue()) ? 1
                            : 0;

                    if (boundaryCondition.hasDirection())
                        formatter.format("EFE%13d%8d%8d%8.3f%8.4f%8.4f%8.4f%8.4f%8.4f%n", ordinal, 0, //$NON-NLS-1$
                                isAbsolute, stepValue, 0.0, 20.000, 0.0, boundaryCondition.getInflowVelocity(),
                                Math.toRadians(boundaryCondition.getDirection().doubleValue()));
                    else
                        formatter.format("EFE%13d%8d%8d%8.3f%8.4f%8.4f%8.4f%n", ordinal, 0, isAbsolute, //$NON-NLS-1$
                                stepValue, 0.0, 20.000, 0.0);
                } else if (bcAbscissaComponentType.equals(Kalypso1D2DDictConstants.DICT_COMPONENT_TIME)
                        && bcOrdinateComponentType
                                .equals(Kalypso1D2DDictConstants.DICT_COMPONENT_SPECIFIC_DISCHARGE_2D)
                        && !boundaryCondition.getParentElementID().startsWith("Element1D")) //$NON-NLS-1$
                {
                    // 2D Element
                    final Boolean isAbsoluteProperty = boundaryCondition.isAbsolute();
                    final Boolean hasDirectionProperty = boundaryCondition.hasDirection();

                    // TODO: @Nico This is very ugly, but it works for the moment!! It should be introduced to GMLLoader checks
                    if (hasDirectionProperty == null) {
                        boundaryCondition.setHasDirection(false);
                        boundaryCondition.setDirection(new BigInteger("0")); //$NON-NLS-1$
                    }
                    if (boundaryCondition.hasDirection() && boundaryCondition.getDirection() == null)
                        boundaryCondition.setDirection(new BigInteger("0")); //$NON-NLS-1$

                    final int isAbsolute = (isAbsoluteProperty != null && isAbsoluteProperty.booleanValue()) ? 1
                            : 0;
                    if (boundaryCondition.hasDirection()) {
                        double infVel = 0.001;
                        try {
                            infVel = boundaryCondition.getInflowVelocity();
                        } catch (final Exception e) {
                            // FIXME: grr, error handling -> we need to stop calculation in such a case!
                            m_log.log(IStatus.WARNING, ISimulation1D2DConstants.CODE_PRE,
                                    Messages.getString("Control1D2DConverter.1"), //$NON-NLS-1$
                                    boundaryCondition.getLocation(), e);
                        }
                        formatter.format("EFE%13d%8d%8d%8.3f%8.4f%8.4f%8.4f%8.4f%8.4f%n", ordinal, 0, //$NON-NLS-1$
                                isAbsolute, stepValue, 0.0, 20.000, 0.0, infVel,
                                Math.toRadians(boundaryCondition.getDirection().doubleValue()));
                    } else
                        formatter.format("EFE%13d%8d%8d%8.3f%8.4f%8.4f%8.4f%n", ordinal, 0, isAbsolute, //$NON-NLS-1$
                                stepValue, 0.0, 20.000, 0.0);
                }
            }
        }

        FormatterUtils.checkIoException(formatter);
    }
}

From source file:au.org.ala.biocache.web.OccurrenceController.java

private Double distInMetres(Double lat1, Double lon1, Double lat2, Double lon2) {
    Double R = 6371000d; // km
    Double dLat = Math.toRadians(lat2 - lat1);
    Double dLon = Math.toRadians(lon2 - lon1);
    Double lat1Rad = Math.toRadians(lat1);
    Double lat2Rad = Math.toRadians(lat2);
    Double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
            + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1Rad) * Math.cos(lat2Rad);
    Double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    return R * c;
}

From source file:AppearanceTest.java

public void onX_30_degrees() {
    Transform3D t3d = new Transform3D();
    t3d.rotX(Math.toRadians(30));
    getTextureAttributes().setTextureTransform(t3d);
}

From source file:AppearanceTest.java

public void onY_30_degrees() {
    Transform3D t3d = new Transform3D();
    t3d.rotY(Math.toRadians(30));
    getTextureAttributes().setTextureTransform(t3d);
}

From source file:AppearanceTest.java

public void onZ_30_degrees() {
    Transform3D t3d = new Transform3D();
    t3d.rotZ(Math.toRadians(30));
    getTextureAttributes().setTextureTransform(t3d);
}

From source file:org.apache.calcite.runtime.SqlFunctions.java

/** SQL <code>RADIANS</code> operator applied to long values. */
public static double radians(long b0) {
    return Math.toRadians(b0);
}

From source file:org.apache.calcite.runtime.SqlFunctions.java

/** SQL <code>RADIANS</code> operator applied to BigDecimal values. */
public static double radians(BigDecimal b0) {
    return Math.toRadians(b0.doubleValue());
}