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:org.squidy.designer.zoom.impl.VisualizationShape.java

/**
 * @param paintContext//from   w ww . jav  a2s . co  m
 */
protected void paintNodeLabels(PPaintContext paintContext) {

    Graphics2D g = paintContext.getGraphics();

    g.setFont(g.getFont().deriveFont(18f));
    FontMetrics fm = g.getFontMetrics();

    PBounds bounds = getBoundsReference();
    double width = bounds.getWidth();
    double height = bounds.getHeight();

    String inputName = pipeShape.getSource().getTitle();
    rotation270.setToRotation(Math.toRadians(270));
    paintContext.pushTransform(rotation270);
    g.setColor(Color.WHITE);
    g.drawString(inputName, (int) -((height / 2) + (FontUtils.getWidthOfText(fm, inputName) / 2)), -25);
    paintContext.popTransform(rotation270);

    String outputName = pipeShape.getTarget().getTitle();
    rotation90.setToRotation(Math.toRadians(90));
    paintContext.pushTransform(rotation90);
    g.setColor(Color.WHITE);
    g.drawString(outputName, (int) ((height / 2) - (FontUtils.getWidthOfText(fm, outputName) / 2)),
            (int) (-width - 30));
    paintContext.popTransform(rotation90);
}

From source file:org.pentaho.platform.uifoundation.chart.FlashChartComponent.java

private String setRadialNumbers(final double x_center, final double y_center, final double radius,
        final double start_angle, final double end_angle, final long start_number, final long end_number,
        final long ticks_count, final long font_size, final String color) {
    StringBuffer sb = new StringBuffer();
    long number = start_number;

    for (double i = start_angle; i <= end_angle; i += (end_angle - start_angle) / (ticks_count - 1)) {
        sb.append("<text x='").append(x_center + Math.sin(Math.toRadians(i)) * radius).append("' y='") //$NON-NLS-1$//$NON-NLS-2$
                .append(y_center - Math.cos(Math.toRadians(i)) * radius).append("'"); //$NON-NLS-1$
        sb.append(" width='200' size='").append(font_size).append("' color='").append(color) //$NON-NLS-1$//$NON-NLS-2$
                .append("' align='left' rotation='").append(i).append("'>"); //$NON-NLS-1$ //$NON-NLS-2$
        sb.append(number).append("</text>\n"); //$NON-NLS-1$
        number += (end_number - start_number) / (ticks_count - 1);
    }// w  ww.ja va2 s  .  co  m
    return (sb.toString());
}

From source file:io.github.malapert.jwcs.JWcs.java

/**
 * Creates the projection by reading CTYPE1.
 * <p>//from   ww w  .  ja  v a2s.c  o m
 * Raises a JWcsError when no projection code is found.
 * 
 * @return the projection
 * @throws
 * io.github.malapert.jwcs.proj.exception.BadProjectionParameterException when the projection parameter is wrong
 */
