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:Matrix.java

/**
 * Create a incline-rotation matrix (incline-rotation is around a (0, 0, 1) axis).
 * @param angle the angle of the rotation
 * @return the matrix/*from w  w w .j a v  a2  s .c  o  m*/
 */
public static float[] matrixRotateIncline(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 m2[] = { cos, sin, 0f, 0f, -sin, cos, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f };
    return m2;
}

From source file:Human1.java

public void setLShoulderRot(int rotation) {
    lShoulderRot = rotation;/*  ww  w . j av a  2s  .  c  om*/
    lShoulderAA.angle = (float) Math.toRadians(lShoulderRot);
    Human_l_shoulder.getTransform(tmpTrans);
    tmpTrans.setRotation(lShoulderAA);
    Human_l_shoulder.setTransform(tmpTrans);
}

From source file:com.skumar.flexibleciruclarseekbar.CircularSeekBar.java

/**
 * Method to draw the needle scale//w  ww  . j a va2  s.co  m
 *
 * @param canvas drawable element
 */
private void drawNeedleMarkings(Canvas canvas) {
    float cx = canvas.getWidth() / 2;
    float cy = canvas.getHeight() / 2;
    float scaleMarkSize = getResources().getDisplayMetrics().density * mNeedleDP;
    int radius = mArcRadius + mNeedleDistance;

    for (float progress = mProgressIncrement; progress < mMax; progress += mProgressIncrement) {
        float progressSweep = progress / mMax * mSweepAngle;
        int thumbAngle = (int) (mStartAngle + progressSweep + mRotation);
        float startX = (float) (cx + radius * Math.sin(Math.toRadians(thumbAngle)));
        float startY = (float) (cy - radius * Math.cos(Math.toRadians(thumbAngle)));

        float stopX = (float) (cx + (radius + scaleMarkSize) * Math.sin(Math.toRadians(thumbAngle)));
        float stopY = (float) (cy - (radius + scaleMarkSize) * Math.cos(Math.toRadians(thumbAngle)));

        if (progress == mMax / 2 && isIncreaseCenter) {
            stopX = (float) (cx
                    + (radius + scaleMarkSize + mIncreaseCenterNeedle) * Math.sin(Math.toRadians(thumbAngle)));
            stopY = (float) (cy
                    - (radius + scaleMarkSize + mIncreaseCenterNeedle) * Math.cos(Math.toRadians(thumbAngle)));
        }
        if (progress >= mMinimumNeedleScale && progress <= mMaximumNeedleScale && mDrawNeedleScaleUp) {
            stopX = (float) (cx
                    + (radius + scaleMarkSize + mIncreaseCenterNeedle) * Math.sin(Math.toRadians(thumbAngle)));
            stopY = (float) (cy
                    - (radius + scaleMarkSize + mIncreaseCenterNeedle) * Math.cos(Math.toRadians(thumbAngle)));
        }
        canvas.drawLine(startX, startY, stopX, stopY, mNeedleScalePaint);
    }
}

From source file:org.owasp.benchmark.score.report.Scatter.java

private XYPointerAnnotation makePointer(int x, int y, String msg, TextAnchor anchor, int angle) {
    XYPointerAnnotation pointer = new XYPointerAnnotation(msg, x, y, Math.toRadians(angle));
    pointer.setBackgroundPaint(Color.white);
    pointer.setTextAnchor(anchor);/*from w w w .  j a v  a  2  s. c  o  m*/
    pointer.setArrowWidth(4);
    pointer.setArrowLength(8);
    pointer.setArrowPaint(Color.red);
    pointer.setLabelOffset(2);
    pointer.setPaint(Color.red);
    pointer.setFont(theme.getRegularFont());
    return pointer;
}

From source file:com.metinkale.prayerapp.compass.Main.java

private double getDirection(double lat1, double lng1, double lat2, double lng2) {
    double dLng = lng1 - lng2;
    return Math.toDegrees(getDirectionRad(Math.toRadians(lat1), Math.toRadians(lat2), Math.toRadians(dLng)));
}

From source file:edu.csun.ecs.cs.multitouchj.ui.control.Control.java

