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:lucee.runtime.img.Image.java

public void rotateAxis(double angle, double x, double y) throws ExpressionException {
    getGraphics().rotate(Math.toRadians(angle), x, y);
}

From source file:io.doist.datetimepicker.time.RadialTimePickerView.java

private void drawSelector(Canvas canvas, int index) {
    // Calculate the current radius at which to place the selection circle.
    mLineLength[index] = (int) (mCircleRadius[index] * mNumbersRadiusMultiplier[index]
            * mAnimationRadiusMultiplier[index]);

    double selectionRadians = Math.toRadians(mSelectionDegrees[index]);

    int pointX = mXCenter + (int) (mLineLength[index] * Math.sin(selectionRadians));
    int pointY = mYCenter - (int) (mLineLength[index] * Math.cos(selectionRadians));

    int color;/*  w w  w  .jav  a2s.c o m*/
    int alpha;
    Paint paint;

    // Draw the selection circle
    color = mColorSelector[index % 2][SELECTOR_CIRCLE];
    alpha = mAlphaSelector[index % 2][SELECTOR_CIRCLE].getValue();
    paint = mPaintSelector[index % 2][SELECTOR_CIRCLE];
    paint.setColor(color);
    paint.setAlpha(getMultipliedAlpha(color, alpha));
    canvas.drawCircle(pointX, pointY, mSelectionRadius[index], paint);

    // Draw the dot if needed
    if (mSelectionDegrees[index] % 30 != 0) {
        // We're not on a direct tick
        color = mColorSelector[index % 2][SELECTOR_DOT];
        alpha = mAlphaSelector[index % 2][SELECTOR_DOT].getValue();
        paint = mPaintSelector[index % 2][SELECTOR_DOT];
        paint.setColor(color);
        paint.setAlpha(getMultipliedAlpha(color, alpha));
        canvas.drawCircle(pointX, pointY, (mSelectionRadius[index] * 2 / 7), paint);
    } else {
        // We're not drawing the dot, so shorten the line to only go as far as the edge of the
        // selection circle
        int lineLength = mLineLength[index] - mSelectionRadius[index];
        pointX = mXCenter + (int) (lineLength * Math.sin(selectionRadians));
        pointY = mYCenter - (int) (lineLength * Math.cos(selectionRadians));
    }

    // Draw the line
    color = mColorSelector[index % 2][SELECTOR_LINE];
    alpha = mAlphaSelector[index % 2][SELECTOR_LINE].getValue();
    paint = mPaintSelector[index % 2][SELECTOR_LINE];
    paint.setColor(color);
    paint.setAlpha(getMultipliedAlpha(color, alpha));
    canvas.drawLine(mXCenter, mYCenter, pointX, pointY, paint);
}

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

/**
 * writes out the time steps. <BR>
 * IMPORTANT: we write the dates in the time zone according to the kalypso-preferences!
 *//*  w  w  w.  ja  v a  2 s  .c o  m*/