protected final Projection createProjection() throws BadProjectionParameterException {
    String ctype1 = ctype(1);
    String codeProjection = ctype1.substring(ctype1.lastIndexOf("-") + 1, ctype1.length());
    Projection projection;
    switch (codeProjection) {
    case "AIT":
        projection = new AIT(crval(1), crval(2));
        break;
    case "ARC":
        projection = new ARC(crval(1), crval(2));
        break;
    case "AZP":
        if (hasKeyword(PV21) && hasKeyword(PV22)) {
            double mu = getValueAsDouble(PV21);
            double gamma = getValueAsDouble(PV22);
            projection = new AZP(crval(1), crval(2), mu, gamma);
        } else {
            projection = new AZP(crval(1), crval(2));
        }
        break;
    case "BON":
        projection = new BON(crval(1), crval(2), getValueAsDouble(PV21));
        break;
    case "CAR":
        projection = new CAR(crval(1), crval(2));
        break;
    case "CEA":
        projection = new CEA(crval(1), crval(2), getValueAsDouble(PV21));
        break;
    case "COD":
        projection = new COD(crval(1), crval(2), getValueAsDouble(PV21), getValueAsDouble(PV22));
        break;
    case "COE":
        projection = new COE(crval(1), crval(2), getValueAsDouble(PV21), getValueAsDouble(PV22));
        break;
    case "COO":
        projection = new COO(crval(1), crval(2), getValueAsDouble(PV21), getValueAsDouble(PV22));
        break;
    case "COP":
        projection = new COP(crval(1), crval(2), getValueAsDouble(PV21), getValueAsDouble(PV22));
        break;
    case "CYP":
        if (hasKeyword(PV21) && hasKeyword(PV22)) {
            projection = new CYP(crval(1), crval(2), getValueAsDouble(PV21), getValueAsDouble(PV22));
        } else {
            projection = new CYP(crval(1), crval(2));
        }
        break;
    case "MER":
        projection = new MER(crval(1), crval(2));
        break;
    case "MOL":
        projection = new MOL(crval(1), crval(2));
        break;
    case "PAR":
        projection = new PAR(crval(1), crval(2));
        break;
    case "PCO":
        projection = new PCO(crval(1), crval(2));
        break;
    case "SFL":
        projection = new SFL(crval(1), crval(2));
        break;
    case "SIN":
        projection = new SIN(crval(1), crval(2));
        break;
    case "STG":
        projection = new STG(crval(1), crval(2));
        break;
    case "SZP":
        if (hasKeyword(PV21) && hasKeyword(PV22) && hasKeyword(PV23)) {
            projection = new SZP(crval(1), crval(2), getValueAsDouble(PV21), getValueAsDouble(PV22),
                    getValueAsDouble(PV23));
        } else {
            projection = new SZP(crval(1), crval(2));
        }
        break;
    case "TAN":
        projection = new TAN(crval(1), crval(2));
        break;
    case "ZEA":
        projection = new ZEA(crval(1), crval(2));
        break;
    case "ZPN":
        Iterator iter = iterator();
        List<Double> pvs = new ArrayList<>();
        while (iter.hasNext()) {
            HeaderCard card = (HeaderCard) iter.next();
            String key = card.getKey();
            if (key.startsWith("PV2")) {
                pvs.add(Double.valueOf(card.getValue()));
            }
        }
        Double[] pvsArray = pvs.toArray(new Double[pvs.size()]);
        double[] pvsPrimitif = new double[pvsArray.length];
        for (int i = 0; i < pvsArray.length; i++) {
            pvsPrimitif[i] = pvsArray[i];
        }
        projection = new ZPN(crval(1), crval(2), pvsPrimitif);
        break;
    default:
        throw new JWcsError("code projection : " + codeProjection + " is not supported");
    }
    if (hasKeyword(PV11)) {
        projection.setPhi0(getValueAsDouble(PV11));
    }
    if (hasKeyword(PV12)) {
        projection.setTheta0(getValueAsDouble(PV12));
    }
    projection.setPhip(Math.toRadians(lonpole()));
    projection.setThetap(Math.toRadians(latpole()));
    return projection;
}

From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PDFAsVisualSignatureBuilder.java

public void createAppearanceDictionary(PDXObjectForm holderForml, PDSignatureField signatureField,
        float degrees) throws IOException {

    PDAppearanceDictionary appearance = new PDAppearanceDictionary();
    appearance.getCOSObject().setDirect(true);

    PDAppearanceStream appearanceStream = new PDAppearanceStream(holderForml.getCOSStream());
    AffineTransform transform = new AffineTransform();
    transform.setToIdentity();//from  www.j a v a2s. c o m
    transform.rotate(Math.toRadians(degrees));
    appearanceStream.setMatrix(transform);
    appearance.setNormalAppearance(appearanceStream);
    signatureField.getWidget().setAppearance(appearance);

    getStructure().setAppearanceDictionary(appearance);
    logger.debug("PDF appearance Dictionary has been created");

}

From source file:com.hangulo.powercontact.MainActivity.java

