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.aidy.launcher3.photos.views.TiledImageRenderer.java

private void getRange(Rect out, int cX, int cY, int level, float scale, int rotation) {

    double radians = Math.toRadians(-rotation);
    double w = mViewWidth;
    double h = mViewHeight;

    double cos = Math.cos(radians);
    double sin = Math.sin(radians);
    int width = (int) Math.ceil(Math.max(Math.abs(cos * w - sin * h), Math.abs(cos * w + sin * h)));
    int height = (int) Math.ceil(Math.max(Math.abs(sin * w + cos * h), Math.abs(sin * w - cos * h)));

    int left = (int) Math.floor(cX - width / (2f * scale));
    int top = (int) Math.floor(cY - height / (2f * scale));
    int right = (int) Math.ceil(left + width / scale);
    int bottom = (int) Math.ceil(top + height / scale);

    // align the rectangle to tile boundary
    int size = mTileSize << level;
    left = Math.max(0, size * (left / size));
    top = Math.max(0, size * (top / size));
    right = Math.min(mImageWidth, right);
    bottom = Math.min(mImageHeight, bottom);

    out.set(left, top, right, bottom);/* ww  w  .  j a v  a2  s.c  o  m*/
}

From source file:at.gv.egiz.pdfas.lib.impl.pdfbox.placeholder.SignaturePlaceholderExtractor.java

@Override
protected void processOperator(PDFOperator operator, List<COSBase> arguments) throws IOException {
    String operation = operator.getOperation();
    if (operation.equals("Do")) {
        COSName objectName = (COSName) arguments.get(0);
        Map<?, ?> xobjects = getResources().getXObjects();
        PDXObject xobject = (PDXObject) xobjects.get(objectName.getName());
        if (xobject instanceof PDXObjectImage) {
            try {
                PDXObjectImage image = (PDXObjectImage) xobject;
                SignaturePlaceholderData data = checkImage(image);
                if (data != null) {
                    PDPage page = getCurrentPage();
                    Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
                    int pageRotation = page.findRotation();
                    pageRotation = pageRotation % 360;
                    double rotationInRadians = Math.toRadians(pageRotation);//(page.findRotation() * Math.PI) / 180;

                    AffineTransform rotation = new AffineTransform();
                    rotation.setToRotation(rotationInRadians);
                    AffineTransform rotationInverse = rotation.createInverse();
                    Matrix rotationInverseMatrix = new Matrix();
                    rotationInverseMatrix.setFromAffineTransform(rotationInverse);
                    Matrix rotationMatrix = new Matrix();
                    rotationMatrix.setFromAffineTransform(rotation);

                    Matrix unrotatedCTM = ctm.multiply(rotationInverseMatrix);

                    float x = unrotatedCTM.getXPosition();
                    float yPos = unrotatedCTM.getYPosition();
                    float yScale = unrotatedCTM.getYScale();
                    float y = yPos + yScale;
                    float w = unrotatedCTM.getXScale();

                    logger.debug("Page height: {}", page.findCropBox().getHeight());
                    logger.debug("Page width: {}", page.findCropBox().getWidth());

                    if (pageRotation == 90) {
                        y = page.findCropBox().getWidth() - (y * (-1));
                    } else if (pageRotation == 180) {
                        x = page.findCropBox().getWidth() + x;
                        y = page.findCropBox().getHeight() - (y * (-1));
                    } else if (pageRotation == 270) {
                        x = page.findCropBox().getHeight() + x;
                    }//from   w  w  w. j  a v a  2  s .  co  m

                    String posString = "p:" + currentPage + ";x:" + x + ";y:" + y + ";w:" + w;

                    logger.debug("Found Placeholder at: {}", posString);
                    try {
                        data.setTablePos(new TablePos(posString));
                        data.setPlaceholderName(objectName.getName());
                        placeholders.add(data);
                    } catch (PdfAsException e) {
                        throw new WrappedIOException(e);
                    }
                }
            } catch (NoninvertibleTransformException e) {
                throw new WrappedIOException(e);
            }
        }
    } else {
        super.processOperator(operator, arguments);
    }
}