protected boolean isWithinWithRotation(Point position) {
    // topleft, topright, bottomright, bottomleft
    // get points centered at (0, 0)
    Size size = getSize();//from ww w  .j  a  v a  2 s.c o m
    Point[] points = new Point[4];
    points[0] = new Point(-1 * (size.getWidth() / 2.0f), (size.getHeight() / 2.0f));
    points[1] = new Point((size.getWidth() / 2.0f), (size.getHeight() / 2.0f));
    points[2] = new Point((size.getWidth() / 2.0f), -1 * (size.getHeight() / 2.0f));
    points[3] = new Point(-1 * (size.getWidth() / 2.0f), -1 * (size.getHeight() / 2.0f));
    /*
    log.info("Vertices:");
    for(int i = 0; i < points.length; i++) {
    log.info("\t"+points[i].toString());
    }
    */

    // rotate at (0, 0)
    double rotationInDegree = getRotation();
    double rotationInRadian = Math.toRadians(rotationInDegree);
    for (Point point : points) {
        double rotatedX = (point.getX() * Math.cos(rotationInRadian))
                - (point.getY() * Math.sin(rotationInRadian));
        double rotatedY = (point.getX() * Math.sin(rotationInRadian))
                + (point.getY() * Math.cos(rotationInRadian));
        point.set((float) rotatedX, (float) rotatedY);
    }
    /*
    log.info("Rotated Vertices:");
    for(int i = 0; i < points.length; i++) {
    log.info("\t"+points[i].toString());
    }
    */

    // check to see if position is above or below the slope of sides of
    // this rectangle
    DisplayMode displayMode = windowManager.getDisplayManager().getCurrentDisplayMode();
    Point center = getOpenGlPosition();
    Point centeredPosition = OpenGlUtility
            .getOpenGlPosition(new Size(displayMode.getWidth(), displayMode.getHeight()), position);
    //log.info("Position GL: "+centeredPosition.toString());
    centeredPosition.minus(center);
    //log.info("Center: "+center.toString());
    //log.info("Position: "+position.toString());
    //log.info("Centered: "+centeredPosition.toString());

    boolean[] results = new boolean[points.length];
    for (int i = 0; i < points.length; i++) {
        Point target1 = points[i];
        Point target2 = points[((i + 1) % points.length)];
        Point target3 = points[((i + 2) % points.length)];

        double targetValue = (centeredPosition.getY() - target1.getY());
        if (target2.getX() != target1.getX()) {
            targetValue = (centeredPosition.getY() - target1.getY())
                    - ((target2.getY() - target1.getY()) / (target2.getX() - target1.getX()))
                            * (centeredPosition.getX() - target1.getX());
        }
        double testValue = (target3.getY() - target1.getY());
        if (target2.getX() != target1.getX()) {
            testValue = (target3.getY() - target1.getY())
                    - ((target2.getY() - target1.getY()) / (target2.getX() - target1.getX()))
                            * (target3.getX() - target1.getX());
        }
        //log.info("target: "+targetValue+", test: "+testValue);

        results[i] = (targetValue == 0.0);
        if (((targetValue > 0.0) && (testValue > 0.0)) || ((targetValue < 0.0) && (testValue < 0.0))) {
            results[i] = true;
        }
    }
    /*
    log.info("Results:");
    for(int i = 0; i < results.length; i++) {
    log.info("\t"+results[i]);
    }
    */

    boolean isWithin = true;
    for (boolean result : results) {
        if (!result) {
            isWithin = false;
            break;
        }
    }
    /*
    float[] results = new float[points.length];
    for(int i = 0; i < points.length; i++) {
    Point target1 = points[i];
    Point target2 = points[((i + 1) % points.length)];
            
    float targetValue = (centeredPosition.getY() - target1.getY());
    if(target2.getX() != target1.getX()) {
        targetValue = (centeredPosition.getY() - target1.getY()) -
            ((target2.getY() - target1.getY()) / (target2.getX() - target1.getX())) *
            (centeredPosition.getX() - target1.getX());
    }
    results[i] = targetValue;
    }
    log.info("Results:");
    for(int i = 0; i < results.length; i++) {
    log.info("\t"+results[i]);
    }
            
    boolean isWithin = false;
    for(float result : results) {
    if(result == 0.0f) {
        isWithin = true;
        break;
    }
    }
    if(!isWithin) {
    int numberOfAboves = 0;
    for(float result : results) {
        if(result > 0.0f) {
            numberOfAboves += 1;
        }
    }
    if(numberOfAboves == 2) {
        isWithin = true;
    }
    }
    */

    //log.info("isWithin: "+isWithin);

    return isWithin;
}

From source file:jp.co.tweetmap.Fragment0.java

/**
 * Calculates distance of cameras coordinate.
 *
 * @param a old camera position./*w w w.ja  v a 2 s .  c  om*/
 * @param b new camera position.
 */
private double calcDistance(CameraPosition a, CameraPosition b) {
    if (LogUtil.isDebug())
        Log.e(TAG, "### calcDistance() ###");
    double lata = Math.toRadians(a.target.latitude);
    double lnga = Math.toRadians(a.target.longitude);

    double latb = Math.toRadians(b.target.latitude);
    double lngb = Math.toRadians(b.target.longitude);

    return MapUtil.EQUATORIAL_RADIUS * Math
            .acos(Math.sin(lata) * Math.sin(latb) + Math.cos(lata) * Math.cos(latb) * Math.cos(lngb - lnga));
}

From source file:Human1.java

public void setLElbowRot(int rotation) {
    float angle = (float) Math.toRadians(rotation);
    lElbowRot = rotation;/*from  w  w  w  .  j  av  a2s  .c o m*/
    lElbowAA.angle = (float) Math.toRadians(lElbowRot);
    Human_l_elbow.getTransform(tmpTrans);
    tmpTrans.setRotation(lElbowAA);
    Human_l_elbow.setTransform(tmpTrans);
}

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

public void rotate(float angle, float dx, float dy, float dz) {
    AxisAngle4f axisAngle = new AxisAngle4f(dx, dy, dz, (float) Math.toRadians(angle));
    Matrix4f rotation = new Matrix4f();
    rotation.setIdentity();//from ww w.  j a  v  a  2  s .  c om
    rotation.set(axisAngle);
    concatTransform(rotation);
}

From source file:wa.was.blastradius.managers.TNTEffectsManager.java

public List<Location> getRandomLocation(Location center, int radius, int amount) {
    Random rand = new Random();
    List<Location> locations = new ArrayList<Location>();
    for (int i = 1; i <= amount; i++) {
        double angle = rand.nextDouble() * 360;
        double x = center.getX() + (rand.nextDouble() * radius * Math.cos(Math.toRadians(angle)));
        double y = center.getY() + (rand.nextDouble() * radius * Math.cos(Math.toRadians(angle)));
        double z = center.getZ() + (rand.nextDouble() * radius * Math.sin(Math.toRadians(angle)));
        Location relLoc = new Location(center.getWorld(), x, y, z);
        Location location = center.getWorld().getHighestBlockAt(relLoc).getLocation();
        locations.add(location);/*  w w w  .  ja  v a 2s  .com*/
    }
    return locations;
}