private int makeDemoData(int max) {

    showLoadingCircle(true);//from  ww w .j  a v a  2 s.  c o m
    //    ?  ~~~!!!!!

    deleteDemoData();

    // ?? .

    String[] dummyNames;
    dummyNames = getResources().getStringArray(R.array.dummy_names);
    int maxNames = dummyNames.length - 1;

    Vector<ContentValues> cVVector = new Vector<>(max + 10);

    // ArrayList<PowerContactAddress> retAddress = new ArrayList<>();
    LatLng currentLatLng = getCurrentLatLng();
    double lat, lng;
    for (int i = 1; i <= (max + 2); i++) {
        // South Korea
        // double latitude = Utils.getRandomNumber((double) 36.4922565f, (double) 38.4922565f);
        // double longitude = Utils.getRandomNumber((double) 125.92319053333333f, (double) 127.92319053333333f);

        ContentValues addrValues = new ContentValues(); // addr 

        String name = dummyNames[Utils.getRandomNumber(0, maxNames)] + " :" + i;

        if (i <= max) {
            lat = Utils.getRandomNumber((currentLatLng.latitude - 1), currentLatLng.latitude + 1);
            lng = Utils.getRandomNumber(currentLatLng.longitude - 1, currentLatLng.longitude + 1);
        } else {// to make same location data
            lat = currentLatLng.latitude;
            lng = currentLatLng.longitude;
            name = "duplicated" + i;
        }

        long contactId = 100000 + i;
        long dataId = 1000000 + i;
        String lookupKey = "";

        String address = "Address Phone " + i;
        int type = 1;
        String addrLabel = "";

        // double dist = Utils.getDistanceX(currentLatLng.latitude, currentLatLng.longitude, lat, lng); // 

        addrValues.put(PowerContactContract.PowerContactEntry.COLUMN_CONTACT_ID, contactId);
        addrValues.put(PowerContactContract.PowerContactEntry.COLUMN_DATA_ID, dataId);
        addrValues.put(PowerContactContract.PowerContactEntry.COLUMN_LOOKUP_KEY, lookupKey);
        addrValues.put(PowerContactContract.PowerContactEntry.COLUMN_NAME, name);
        addrValues.put(PowerContactContract.PowerContactEntry.COLUMN_ADDR, address);
        addrValues.put(PowerContactContract.PowerContactEntry.COLUMN_TYPE, type);
        addrValues.put(PowerContactContract.PowerContactEntry.COLUMN_LABEL, addrLabel);

        addrValues.put(PowerContactContract.PowerContactEntry.COLUMN_LAT, lat); // ?
        addrValues.put(PowerContactContract.PowerContactEntry.COLUMN_LNG, lng); //?

        // constants for calculation distance query   * http://king24.tistory.com/4
        addrValues.put(PowerContactContract.PowerContactEntry.COLUMN_SIN_LAT, Math.sin(Math.toRadians(lat)));
        addrValues.put(PowerContactContract.PowerContactEntry.COLUMN_SIN_LNG, Math.sin(Math.toRadians(lng)));
        addrValues.put(PowerContactContract.PowerContactEntry.COLUMN_COS_LAT, Math.cos(Math.toRadians(lat)));
        addrValues.put(PowerContactContract.PowerContactEntry.COLUMN_COS_LNG, Math.cos(Math.toRadians(lng)));

        // this is demo
        addrValues.put(PowerContactContract.PowerContactEntry.COLUMN_CONTACT_DATA_TYPE,
                PowerContactContract.PowerContactEntry.CONTACT_DATA_TYPE_DEMO);

        cVVector.add(addrValues); // save this row -->   ??.
    }

    // wrote to database // bulk update
    int return_count = 0;
    if (cVVector.size() > 0) {
        ContentValues[] cvArray = new ContentValues[cVVector.size()];
        cVVector.toArray(cvArray);
        return_count = getContentResolver().bulkInsert(PowerContactContract.PowerContactEntry.CONTENT_URI,
                cvArray);
    }

    showDemoInfo(return_count);

    Log.v(LOG_TAG, "makeDemoData()/dummydata input : " + return_count);

    showLoadingCircle(false);
    return return_count;
}

From source file:io.github.malapert.jwcs.coordsystem.Utility.java

