Example usage for java.lang Math toDegrees

List of usage examples for java.lang Math toDegrees

Introduction

In this page you can find the example usage for java.lang Math toDegrees.

Prototype

public static double toDegrees(double angrad) 

Source Link

Document

Converts an angle measured in radians to an approximately equivalent angle measured in degrees.

Usage

From source file:org.kuali.coeus.common.impl.print.watermark.WatermarkServiceImpl.java

/**
 * This method is for setting the properties of watermark Text.
 *///ww w  .  j  a v a 2  s  . c om
private void decoratePdfWatermarkText(PdfContentByte pdfContentByte, Rectangle rectangle,
        WatermarkBean watermarkBean) {
    float x, y, x1, y1, angle;
    final float OPACITY = 0.3f;
    PdfGState pdfGState = new PdfGState();
    pdfGState.setFillOpacity(OPACITY);
    int pageWidth = (int) rectangle.getWidth();
    int pageHeight = (int) rectangle.getHeight();
    try {
        if (watermarkBean.getType().equalsIgnoreCase(WatermarkConstants.WATERMARK_TYPE_TEXT)) {
            pdfContentByte.beginText();
            pdfContentByte.setGState(pdfGState);
            Color fillColor = watermarkBean.getFont().getColor() == null
                    ? WatermarkConstants.DEFAULT_WATERMARK_COLOR
                    : watermarkBean.getFont().getColor();
            pdfContentByte.setColorFill(fillColor);

            if (watermarkBean.getPosition().equals(WatermarkConstants.WATERMARK_POSITION_FOOTER)) {

                pdfContentByte.setFontAndSize(watermarkBean.getFont().getBaseFont(),
                        watermarkBean.getPositionFont().getSize());
                if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_CENTER)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_CENTER, watermarkBean.getText(),
                            (rectangle.getLeft(rectangle.getBorderWidthLeft())
                                    + rectangle.getRight(rectangle.getBorderWidthRight())) / 2,
                            rectangle.getBottom(rectangle.getBorderWidthBottom()
                                    + watermarkBean.getPositionFont().getSize()),
                            0);
                } else if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_RIGHT)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_RIGHT, watermarkBean.getText(),
                            rectangle.getRight(rectangle.getBorderWidthRight()),
                            rectangle.getBottom(rectangle.getBorderWidthBottom()
                                    + watermarkBean.getPositionFont().getSize()),
                            0);
                } else if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_LEFT)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_LEFT, watermarkBean.getText(),
                            rectangle.getLeft(rectangle.getBorderWidthLeft()),
                            rectangle.getBottom(rectangle.getBorderWidthBottom()
                                    + watermarkBean.getPositionFont().getSize()),
                            0);
                }
            } else if (watermarkBean.getPosition().equals(WatermarkConstants.WATERMARK_POSITION_HEADER)) {
                pdfContentByte.setFontAndSize(watermarkBean.getFont().getBaseFont(),
                        watermarkBean.getPositionFont().getSize());
                if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_CENTER)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_CENTER, watermarkBean.getText(),
                            (rectangle.getLeft(rectangle.getBorderWidthLeft())
                                    + rectangle.getRight(rectangle.getBorderWidthRight())) / 2,
                            rectangle.getTop(
                                    rectangle.getBorderWidthTop() + watermarkBean.getPositionFont().getSize()),
                            0);
                } else if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_RIGHT)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_RIGHT, watermarkBean.getText(),
                            rectangle.getRight(rectangle.getBorderWidthRight()),
                            rectangle.getTop(
                                    rectangle.getBorderWidthTop() + watermarkBean.getPositionFont().getSize()),
                            0);
                } else if (watermarkBean.getAlignment().equals(WatermarkConstants.ALIGN_LEFT)) {
                    pdfContentByte.showTextAligned(Element.ALIGN_LEFT, watermarkBean.getText(),
                            rectangle.getLeft(rectangle.getBorderWidthLeft()),
                            rectangle.getTop(
                                    rectangle.getBorderWidthTop() + watermarkBean.getPositionFont().getSize()),
                            0);
                }
            } else {
                pdfContentByte.setFontAndSize(watermarkBean.getFont().getBaseFont(),
                        watermarkBean.getFont().getSize());
                int textWidth = (int) pdfContentByte.getEffectiveStringWidth(watermarkBean.getText(), false);
                int diagonal = (int) Math.sqrt((pageWidth * pageWidth) + (pageHeight * pageHeight));
                int pivotPoint = (diagonal - textWidth) / 2;

                angle = (float) Math.atan((float) pageHeight / pageWidth);

                x = (float) (pivotPoint * pageWidth) / diagonal;
                y = (float) (pivotPoint * pageHeight) / diagonal;

                x1 = (float) (((float) watermarkBean.getFont().getSize() / 2) * Math.sin(angle));
                y1 = (float) (((float) watermarkBean.getFont().getSize() / 2) * Math.cos(angle));

                pdfContentByte.showTextAligned(Element.ALIGN_LEFT, watermarkBean.getText(), x + x1, y - y1,
                        (float) Math.toDegrees(angle));
            }
            pdfContentByte.endText();
        }
    } catch (Exception exception) {
        LOG.error("Exception occured in WatermarkServiceImpl. Water mark Exception: " + exception.getMessage());
    }

}

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