private void writeTimeStep(final Formatter formatter, final String message, final Calendar calculationStep,
        final Calendar lastStepCal, final String uRVal, final int niti) throws CoreException, IOException {
    final String dashes = StringUtils.repeat("-", message.length()); //$NON-NLS-1$
    formatter.format("com %s%n", dashes); //$NON-NLS-1$
    formatter.format("com %s%n", message); //$NON-NLS-1$
    formatter.format("com %s%n", dashes); //$NON-NLS-1$

    final long timeStepInterval;
    final double timeStepMinutes;
    final int year;
    final int dayOfYear;
    final double ihre;

    final TimeZone displayTimeZone = KalypsoCorePlugin.getDefault().getTimeZone();
    Calendar kalypsoCalendarStep = Calendar.getInstance(displayTimeZone);

    // unsteady
    if (calculationStep != null) {
        // REMARK: we write the date in the kalypso-preferences time zone!
        kalypsoCalendarStep.setTime(calculationStep.getTime());
        dayOfYear = kalypsoCalendarStep.get(Calendar.DAY_OF_YEAR);
        year = kalypsoCalendarStep.get(Calendar.YEAR);

        // REMARK: we write the date in the kalypso-preferences time zone!
        final Calendar kalypsoCallendarPreviousStep = Calendar.getInstance(displayTimeZone);
        kalypsoCallendarPreviousStep.setTime(lastStepCal.getTime());

        timeStepInterval = kalypsoCalendarStep.getTimeInMillis()
                - kalypsoCallendarPreviousStep.getTimeInMillis();

        // FIXME: should never happen, kalypso does not allow summertime timezones any more
        // if timeStepInterval is zero, step will be ignored
        // (this will happen on summertime to wintertime transition)
        if (timeStepInterval == 0) {
            formatter.format(Messages.getString("org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverter.14")); //$NON-NLS-1$
            return;
        }

        timeStepMinutes = (double) timeStepInterval / (60 * 1000);
        ihre = getTimeInPercentage(kalypsoCalendarStep);
    }
    // steady dont need startdate
    else {
        kalypsoCalendarStep = null;
        dayOfYear = 0;
        year = 0;
        timeStepMinutes = 0;
        ihre = 0;
    }

    formatter.format("DT MIN  %e%8d%8d%8.2f", timeStepMinutes, year, dayOfYear, ihre); //$NON-NLS-1$

    // BC lines
    if (niti == 0)
        formatter.format("%nBC%n"); //$NON-NLS-1$
    else
        formatBC(formatter, uRVal, niti);

    // order is important, first QC than HC, SQC and EFE
    formatBoundCondLines(formatter, kalypsoCalendarStep, Kalypso1D2DDictConstants.DICT_COMPONENT_TIME,
            Kalypso1D2DDictConstants.DICT_COMPONENT_DISCHARGE);
    formatBoundCondLines(formatter, kalypsoCalendarStep, Kalypso1D2DDictConstants.DICT_COMPONENT_TIME,
            Kalypso1D2DDictConstants.DICT_COMPONENT_WATERLEVEL);
    formatBoundCondLines(formatter, kalypsoCalendarStep, Kalypso1D2DDictConstants.DICT_COMPONENT_WATERLEVEL,
            Kalypso1D2DDictConstants.DICT_COMPONENT_DISCHARGE);

    FormatterUtils.checkIoException(formatter);

    for (final Map.Entry<Integer, IFlowRelationship> buildingData : m_buildingProvider.getBuildingData()
            .entrySet()) {
        final Integer buildingID = buildingData.getKey();
        final IFlowRelationship building = buildingData.getValue();
        final int buildingKind = 10;
        int lIntDirection = 0;
        if (building instanceof IBuildingFlowRelation) {
            if (((IBuildingFlowRelation) building).getKind() != KIND.TABULAR) {
                final String msg = Messages.getString(
                        "org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverter.43", //$NON-NLS-1$
                        ((IBuildingFlowRelation) building).getKind());
                throw new CoreException(new Status(IStatus.ERROR, KalypsoModel1D2DPlugin.PLUGIN_ID, msg));
            }
            lIntDirection = ((IBuildingFlowRelation) building).getDirection();
        } else if (building instanceof IBuildingFlowRelation2D) {
            if (((IBuildingFlowRelation2D) building).getKind() != KIND2D.TABULAR) {
                final String msg = Messages.getString(
                        "org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverter.43", //$NON-NLS-1$
                        ((IBuildingFlowRelation) building).getKind());
                throw new CoreException(new Status(IStatus.ERROR, KalypsoModel1D2DPlugin.PLUGIN_ID, msg));
            }
            lIntDirection = ((IBuildingFlowRelation2D) building).getDirection();
        }
        final double direction = Math.toRadians(lIntDirection);
        formatter.format("FC%14d%8d%8.3f%8.3f%8.3f%8.3f%8.3f%n", buildingID, buildingKind, 0.0, 0.0, 0.0, 0.0, //$NON-NLS-1$
                direction);

        FormatterUtils.checkIoException(formatter);
    }

    formatBoundCondLines(formatter, kalypsoCalendarStep, Kalypso1D2DDictConstants.DICT_COMPONENT_TIME,
            Kalypso1D2DDictConstants.DICT_COMPONENT_SPECIFIC_DISCHARGE_1D);
    formatBoundCondLines(formatter, kalypsoCalendarStep, Kalypso1D2DDictConstants.DICT_COMPONENT_TIME,
            Kalypso1D2DDictConstants.DICT_COMPONENT_SPECIFIC_DISCHARGE_2D);

    // add other conti lines types as well (buildings)?
    if (m_controlModel.getHasWindDrag() && !m_boolPrintWindLineDone) {
        formatter.format("WVA          1.0     1.0       1%n"); //$NON-NLS-1$
        m_boolPrintWindLineDone = true;
    }
    formatter.format("ENDSTEP %s%n", message); //$NON-NLS-1$

    FormatterUtils.checkIoException(formatter);
}