/**
 * Given two angles in longitude and latitude returns corresponding 
 * Cartesian coordinates x,y,z.//  www  . ja  v  a2 s .  co  m
 * 
 * Notes:     
 * ------
 * The three coordinate axes x, y and z, the set of right-handed Cartesian
 * axes that correspond to the usual celestial spherical coordinate system. 
 * The xy-plane is the equator, the z-axis points toward the north celestial
 * pole, and the x-axis points toward the origin of right ascension.
 * 
 * @param longitude longitude in decimal degree
 * @param latitude latitude in decimal degree
 * @return Corresponding values of x,y,z in same order as input
 */
public final static RealMatrix longlat2xyz(double longitude, double latitude) {
    double longitudeRad = Math.toRadians(longitude);
    double latitudeRad = Math.toRadians(latitude);
    double x = Math.cos(longitudeRad) * Math.cos(latitudeRad);
    double y = Math.sin(longitudeRad) * Math.cos(latitudeRad);
    double z = Math.sin(latitudeRad);
    double[][] array = { { x }, { y }, { z } };
    return MatrixUtils.createRealMatrix(array);
}

From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox2.PDFAsVisualSignatureBuilder.java

public void createAppearanceDictionary(PDFormXObject holderForml, PDSignatureField signatureField,
        float degrees) throws IOException {

    PDAppearanceDictionary appearance = new PDAppearanceDictionary();
    appearance.getCOSObject().setDirect(true);

    PDAppearanceStream appearanceStream = new PDAppearanceStream(holderForml.getCOSStream());
    AffineTransform transform = new AffineTransform();
    transform.setToIdentity();/*www  . ja v a  2 s  . c om*/
    transform.rotate(Math.toRadians(degrees));
    appearanceStream.setMatrix(transform);
    appearance.setNormalAppearance(appearanceStream);
    signatureField.getWidget().setAppearance(appearance);

    getStructure().setAppearanceDictionary(appearance);
    logger.debug("PDF appereance Dictionary has been created");

}

From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java