private double getTouchDegrees(float xPos, float yPos) {
    float x = xPos - mTranslateX;
    float y = yPos - mTranslateY;
    //invert the x-coord if we are rotating anti-clockwise
    x = (mClockwise) ? x : -x;/*  w w  w  .  j av  a  2s . c  o m*/
    // convert to arc Angle
    double angle = Math.toDegrees(Math.atan2(y, x) + (Math.PI / 2) - Math.toRadians(mRotation));
    if (angle < 0) {
        angle = 360 + angle;
    }
    angle -= mStartAngle;
    return angle;
}

From source file:org.mwc.debrief.sensorfusion.views.DataSupport.java

/**
 * Deletes all blocks of sensor data that are more than 45 degrees from an
 * secondary track./*from w w w .j a v a  2 s  . c  om*/
 * 
 * @return
 */
public static ArrayList<SensorWrapper> trimToSensorNearSubjectTracks(final TrackWrapper primary,
        final WatchableList[] secondaries) {
    ArrayList<SensorWrapper> toRemove = new ArrayList<SensorWrapper>();
    ArrayList<SensorWrapper> toKeep = new ArrayList<SensorWrapper>();

    if (primary == null || secondaries == null)
        return toRemove;

    Enumeration<Editable> sensors = primary.getSensors().elements();
    while (sensors.hasMoreElements()) {
        SensorWrapper sensor = (SensorWrapper) sensors.nextElement();

        // ok, remember this one
        toRemove.add(sensor);

        final Enumeration<Editable> contacts = sensor.elements();
        // loop though the individual sensor contact objects
        while (sensor != null && (contacts.hasMoreElements())) {
            final SensorContactWrapper contact = (SensorContactWrapper) contacts.nextElement();
            // check this sensor contact has a bearing
            if (!contact.getHasBearing()) {
                // hey, no bearing - we aren't sufficiently able to decide if
                // it can be ditched.
                toKeep.add(sensor);
                sensor = null;
            } else {
                final HiResDate contactTime = contact.getDTG();
                // loop through each secondary track
                for (int i = 0; i < secondaries.length; i++) {
                    final WatchableList thisS = secondaries[i];

                    final Watchable[] secondaryFixes = thisS.getNearestTo(contactTime);
                    final Watchable[] primaryFixes = primary.getNearestTo(contactTime);
                    double bearing = 0;
                    if (secondaryFixes != null && secondaryFixes.length > 0) {
                        if (primaryFixes != null && primaryFixes.length > 0) {
                            WorldLocation wl1 = secondaryFixes[0].getLocation();
                            WorldLocation wl2 = primaryFixes[0].getLocation();
                            bearing = wl1.bearingFrom(wl2);
                        }
                    }

                    double bearingDelta = contact.getBearing() - Math.toDegrees(bearing);
                    if (Math.abs(bearingDelta) < THRESHOLD_FOR_IRRELEVANT_DATA) {
                        // ok, this sensor is relevant
                        toKeep.add(sensor);

                        // now clear the sensor, as a marker to move on to the next
                        // sensor
                        sensor = null;
                    }
                }

            }
        } // end loop through sensor contacts
    }

    // ok, we've built up a list of sensors to keep. We now need to get rid of
    // the other ones
    Iterator<SensorWrapper> keepers = toKeep.iterator();
    while (keepers.hasNext()) {
        SensorWrapper keepMe = (SensorWrapper) keepers.next();
        toRemove.remove(keepMe);
    }

    return toRemove;
}