From source file:chat.client.gui.ChatActivity.java

private static double getDistance(double lat1, double lon1, double lat2, double lon2) {
    final double Radius = 6371 * 1E3; // Earth's mean radius
    double dLat = Math.toRadians(lat2 - lat1);
    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 Radius * c;
}

From source file:Matrix.java

/**
 * Incline a matrix (incline-rotation is around a (0, 0, 1) axis).
 * @param angle the angle of the rotation
 * @param m the matrix to rotate/*from  w w w  . j  av  a  2 s.  com*/
 * @return the resulting matrix 
 */
public static float[] matrixRotateIncline(float[] m, float angle) {
    if (angle == 0f)
        return matrixIdentity();
    angle = (float) Math.toRadians(angle);
    float cos = (float) java.lang.Math.cos(angle);
    float sin = (float) java.lang.Math.sin(angle);
    float r[] = new float[16];
    r[0] = m[0] * cos - m[1] * sin;
    r[4] = m[4] * cos - m[5] * sin;
    r[8] = m[8] * cos - m[9] * sin;
    r[12] = m[12] * cos - m[13] * sin;
    r[1] = m[0] * sin + m[1] * cos;
    r[5] = m[4] * sin + m[5] * cos;
    r[9] = m[8] * sin + m[9] * cos;
    r[13] = m[12] * sin + m[13] * cos;
    r[2] = m[2];
    r[6] = m[6];
    r[10] = m[10];
    r[14] = m[14];
    r[3] = 0;
    r[7] = 0;
    r[11] = 0;
    r[15] = 1;
    return r;
    //    return matrixMultiply(matrixRotateIncline(angle), m);
}

From source file:com.example.brendan.learningandroid2.SeekArc.java

private void updateThumbPosition() {
    int thumbAngle = (int) (mStartAngle + mProgressSweep + mRotation + 90);
    mThumbXPos = (int) (mArcRadius * Math.cos(Math.toRadians(thumbAngle)));
    mThumbYPos = (int) (mArcRadius * Math.sin(Math.toRadians(thumbAngle)));
}

From source file:android.wuliqing.com.mylibrary.header.MaterialProgressDrawable.java

private void setupAnimators() {
    final Ring ring = mRing;
    final Animation finishRingAnimation = new Animation() {
        public void applyTransformation(float interpolatedTime, Transformation t) {
            // shrink back down and complete a full rotation before starting other circles
            // Rotation goes between [0..1].
            float targetRotation = (float) (Math.floor(ring.getStartingRotation() / MAX_PROGRESS_ARC) + 1f);
            final float startTrim = ring.getStartingStartTrim()
                    + (ring.getStartingEndTrim() - ring.getStartingStartTrim()) * interpolatedTime;
            ring.setStartTrim(startTrim);
            final float rotation = ring.getStartingRotation()
                    + ((targetRotation - ring.getStartingRotation()) * interpolatedTime);
            ring.setRotation(rotation);/*  w  w  w  .  ja  v  a 2s .  c  o m*/
            ring.setArrowScale(1 - interpolatedTime);
        }
    };
    finishRingAnimation.setInterpolator(EASE_INTERPOLATOR);
    finishRingAnimation.setDuration(ANIMATION_DURATION / 2);
    finishRingAnimation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            ring.goToNextColor();
            ring.storeOriginals();
            ring.setShowArrow(false);
            mParent.startAnimation(mAnimation);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
    final Animation animation = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            // The minProgressArc is calculated from 0 to create an angle that
            // matches the stroke width.
            final float minProgressArc = (float) Math
                    .toRadians(ring.getStrokeWidth() / (2 * Math.PI * ring.getCenterRadius()));
            final float startingEndTrim = ring.getStartingEndTrim();
            final float startingTrim = ring.getStartingStartTrim();
            final float startingRotation = ring.getStartingRotation();
            // Offset the minProgressArc to where the endTrim is located.
            final float minArc = MAX_PROGRESS_ARC - minProgressArc;
            final float endTrim = startingEndTrim
                    + (minArc * START_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime));
            ring.setEndTrim(endTrim);
            final float startTrim = startingTrim
                    + (MAX_PROGRESS_ARC * END_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime));
            ring.setStartTrim(startTrim);
            final float rotation = startingRotation + (0.25f * interpolatedTime);
            ring.setRotation(rotation);
            float groupRotation = ((720.0f / NUM_POINTS) * interpolatedTime)
                    + (720.0f * (mRotationCount / NUM_POINTS));
            setRotation(groupRotation);
        }
    };
    animation.setRepeatCount(Animation.INFINITE);
    animation.setRepeatMode(Animation.RESTART);
    animation.setInterpolator(LINEAR_INTERPOLATOR);
    animation.setDuration(ANIMATION_DURATION);
    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            mRotationCount = 0;
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // do nothing
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            ring.storeOriginals();
            ring.goToNextColor();
            ring.setStartTrim(ring.getEndTrim());
            mRotationCount = (mRotationCount + 1) % (NUM_POINTS);
        }
    });
    mFinishAnimation = finishRingAnimation;
    mAnimation = animation;
}