@Override
protected void onResume() {
    super.onResume();

    try {//from  w w w.j  ava2 s  .  c  o m
        this.mWakeLock.acquire(); // ?? ?

        killOnError(); // ?  ?
        mixContext.mixView = this; // ??  
        dataView.doStart(); // ?? 
        dataView.clearEvents(); // ? ?

        double angleX, angleY; // ? x, y

        /*? ?  ? */
        angleX = Math.toRadians(-90);
        m1.set(1f, 0f, 0f, 0f, (float) Math.cos(angleX), (float) -Math.sin(angleX), 0f,
                (float) Math.sin(angleX), (float) Math.cos(angleX));

        angleX = Math.toRadians(-90);
        angleY = Math.toRadians(-90);
        m2.set(1f, 0f, 0f, 0f, (float) Math.cos(angleX), (float) -Math.sin(angleX), 0f,
                (float) Math.sin(angleX), (float) Math.cos(angleX));
        m3.set((float) Math.cos(angleY), 0f, (float) Math.sin(angleY), 0f, 1f, 0f, (float) -Math.sin(angleY),
                0f, (float) Math.cos(angleY));

        m4.toIdentity();

        for (int i = 0; i < histR.length; i++) {
            histR[i] = new Matrix();
        }
        /*   */

        //  ? 
        sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);

        // ?  ?
        // ?? 
        sensors = sensorMgr.getSensorList(Sensor.TYPE_ACCELEROMETER);
        if (sensors.size() > 0) {
            sensorGrav = sensors.get(0);
        }

        // ? 
        sensors = sensorMgr.getSensorList(Sensor.TYPE_MAGNETIC_FIELD);
        if (sensors.size() > 0) {
            sensorMag = sensors.get(0);
        }
        //// TODO: 2016-06-01
        if (sensors.size() > 0) {
            sensors = sensorMgr_ori.getSensorList(Sensor.TYPE_ORIENTATION);
            orientationSensor = sensors.get(0);
        }
        //  ??  ? ? ? ?
        sensorMgr.registerListener(this, sensorGrav, SENSOR_DELAY_GAME);
        sensorMgr.registerListener(this, sensorMag, SENSOR_DELAY_GAME);

        if (orientationSensor != null) {
            sensorMgr_ori.registerListener(this, orientationSensor, sensorMgr_ori.SENSOR_DELAY_GAME);
        }

        try {
            // ?? (Criteria)
            // http://developer.android.com/reference/android/location/Criteria.html
            Criteria c = new Criteria();

            // ? 
            c.setAccuracy(Criteria.ACCURACY_FINE);
            //c.setBearingRequired(true);

            // ?  
            locationMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            // ?? ? ?  ? . 2 , 3 
            locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 4, this);

            // ?? ? ,   
            String bestP = locationMgr.getBestProvider(c, true);
            isGpsEnabled = locationMgr.isProviderEnabled(bestP);

            // gps, ? ? ?   
            Location hardFix = new Location("reverseGeocoded");

            try {
                //  ? gps, ??     
                Location gps = locationMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                Location network = locationMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

                //  ?  ?   
                //  gps > ? > 
                if (gps != null)
                    mixContext.curLoc = gps;
                else if (network != null)
                    mixContext.curLoc = network;
                else
                    mixContext.curLoc = hardFix;

            } catch (Exception ex2) { //  ? 
                ex2.printStackTrace(); //  
                mixContext.curLoc = hardFix; //   
            }
            // ? ?  ??  
            mixContext.setLocationAtLastDownload(mixContext.curLoc);

            // ?? .   ?   
            GeomagneticField gmf = new GeomagneticField((float) mixContext.curLoc.getLatitude(),
                    (float) mixContext.curLoc.getLongitude(), (float) mixContext.curLoc.getAltitude(),
                    System.currentTimeMillis());

            // ??   
            angleY = Math.toRadians(-gmf.getDeclination());
            m4.set((float) Math.cos(angleY), 0f, (float) Math.sin(angleY), 0f, 1f, 0f,
                    (float) -Math.sin(angleY), 0f, (float) Math.cos(angleY));
            mixContext.declination = gmf.getDeclination();
        } catch (Exception ex) {
            Log.d("mixare", "GPS Initialize Error", ex); //  ? 
        }
        //  ? 
        downloadThread = new Thread(mixContext.downloadManager);
        downloadThread.start();

    } catch (Exception ex) {
        doError(ex); // ? 

        try {
            // ???  
            if (sensorMgr != null) {
                sensorMgr.unregisterListener(this, sensorGrav);
                sensorMgr.unregisterListener(this, sensorMag);
                sensorMgr = null;
            }
            //  ??   
            if (locationMgr != null) {
                locationMgr.removeUpdates(this);
                locationMgr = null;
            }
            // ??  ?? 
            if (mixContext != null) {
                if (mixContext.downloadManager != null)
                    mixContext.downloadManager.stop();
            }
        } catch (Exception ignore) {
        }
    }

    //  ?? 
    // ??   ? ( ?? ) ?    
    if (dataView.isFrozen() && searchNotificationTxt == null) {
        searchNotificationTxt = new TextView(this);
        searchNotificationTxt.setWidth(dWindow.getWidth());
        searchNotificationTxt.setPadding(10, 2, 0, 0);
        searchNotificationTxt.setBackgroundColor(Color.DKGRAY);
        searchNotificationTxt.setTextColor(Color.WHITE);

        searchNotificationTxt.setOnTouchListener(this);
        addContentView(searchNotificationTxt,
                new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    } else if (!dataView.isFrozen() && searchNotificationTxt != null) {
        searchNotificationTxt.setVisibility(View.GONE);
        searchNotificationTxt = null;
    }
}

From source file:com.larvalabs.svgandroid.SVGParser.java

/**
 * Elliptical arc implementation based on the SVG specification notes
 * Adapted from the Batik library (Apache-2 license) by SAU
 *///from   w  w w  .  j a  v  a 2  s  .c o m