From source file:org.jrman.parser.Parser.java

public void addDisk(final float height, final float radius, float tMax, final ParameterList parameters) {
    if (inAreaLightSource)
        return;//from   w ww . j av a 2 s  .  com
    final float thetaMax = (float) Math.toRadians(tMax);
    if (!inObject) {
        renderer.addPrimitive(new Disk(height, 0f, thetaMax, 0f, radius, parameters, getAttributes()));
        diskCount++;
    } else {
        final Transform transform = currentAttributes.getTransform();
        currentObjectInstanceList.addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() {
            public Primitive create(Attributes attributes) {
                coneCount++;
                return new Disk(height, 0f, thetaMax, 0f, radius, parameters,
                        createAttributes(transform, attributes));
            }
        });
    }
}

From source file:eu.trentorise.smartcampus.mobility.util.GamificationHelper.java

private static double harvesineDistance(double lat1, double lon1, double lat2, double lon2) {
    lat1 = Math.toRadians(lat1);
    lon1 = Math.toRadians(lon1);/*from w w w . ja  v a 2s.  c  om*/
    lat2 = Math.toRadians(lat2);
    lon2 = Math.toRadians(lon2);

    double dlon = lon2 - lon1;
    double dlat = lat2 - lat1;

    double a = Math.pow((Math.sin(dlat / 2)), 2)
            + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon / 2), 2);

    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));

    return EARTH_RADIUS * c;
}

From source file:web.diva.server.model.SomClustering.SomClustImgGenerator.java

private BufferedImage rotateImage(BufferedImage masterImage, int angle) {
    int virtualAngle = getVirtualAngle(angle);
    Dimension size = new Dimension(masterImage.getWidth(), masterImage.getHeight());
    int masterWidth = masterImage.getWidth();
    int masterHeight = masterImage.getHeight();

    double x = 0; //masterWidth / 2.0;
    double y = 0; //masterHeight / 2.0;

    switch (virtualAngle) {
    case 0:/*from   w  w  w.  j  ava2  s. co m*/
        break;
    case 180:
        break;
    case 90:
    case 270:
        size = new Dimension(masterImage.getHeight(), masterImage.getWidth());
        x = (masterHeight - masterWidth) / 2.0;
        y = (masterWidth - masterHeight) / 2.0;
        break;
    }
    BufferedImage renderedImage = new BufferedImage(size.width, size.height, masterImage.getTransparency());
    Graphics2D g2d = renderedImage.createGraphics();

    AffineTransform at = AffineTransform.getTranslateInstance(x, y);

    at.rotate(Math.toRadians(virtualAngle), masterWidth / 2.0, masterHeight / 2.0);
    g2d.drawImage(masterImage, at, null);

    g2d.dispose();
    return renderedImage;
}

From source file:org.jrman.parser.Parser.java

public void addParaboloid(final float radius, final float zmin, final float zmax, float tMax,
        final ParameterList parameters) {
    if (inAreaLightSource)
        return;//  w w w  .ja v a  2 s.  c  om

    final float thetaMin = 0f;
    final float thetaMax = (float) Math.toRadians(tMax);
    if (!inObject) {
        renderer.addPrimitive(new Paraboloid(radius, zmin, zmax, thetaMin, thetaMax, zmin, zmax, thetaMax,
                parameters, getAttributes()));
        paraboloidCount++;
    } else {
        final Transform transform = currentAttributes.getTransform();
        currentObjectInstanceList.addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() {
            public Primitive create(Attributes attributes) {
                paraboloidCount++;
                return new Paraboloid(radius, zmin, zmax, thetaMin, thetaMax, zmin, zmax, thetaMax, parameters,
                        createAttributes(transform, attributes));
            }
        });
    }
}

From source file:ac.robinson.paperchains.PaperChainsActivity.java