From source file:cn.xiaocool.hongyunschool.view.MaterialProgressDrawable.java

private void setupAnimators() {
    final Ring ring = mRing;
    final Animation finishRingAnimation = new Animation() {
        public void applyTransformation(float interpolatedTime, Transformation t) {
            // shrink back down and complete a full rotation before starting
            // other circles
            // Rotation goes between [0..1].
            float targetRotation = (float) (Math.floor(ring.getStartingRotation() / MAX_PROGRESS_ARC) + 1f);
            final float startTrim = ring.getStartingStartTrim()
                    + (ring.getStartingEndTrim() - ring.getStartingStartTrim()) * interpolatedTime;
            ring.setStartTrim(startTrim);
            final float rotation = ring.getStartingRotation()
                    + ((targetRotation - ring.getStartingRotation()) * interpolatedTime);
            ring.setRotation(rotation);/*from   w w  w .  ja v a  2 s  .co m*/
            ring.setArrowScale(1 - interpolatedTime);
        }
    };
    finishRingAnimation.setInterpolator(EASE_INTERPOLATOR);
    finishRingAnimation.setDuration(ANIMATION_DURATION / 2);
    finishRingAnimation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            ring.goToNextColor();
            ring.storeOriginals();
            ring.setShowArrow(false);
            mParent.startAnimation(mAnimation);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    });
    final Animation animation = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            // The minProgressArc is calculated from 0 to create an angle
            // that
            // matches the stroke width.
            final float minProgressArc = (float) Math
                    .toRadians(ring.getStrokeWidth() / (2 * Math.PI * ring.getCenterRadius()));
            final float startingEndTrim = ring.getStartingEndTrim();
            final float startingTrim = ring.getStartingStartTrim();
            final float startingRotation = ring.getStartingRotation();
            // Offset the minProgressArc to where the endTrim is located.
            final float minArc = MAX_PROGRESS_ARC - minProgressArc;
            final float endTrim = startingEndTrim
                    + (minArc * START_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime));
            ring.setEndTrim(endTrim);
            final float startTrim = startingTrim
                    + (MAX_PROGRESS_ARC * END_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime));
            ring.setStartTrim(startTrim);
            final float rotation = startingRotation + (0.25f * interpolatedTime);
            ring.setRotation(rotation);
            float groupRotation = ((720.0f / NUM_POINTS) * interpolatedTime)
                    + (720.0f * (mRotationCount / NUM_POINTS));
            setRotation(groupRotation);
        }
    };
    animation.setRepeatCount(Animation.INFINITE);
    animation.setRepeatMode(Animation.RESTART);
    animation.setInterpolator(LINEAR_INTERPOLATOR);
    animation.setDuration(ANIMATION_DURATION);
    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            mRotationCount = 0;
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // do nothing
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            ring.storeOriginals();
            ring.goToNextColor();
            ring.setStartTrim(ring.getEndTrim());
            mRotationCount = (mRotationCount + 1) % (NUM_POINTS);
        }
    });
    mFinishAnimation = finishRingAnimation;
    mAnimation = animation;
}