From source file:com.facebook.presto.operator.scalar.MathFunctions.java

@Description("converts an angle in radians to degrees")
@ScalarFunction//from   www  . j av  a 2 s .com
@SqlType(StandardTypes.DOUBLE)
public static double degrees(@SqlType(StandardTypes.DOUBLE) double radians) {
    return Math.toDegrees(radians);
}

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:com.cubic9.android.droidglove.Main.java

@Override
public void onSensorChanged(SensorEvent event) {
    Float[] avgAngles = new Float[3];
    float[] rotationMatrix = new float[9];
    float[] attitude = new float[3];

    switch (event.sensor.getType()) {
    case Sensor.TYPE_MAGNETIC_FIELD:
        geomagnetic = event.values.clone();
        break;//from  w  ww  .  ja  v a  2  s.c o m
    case Sensor.TYPE_ACCELEROMETER:
        gravity = event.values.clone();
        break;
    }

    if (geomagnetic != null && gravity != null) {
        SensorManager.getRotationMatrix(rotationMatrix, null, gravity, geomagnetic);
        SensorManager.getOrientation(rotationMatrix, attitude);

        if (!mInitirizedSensor) {
            if (mCountBeforeInit > 20) {
                mInitirizedSensor = true;
                initYaw = (float) Math.toDegrees(attitude[0]);
            } else {
                mCountBeforeInit++;
            }
        }

        for (int i = 0; i < 3; i++) {
            for (int j = AVERAGE_AMOUNT - 1; j > 0; j--) {
                mOrigAngles[i][j] = mOrigAngles[i][j - 1];
            }
        }

        mOrigAngles[0][0] = (float) Math.toDegrees(attitude[0]) - initYaw;
        mOrigAngles[1][0] = (float) Math.toDegrees(attitude[1]);
        mOrigAngles[2][0] = (float) Math.toDegrees(attitude[2]);

        for (int i = 0; i < 3; i++) {
            avgAngles[i] = 0f;
            for (int j = 0; j < AVERAGE_AMOUNT; j++) {
                avgAngles[i] += mOrigAngles[i][j];
            }
            avgAngles[i] /= AVERAGE_AMOUNT;
        }

        /*
         * textViewX.setText(avgAngles[0].toString());
         * textViewY.setText(avgAngles[1].toString());
         * textViewZ.setText(avgAngles[2].toString());
         * textViewGrip.setText(Float.toString(mYDiff));
         */

        // create message for send
        List<Object> valueList = new ArrayList<Object>();
        valueList.add(avgAngles[1]);
        valueList.add(avgAngles[0]);
        valueList.add(-avgAngles[2]);
        valueList.add(Integer.valueOf((int) mYDiff));
        OSCMessage message = new OSCMessage(OSC_ADDRESS_TO_PC, valueList);

        // send
        try {
            mSender.send(message);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.javadog.cgeowear.WearService.java

/**
 * Handles compass rotation./*from  w w w.j  a va2 s  . c  om*/
 */
@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        gravity = event.values.clone();
    } else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        geomagnetic = event.values.clone();
    }

    if (gravity != null && geomagnetic != null) {
        float[] R = new float[9];
        float[] I = new float[9];

        boolean success = SensorManager.getRotationMatrix(R, I, gravity, geomagnetic);
        if (success) {
            float[] orientation = new float[3];
            SensorManager.getOrientation(R, orientation);
            float azimuth = (float) Math.toDegrees(orientation[0]);
            float pitch = (float) Math.toDegrees(orientation[1]);

            if (currentLocation != null) {
                float smoothedLatitude = smoothSensorValues(oldLatitude, (float) currentLocation.getLatitude(),
                        1 / 3f);
                float smoothedLongitude = smoothSensorValues(oldLongitude,
                        (float) currentLocation.getLongitude(), 1 / 3f);
                float smoothedAltitude = smoothSensorValues(oldAltitude, (float) currentLocation.getAltitude(),
                        1 / 3f);

                GeomagneticField geomagneticField = new GeomagneticField(smoothedLatitude, smoothedLongitude,
                        smoothedAltitude, System.currentTimeMillis());
                azimuth += geomagneticField.getDeclination();

                float bearing = currentLocation.bearingTo(geocacheLocation);

                float direction = smoothSensorValues(oldDirection, -(azimuth - bearing), 1 / 5f);

                //If the user puts the phone in his/her pocket upside-down, invert the compass
                if (pitch > 0) {
                    direction += 180f;
                }

                //Set old values to current values (for smoothing)
                oldDirection = direction;
                oldLatitude = smoothedLatitude;
                oldLongitude = smoothedLongitude;
                oldAltitude = smoothedAltitude;

                //Send direction update to Android Wear if update interval has passed
                long currentTime = System.currentTimeMillis();
                if ((currentTime - prevTime) > DIRECTION_UPDATE_SPEED) {
                    wearInterface.sendDirectionUpdate(direction);
                    prevTime = currentTime;
                }
            }
        }
    }
}