private void animateRecordingInterface(int direction, View keyView) {
    mPlayButton.setVisibility(View.VISIBLE);
    mDeleteButton.setVisibility(View.VISIBLE);
    mSaveButton.setVisibility(View.VISIBLE);

    // animate the control buttons out to be equally spaced around the record button
    float buttonOffset = -mPlayButton.getWidth();
    PointF centre = new PointF(0, 0);
    PointF startingPoint = new PointF(0, buttonOffset);
    double radRot = Math.toRadians(-120);
    double cosRot = Math.cos(radRot);
    double sinRot = Math.sin(radRot);
    QRImageParser.rotatePoint(startingPoint, centre, cosRot, sinRot);
    float leftX = startingPoint.x;
    float leftY = startingPoint.y;
    QRImageParser.rotatePoint(startingPoint, centre, cosRot, sinRot);
    float rightX = startingPoint.x;
    float rightY = startingPoint.y;

    RelativeLayout parent;//from  w ww  .j a  va 2s  .  co  m
    AnimatorSet buttonAnimator = new AnimatorSet();
    switch (direction) {
    case 1: // out
        // on an outward animation, we want the three minor buttons to have priority so the record button's
        // larger click area doesn't capture their clicks
        mPlayButton.bringToFront();
        mDeleteButton.bringToFront();
        mSaveButton.bringToFront();
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            // need to manually re-layout before KitKat
            parent = (RelativeLayout) mPlayButton.getParent();
            parent.requestLayout();
            parent.invalidate();
        }

        buttonAnimator.playTogether(ObjectAnimator.ofFloat(mDeleteButton, "translationX", 0, leftX),
                ObjectAnimator.ofFloat(mDeleteButton, "translationY", 0, leftY),
                ObjectAnimator.ofFloat(mSaveButton, "translationX", 0, rightX),
                ObjectAnimator.ofFloat(mSaveButton, "translationY", 0, rightY),
                ObjectAnimator.ofFloat(mPlayButton, "translationY", 0, buttonOffset));
        buttonAnimator.setInterpolator(new OvershootInterpolator());
        break;
    case -1: // in
        // keyView is the view we want to be at the front after an inward animation
        if (keyView != null) {
            keyView.bringToFront();
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
                // need to manually re-layout before KitKat
                parent = (RelativeLayout) keyView.getParent();
                parent.requestLayout();
                parent.invalidate();
            }
        }

        buttonAnimator.playTogether(ObjectAnimator.ofFloat(mDeleteButton, "translationX", leftX, 0),
                ObjectAnimator.ofFloat(mDeleteButton, "translationY", leftY, 0),
                ObjectAnimator.ofFloat(mSaveButton, "translationX", rightX, 0),
                ObjectAnimator.ofFloat(mSaveButton, "translationY", rightY, 0),
                ObjectAnimator.ofFloat(mPlayButton, "translationY", buttonOffset, 0));
        buttonAnimator.setInterpolator(new AnticipateInterpolator());
        break;
    }
    buttonAnimator.setDuration(BUTTON_ANIMATION_DURATION);
    buttonAnimator.start();
}

From source file:com.sidekickApp.AppState.java

public static Double haversine(Double lat1, Double lon1, Double lat2, Double lon2) {
    int R = 6371;
    Double dLat = Math.toRadians(lat2 - lat1);
    Double dLon = Math.toRadians(lon2 - lon1);

    Double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2)
            * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2));

    Double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    Double d = R * c * 1000;/*ww  w  .j a v  a 2 s . c  o  m*/

    return d;
}

From source file:org.jrman.parser.Parser.java

public void addHyperboloid(final float x1, final float y1, final float z1, final float x2, final float y2,
        final float z2, final float tMax, final ParameterList parameters) {
    if (inAreaLightSource)
        return;//from w w w.j a v  a  2 s.c  o  m

    final float thetaMin = 0f;
    final float thetaMax = (float) Math.toRadians(tMax);
    if (!inObject) {
        renderer.addPrimitive(
                new Hyperboloid(x1, y1, z1, x2, y2, z2, thetaMin, thetaMax, parameters, getAttributes()));
        hyperboloidCount++;
    } else {
        final Transform transform = currentAttributes.getTransform();
        currentObjectInstanceList.addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() {
            public Primitive create(Attributes attributes) {
                hyperboloidCount++;
                return new Hyperboloid(x1, y1, z1, x2, y2, z2, thetaMin, thetaMax, parameters,
                        createAttributes(transform, attributes));
            }
        });
    }

}