From source file:nz.co.fortytwo.signalk.util.Util.java

public static double haversineMeters(double lat, double lon, double anchorLat, double anchorLon) {
    double dLat = Math.toRadians(anchorLat - lat);
    double dLon = Math.toRadians(anchorLon - lon);
    lat = Math.toRadians(lat);/* w w w .java2s.com*/
    anchorLat = Math.toRadians(anchorLat);

    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
            + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat) * Math.cos(anchorLat);
    double c = 2 * Math.asin(Math.sqrt(a));
    return R * c;
}

From source file:com.sketchy.image.ImageProcessingThread.java

public static BufferedImage rotateImage(BufferedImage image, RotateOption rotateOption) {

    if (rotateOption == RotateOption.ROTATE_NONE)
        return image;

    int degrees = 0;
    int imageWidth = image.getWidth();
    int imageHeight = image.getHeight();

    BufferedImage rotatedImage = null;
    if (rotateOption == RotateOption.ROTATE_90) {
        degrees = 90;// w w w  .java  2s .  c  om
        rotatedImage = new BufferedImage(imageHeight, imageWidth, BufferedImage.TYPE_INT_ARGB);
    } else if (rotateOption == RotateOption.ROTATE_180) {
        degrees = 180;
        rotatedImage = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB);
    } else if (rotateOption == RotateOption.ROTATE_270) {
        degrees = 270;
        rotatedImage = new BufferedImage(imageHeight, imageWidth, BufferedImage.TYPE_INT_ARGB);
    }

    Graphics2D g = rotatedImage.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

    g.rotate(Math.toRadians(degrees), 0, 0);

    if (degrees == 90) {
        g.drawImage(image, null, 0, -imageHeight);
    } else if (degrees == 180) {
        g.drawImage(image, null, -imageWidth, -imageHeight);
    } else if (degrees == 270) {
        g.drawImage(image, null, -imageWidth, 0);
    }
    g.dispose();
    return rotatedImage;
}

From source file:Matrix.java

/**
 * Create a rotation matrix./*  w w  w.  j a  v  a2  s.co  m*/
 * @param angle the angle of the rotation
 * @param x the x coordinate of the rotation axis
 * @param y the y coordinate of the rotation axis
 * @param z the z coordinate of the rotation axis
 * @return the matrix
 */
public static float[] matrixRotate(float angle, float x, float y, float z) {
    if (angle == 0f)
        return matrixIdentity();
    angle = (float) Math.toRadians(angle);
    float d = (float) java.lang.Math
            .sqrt(java.lang.Math.pow(x, 2) + java.lang.Math.pow(y, 2) + java.lang.Math.pow(z, 2));
    if (d != 1f) {
        x = x / d;
        y = y / d;
        z = z / d;
    }
    float cos = (float) java.lang.Math.cos(angle);
    float sin = (float) java.lang.Math.sin(angle);
    float co1 = 1f - cos;
    float m2[] = { x * x * co1 + cos, y * x * co1 + z * sin, z * x * co1 - y * sin, 0f, x * y * co1 - z * sin,
            y * y * co1 + cos, z * y * co1 + x * sin, 0f, x * z * co1 + y * sin, y * z * co1 - x * sin,
            z * z * co1 + cos, 0f, 0f, 0f, 0f, 1f };
    return m2;
}