private static void drawArc(Path path, double x0, double y0, double x, double y, double rx, double ry,
        double angle, boolean largeArcFlag, boolean sweepFlag) {
    double dx2 = (x0 - x) / 2.0;
    double dy2 = (y0 - y) / 2.0;
    angle = Math.toRadians(angle % 360.0);
    double cosAngle = Math.cos(angle);
    double sinAngle = Math.sin(angle);

    double x1 = (cosAngle * dx2 + sinAngle * dy2);
    double y1 = (-sinAngle * dx2 + cosAngle * dy2);
    rx = Math.abs(rx);
    ry = Math.abs(ry);

    double Prx = rx * rx;
    double Pry = ry * ry;
    double Px1 = x1 * x1;
    double Py1 = y1 * y1;

    // check that radii are large enough
    double radiiCheck = Px1 / Prx + Py1 / Pry;
    if (radiiCheck > 1) {
        rx = Math.sqrt(radiiCheck) * rx;
        ry = Math.sqrt(radiiCheck) * ry;
        Prx = rx * rx;
        Pry = ry * ry;
    }

    // Step 2 : Compute (cx1, cy1)
    double sign = (largeArcFlag == sweepFlag) ? -1 : 1;
    double sq = ((Prx * Pry) - (Prx * Py1) - (Pry * Px1)) / ((Prx * Py1) + (Pry * Px1));
    sq = (sq < 0) ? 0 : sq;
    double coef = (sign * Math.sqrt(sq));
    double cx1 = coef * ((rx * y1) / ry);
    double cy1 = coef * -((ry * x1) / rx);

    double sx2 = (x0 + x) / 2.0;
    double sy2 = (y0 + y) / 2.0;
    double cx = sx2 + (cosAngle * cx1 - sinAngle * cy1);
    double cy = sy2 + (sinAngle * cx1 + cosAngle * cy1);

    // Step 4 : Compute the angleStart (angle1) and the angleExtent (dangle)
    double ux = (x1 - cx1) / rx;
    double uy = (y1 - cy1) / ry;
    double vx = (-x1 - cx1) / rx;
    double vy = (-y1 - cy1) / ry;
    double p, n;

    // Compute the angle start
    n = Math.sqrt((ux * ux) + (uy * uy));
    p = ux; // (1 * ux) + (0 * uy)
    sign = (uy < 0) ? -1.0 : 1.0;
    double angleStart = Math.toDegrees(sign * Math.acos(p / n));

    // Compute the angle extent
    n = Math.sqrt((ux * ux + uy * uy) * (vx * vx + vy * vy));
    p = ux * vx + uy * vy;
    sign = (ux * vy - uy * vx < 0) ? -1.0 : 1.0;
    double angleExtent = Math.toDegrees(sign * Math.acos(p / n));
    if (!sweepFlag && angleExtent > 0) {
        angleExtent -= 360f;
    } else if (sweepFlag && angleExtent < 0) {
        angleExtent += 360f;
    }
    angleExtent %= 360f;
    angleStart %= 360f;

    RectF oval = new RectF((float) (cx - rx), (float) (cy - ry), (float) (cx + rx), (float) (cy + ry));
    path.addArc(oval, (float) angleStart, (float) angleExtent);
}

From source file:io.github.data4all.activity.CameraActivity.java

/**
 * This method update the Camera View Assist for drawing the horizontal line
 * on sensor change./* ww  w.  j a v  a 2  s. c  o  m*/
 */
public void updateCameraAssistView() {

    if (orientationListener != null) {
        final Camera.Parameters params = mCamera.getParameters();
        final float horizontalViewAngle = (float) Math.toRadians(params.getVerticalViewAngle());
        final float verticalViewAngle = (float) Math.toRadians(params.getHorizontalViewAngle());
        cameraAssistView.setInformations(horizontalViewAngle, verticalViewAngle,
                orientationListener.getDeviceOrientation());
        cameraAssistView.invalidate();
        // disable the camerabutton when the camera looks to the sky
        if (!cameraAssistView.isSkylook()) {
            btnCapture.setVisibility(View.VISIBLE);
        } else {
            btnCapture.setVisibility(View.GONE);
        }
    }

}