From source file:ffx.potential.bonded.ImproperTorsion.java

/**
 * Evaluate this Improper Torsion energy.
 *
 * @param gradient Evaluate the gradient.
 * @param threadID//  w  w w. j a va 2 s .c  om
 * @param gradX
 * @param gradY
 * @param gradZ
 * @return Returns the energy.
 */
@Override
public double energy(boolean gradient, int threadID, AtomicDoubleArray gradX, AtomicDoubleArray gradY,
        AtomicDoubleArray gradZ, AtomicDoubleArray lambdaGradX, AtomicDoubleArray lambdaGradY,
        AtomicDoubleArray lambdaGradZ) {

    double a0[] = new double[3];
    double a1[] = new double[3];
    double a2[] = new double[3];
    double a3[] = new double[3];
    /**
     * Vector from Atom 1 to Atom 0.
     */
    double v10[] = new double[3];
    /**
     * Vector from Atom 2 to Atom 1.
     */
    double v21[] = new double[3];
    /**
     * Vector from Atom 3 to Atom 2.
     */
    double v32[] = new double[3];
    /**
     * Vector from Atom 3 to Atom 1.
     */
    double v31[] = new double[3];
    /**
     * Vector from Atom 2 to Atom 0.
     */
    double v20[] = new double[3];
    double t[] = new double[3];
    double u[] = new double[3];
    double tu[] = new double[3];
    double dedu[] = new double[3];
    double dedt[] = new double[3];
    /**
     * Gradient on atoms 0, 1, 2 & 3.
     */
    double g0[] = new double[3];
    double g1[] = new double[3];
    double g2[] = new double[3];
    double g3[] = new double[3];
    /**
     * Work arrays.
     */
    double g1a[] = new double[3];
    double g2a[] = new double[3];

    energy = 0.0;
    value = 0.0;
    atoms[0].getXYZ(a0);
    atoms[1].getXYZ(a1);
    atoms[2].getXYZ(a2);
    atoms[3].getXYZ(a3);
    diff(a1, a0, v10);
    diff(a2, a1, v21);
    diff(a3, a2, v32);
    cross(v10, v21, t);
    cross(v21, v32, u);
    cross(t, u, tu);
    double rt2 = dot(t, t);
    double ru2 = dot(u, u);
    double rtru = sqrt(rt2 * ru2);
    if (rtru != 0.0) {

        /* Set the improper torsional parameters for this angle */
        //double v1 = 0.0;
        //double c1 = 0.0;
        //double s1 = 0.0;
        double v2 = improperType.k;
        double c2 = improperType.cos;
        double s2 = improperType.sin;
        //double v3 = 0.0;
        // double c3 = 0.0;
        // double s3 = 0.0;

        /* compute the multiple angle trigonometry and the phase terms */
        double rcb = r(v21);
        double cosine = dot(t, u) / rtru;
        double sine = dot(v21, tu) / (rcb * rtru);
        double cosine2 = cosine * cosine - sine * sine;
        double sine2 = 2.0 * cosine * sine;
        //double cosine3 = cosine * cosine2 - sine * sine2;
        //double sine3 = cosine * sine2 + sine * cosine2;
        //double phi1 = 1.0 + (cosine * c1 + sine * s1);
        double phi2 = 1.0 + (cosine2 * c2 + sine2 * s2);
        //double phi3 = 1.0 + (cosine3 * c3 + sine3 * s3);
        //double dphi1 = (cosine * s1 - sine * c1);
        double dphi2 = 2.0 * (cosine2 * s2 - sine2 * c2);
        //double dphi3 = 3.0 * (cosine3 * s3 - sine3 * c3);

        /* calculate improper torsion energy and master chain rule term */
        value = Math.toDegrees(Math.acos(cosine));
        //energy = ImproperTorsionType.units * (v1 * phi1 + v2 * phi2 + v3 * phi3);
        //double dedphi = ImproperTorsionType.units * (v1 * dphi1 + v2 * dphi2 + v3 * dphi3);
        final double desvPrefactor = units * scaleFactor;
        final double prefactor = units * scaleFactor * esvLambda;
        energy = prefactor * (v2 * phi2);
        double dedphi = prefactor * (v2 * dphi2);
        if (esvTerm) {
            setEsvDeriv(desvPrefactor * (v2 * phi2) * dedesvChain);
        }

        if (gradient) {
            /**
             * Chain rule terms for first derivative components.
             */
            diff(a2, a0, v20);
            diff(a3, a1, v31);
            cross(t, v21, dedt);
            cross(u, v21, dedu);
            scalar(dedt, dedphi / (rt2 * rcb), dedt);
            scalar(dedu, -dedphi / (ru2 * rcb), dedu);
            /**
             * Compute first derivative components for this angle.
             */
            cross(dedt, v21, g0);
            cross(dedt, v20, g1a);
            cross(dedu, v32, g1);
            scalar(g1a, -1.0, g1a);
            sum(g1a, g1, g1);
            cross(dedt, v10, g2a);
            cross(dedu, v31, g2);
            scalar(g2, -1.0, g2);
            sum(g2a, g2, g2);
            cross(dedu, v21, g3);
            /**
             * Accumulate derivatives.
             */
            // atoms[0].addToXYZGradient(g0[0], g0[1], g0[2]);
            // atoms[1].addToXYZGradient(g1[0], g1[1], g1[2]);
            // atoms[2].addToXYZGradient(g2[0], g2[1], g2[2]);
            // atoms[3].addToXYZGradient(g3[0], g3[1], g3[2]);
            int i0 = atoms[0].getXYZIndex() - 1;
            gradX.add(threadID, i0, g0[0]);
            gradY.add(threadID, i0, g0[1]);
            gradZ.add(threadID, i0, g0[2]);
            int i1 = atoms[1].getXYZIndex() - 1;
            gradX.add(threadID, i1, g1[0]);
            gradY.add(threadID, i1, g1[1]);
            gradZ.add(threadID, i1, g1[2]);
            int i2 = atoms[2].getXYZIndex() - 1;
            gradX.add(threadID, i2, g2[0]);
            gradY.add(threadID, i2, g2[1]);
            gradZ.add(threadID, i2, g2[2]);
            int i3 = atoms[3].getXYZIndex() - 1;
            gradX.add(threadID, i3, g3[0]);
            gradY.add(threadID, i3, g3[1]);
            gradZ.add(threadID, i3, g3[2]);
        }
    }

    // log();
    return energy;
}

From source file:org.gearvrf.keyboard.util.Util.java

public static float getZRotationAngle(GVRSceneObject rotatingObject, GVRTransform targetObject) {
    float angle = (float) Math
            .toDegrees(Math.atan2(targetObject.getPositionY() - rotatingObject.getTransform().getPositionY(),
                    targetObject.getPositionX() - rotatingObject.getTransform().getPositionX()));

    return angle;
}