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:pt.lsts.neptus.plugins.sunfish.awareness.HubLocationProvider.java

@Periodic(millisBetweenUpdates = 3000 * 60)
public void sendToHub() {
    if (!enabled)
        return;//  w ww.  j av  a2s  . com
    NeptusLog.pub().info("Uploading device updates to Hub...");
    LinkedHashMap<Integer, AssetPosition> toSend = new LinkedHashMap<Integer, AssetPosition>();
    LocationType myLoc = MyState.getLocation();
    AssetPosition myPos = new AssetPosition(StringUtils.toImcName(GeneralPreferences.imcCcuName),
            myLoc.getLatitudeDegs(), myLoc.getLongitudeDegs());
    toSend.put(ImcMsgManager.getManager().getLocalId().intValue(), myPos);
    toSend.putAll(positionsToSend);
    positionsToSend.clear();
    DeviceUpdate upd = new DeviceUpdate();
    //ExtendedDeviceUpdate upd = new ExtendedDeviceUpdate();
    upd.source = ImcMsgManager.getManager().getLocalId().intValue();
    upd.destination = 65535;
    for (Entry<Integer, AssetPosition> pos : toSend.entrySet()) {
        Position p = new Position();
        p.id = pos.getKey();
        p.latRads = pos.getValue().getLoc().getLatitudeRads();
        p.lonRads = pos.getValue().getLoc().getLongitudeRads();
        p.posType = Position.fromImcId(p.id);
        p.timestamp = pos.getValue().getTimestamp() / 1000.0;
        upd.getPositions().put(pos.getKey(), p);
    }

    for (Position p : upd.getPositions().values()) {
        NeptusLog.pub().info("Uploading position for " + p.id + ": " + Math.toDegrees(p.latRads) + "/"
                + Math.toDegrees(p.lonRads) + "/" + new Date((long) (1000 * p.timestamp)));
    }

    try {
        HttpPost postMethod = new HttpPost(iridiumUrl);
        postMethod.setHeader("Content-type", "application/hub");
        String data = new String(Hex.encodeHex(upd.serialize()));
        NeptusLog.pub().info("Sending '" + data + "'");
        StringEntity ent = new StringEntity(data);
        postMethod.setEntity(ent);
        @SuppressWarnings("resource")
        HttpClient client = new DefaultHttpClient();
        HttpResponse response = client.execute(postMethod);
        NeptusLog.pub().info("Sent " + upd.getPositions().size() + " device updates to Hub: "
                + response.getStatusLine().toString());
        postMethod.abort();
    } catch (Exception e) {
        NeptusLog.pub().error("Error sending updates to hub", e);
        parent.postNotification(Notification
                .error("Situation Awareness",
                        e.getClass().getSimpleName() + " while trying to send device updates to HUB.")
                .requireHumanAction(false));
    }
}

From source file:android.support.transition.PatternPathMotion.java

@Override
public Path getPath(float startX, float startY, float endX, float endY) {
    float dx = endX - startX;
    float dy = endY - startY;
    float length = distance(dx, dy);
    double angle = Math.atan2(dy, dx);

    mTempMatrix.setScale(length, length);
    mTempMatrix.postRotate((float) Math.toDegrees(angle));
    mTempMatrix.postTranslate(startX, startY);
    Path path = new Path();
    mPatternPath.transform(mTempMatrix, path);
    return path;//from  ww  w  .  ja v a  2s . co m
}

From source file:org.interpss.dstab.output.DStabOutFunc.java

public static String initConditionSummary(DynamicSimuAlgorithm algo) {
    DStabilityNetwork net = algo.getDStabNet();
    StringBuffer str = new StringBuffer("");
    try {/*from  www.j av  a  2  s. c o m*/
        double refAng = 0.0;
        Machine refMach = algo.getRefMachine();
        if (refMach != null)
            refAng = Math.toDegrees(refMach.getAngle());

        str.append("\n                          Initial Condition Summary\n");
        str.append("     BusID     Volt(pu)     Angle(deg)   P(pu)     Q(pu)   Mach Model     PowerAng(deg)\n");
        str.append("  -------------------------------------------------------------------------------------\n");

        for (Bus b : net.getBusList()) {
            DStabBus bus = (DStabBus) b;
            AclfGenBus genBus = bus.toGenBus();
            Complex busPQ = genBus.getGenResults(UnitType.PU);
            busPQ = busPQ.subtract(genBus.getLoadResults(UnitType.PU));
            if (bus.isCapacitor()) {
                AclfCapacitorBus cap = bus.toCapacitorBus();
                busPQ = busPQ.add(new Complex(0.0, cap.getQResults(UnitType.PU)));
            }
            str.append(Number2String.toStr(2, " "));
            str.append(Number2String.toStr(-12, bus.getId()) + "  ");
            str.append(Number2String.toStr(bus.getVoltageMag(UnitType.PU), "###0.000") + " ");
            str.append(Number2String.toStr((bus.getVoltageAng(UnitType.Deg)) - refAng, "######0.0") + "  ");
            str.append(Number2String.toStr(busPQ.getReal(), "####0.0000"));
            str.append(Number2String.toStr(busPQ.getImaginary(), "####0.0000") + "  ");
            if (bus.getMachine() != null) {
                Machine mach = bus.getMachine();
                str.append(machModelStr(mach) + "   ");
                str.append(Number2String.toStr(Math.toDegrees(mach.getAngle()) - refAng, "####0.0"));
            } else if (bus.getScriptDynamicBusDevice() != null) {
                // Machine mach = bus.getMachine();
                str.append("Dyn Bus Device   " + " ");
            }
            /*
             * else if (bus.getScriptDBusDevice() != null) { //Machine mach =
             * bus.getMachine(); str.append("Script Bus Device" + " "); }
             */
            str.append("\n");
        }
    } catch (Exception emsg) {
        str.append(emsg.toString());
    }
    return str.toString();
}

From source file:org.interpss.numeric.datatype.ComplexFunc.java

/**
 * Convert the obj to a string./*w w w  . j ava  2 s.c  o  m*/
 * 
 * @return the string representation of the obj
 */
public static String toMagAng(final Complex c) {
    return Number2String.toStr(c.abs()) + "(" + Number2String.toStr(Math.toDegrees(arg(c)), "###0.#") + ")";
}

From source file:com.laex.cg2d.model.joints.BERevoluteJoint.java

@Override
public Object getPropertyValue(Object id) {
    if (isReferenceAngleProp(id)) {
        return Double.toString(Math.toDegrees(revoluteJointDef.referenceAngle));
    }/*from  w  w w  .  j  a v a 2s.c  om*/
    if (isEnableLimitProp(id)) {
        return BooleanUtil.getIntegerFromBoolean(revoluteJointDef.enableLimit);
    }
    if (isLowerAngleProp(id)) {
        return Float.toString(revoluteJointDef.lowerAngle);
    }
    if (isUpperAngleProp(id)) {
        return Float.toString(revoluteJointDef.upperAngle);
    }
    if (isEnableMotorProp(id)) {
        return BooleanUtil.getIntegerFromBoolean(revoluteJointDef.enableMotor);
    }
    if (isMotorSpeedProp(id)) {
        return Float.toString(revoluteJointDef.motorSpeed);
    }
    if (isMaxMotorTorqueProp(id)) {
        return Float.toString(revoluteJointDef.maxMotorTorque);
    }
    return super.getPropertyValue(id);
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionMath.java

/**
 * data provider generator for single-value tests
 * @return data/*from ww w .  j  a  v a  2  s .  co m*/
 */
@DataProvider
public static Object[] singlevaluegenerate() {
    return Stream.concat(

            singlevaluetestcase(

                    Stream.of(2.5, 9.1, 111.7, 889.9),

                    Stream.of(CNextPrime.class),

                    (i) -> (double) Primes.nextPrime(i.intValue())),

            singlevaluetestcase(

                    Stream.of(-2, -6, 4, -1, -5, 3, 49, 30, 6, 5, 1.3, 2.8, 9.7, 1, 8, 180, Math.PI),

                    Stream.of(CAbs.class, CACos.class, CASin.class, CATan.class, CCeil.class, CCos.class,
                            CCosh.class, CDegrees.class, CExp.class, CIsPrime.class, CLog.class, CLog10.class,
                            CFloor.class, CRadians.class, CRound.class, CSignum.class, CSin.class, CSinh.class,
                            CSqrt.class, CTan.class, CTanh.class),

                    (i) -> Math.abs(i.doubleValue()), (i) -> Math.acos(i.doubleValue()),
                    (i) -> Math.asin(i.doubleValue()), (i) -> Math.atan(i.doubleValue()),
                    (i) -> Math.ceil(i.doubleValue()), (i) -> Math.cos(i.doubleValue()),
                    (i) -> Math.cosh(i.doubleValue()), (i) -> Math.toDegrees(i.doubleValue()),
                    (i) -> Math.exp(i.doubleValue()), (i) -> Primes.isPrime(i.intValue()),
                    (i) -> Math.log(i.doubleValue()), (i) -> Math.log10(i.doubleValue()),
                    (i) -> Math.floor(i.doubleValue()), (i) -> Math.toRadians(i.doubleValue()),
                    (i) -> Math.round(i.doubleValue()), (i) -> Math.signum(i.doubleValue()),
                    (i) -> Math.sin(i.doubleValue()), (i) -> Math.sinh(i.doubleValue()),
                    (i) -> Math.sqrt(i.doubleValue()), (i) -> Math.tan(i.doubleValue()),
                    (i) -> Math.tanh(i.doubleValue()))

    ).toArray();
}

From source file:com.adstrosoftware.notificationcompass.CompassService.java

@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
        if (previousEventTimeStamp == Long.MIN_VALUE
                || (event.timestamp - previousEventTimeStamp) > DELAY_IN_NS) {
            previousEventTimeStamp = event.timestamp;

            float[] orientation = new float[3];
            float[] rotationMatrix = new float[16];
            float[] remappedRotationMatrix = new float[16];

            SensorManager.getRotationMatrixFromVector(rotationMatrix, event.values);

            if (event.values[0] <= -45) {
                SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z,
                        remappedRotationMatrix);
            } else {
                remappedRotationMatrix = rotationMatrix;
            }/*from  www. j av a 2s .co  m*/

            SensorManager.getOrientation(remappedRotationMatrix, orientation);

            Notification notification;

            double azimuth = Math.toDegrees(orientation[0]);

            if (BuildConfig.DEBUG) {
                Log.d(TAG, "Azimuth = " + azimuth);
            }

            if (azimuth <= (NORTH + ANGLE) && azimuth >= (NORTH - ANGLE)) {
                if (BuildConfig.DEBUG)
                    Log.d(TAG, "NORTH");
                notification = buildNotification(R.string.north, R.drawable.ic_stat_north, azimuth);
            } else if (azimuth <= (NORTH_EAST + ANGLE) && azimuth > 0) {
                if (BuildConfig.DEBUG)
                    Log.d(TAG, "NORTH_EAST");
                notification = buildNotification(R.string.north_east, R.drawable.ic_stat_north_east, azimuth);
            } else if (azimuth >= (NORTH_WEST - ANGLE) && azimuth < 0) {
                if (BuildConfig.DEBUG)
                    Log.d(TAG, "NORTH_WEST");
                notification = buildNotification(R.string.north_west, R.drawable.ic_stat_north_west, azimuth);
            } else if (azimuth <= (EAST + ANGLE) && azimuth > 0) {
                if (BuildConfig.DEBUG)
                    Log.d(TAG, "EAST");
                notification = buildNotification(R.string.east, R.drawable.ic_stat_east, azimuth);
            } else if (azimuth >= (WEST - ANGLE) && azimuth < 0) {
                if (BuildConfig.DEBUG)
                    Log.d(TAG, "WEST");
                notification = buildNotification(R.string.west, R.drawable.ic_stat_west, azimuth);
            } else if (azimuth <= (SOUTH_EAST + ANGLE) && azimuth > 0) {
                if (BuildConfig.DEBUG)
                    Log.d(TAG, "SOUTH_EAST");
                notification = buildNotification(R.string.south_east, R.drawable.ic_stat_south_east, azimuth);
            } else if (azimuth >= (SOUTH_WEST - ANGLE) && azimuth < 0) {
                if (BuildConfig.DEBUG)
                    Log.d(TAG, "SOUTH_WEST");
                notification = buildNotification(R.string.south_west, R.drawable.ic_stat_south_west, azimuth);
            } else {
                if (BuildConfig.DEBUG)
                    Log.d(TAG, "SOUTH");
                notification = buildNotification(R.string.south, R.drawable.ic_stat_south, azimuth);
            }

            notificationManager.notify(NOTIFICATION_ID, notification);
        }
    }
}

From source file:fr.amap.lidar.amapvox.commons.GTheta.java

/**
 * <p>Get the transmittance from the specified angle (radians or degrees) and the specified Leaf Angle Distribution.</p>
 * 0 is vertical, 90 is horizontal (zenithal angle, measured from vertical).
 * @param theta Angle//from   w  w  w.jav  a2 s  . co  m
 * @param degrees true if the given angle is in degrees, false otherwise
 * @return directional transmittance (GTheta)
 */
public double getGThetaFromAngle(double theta, boolean degrees) {

    if (degrees) {
        if (theta > 90) { //get an angle between 0 and 90
            theta = 180 - theta;
        }
    } else {
        if (theta > (Math.PI / 2.0)) { //get an angle between 0 and pi/2
            theta = Math.PI - theta;
        }
    }

    if (transmittanceFunctions != null && !isBuildingTable) { //a table was built

        int indice = 0;
        if (degrees) {
            indice = (int) (theta / res);
        } else {
            indice = (int) (Math.toDegrees(theta) / res);
        }

        if (indice >= transmittanceFunctions.length) {
            indice = transmittanceFunctions.length - 1;
        } else if (indice < 0) {
            indice = 0;
        }

        return transmittanceFunctions[indice];

    } else { //no table was built, get transmittance on the fly

        if (pdfArray == null) {
            setupDensityProbabilityArray(DEFAULT_STEP_NUMBER);
        }
        if (distribution.getType() == SPHERIC) {

            return 0.5; //the result for spherical distribution is always 0.5, saving processing time

        } else {

            if (degrees) {
                theta = Math.toRadians(theta);
            }

            if (theta == 0) {
                theta = Double.MIN_VALUE;
            }

            if (theta >= Math.PI / 2.0) {
                theta = (Math.PI / 2.0) - 0.00001;
            }

            UnivariateFunction function1 = new CustomFunction1(theta);
            UnivariateFunction function2 = new CustomFunction2(theta);

            TrapezoidIntegrator integrator = new TrapezoidIntegrator();

            double sum = 0;
            for (int j = 0; j < nbIntervals; j++) {

                double thetaL = (serie_angulaire[j] + serie_angulaire[j + 1]) / 2.0d;
                double Fi = (pdfArray[j]) / SOM;

                double cotcot = Math.abs(1 / (Math.tan(theta) * Math.tan(thetaL)));

                double Hi;

                if (cotcot > 1 || Double.isInfinite(cotcot)) {
                    Hi = integrator.integrate(10000, function1, serie_angulaire[j], serie_angulaire[j + 1]);
                } else {
                    Hi = integrator.integrate(10000, function2, serie_angulaire[j], serie_angulaire[j + 1]);
                    //System.out.println("nb evaluations: " + integrator.getEvaluations());
                }

                double Gi = Fi * Hi / ((Math.PI / 2) / (double) serie_angulaire.length); //because we need the average value not the actual integral value!!!!
                sum += Gi;
            }

            return sum;
        }
    }

}

From source file:org.apache.drill.exec.fn.impl.TestNewMathFunctions.java

@Test
public void testExtendedMathFunc() throws Throwable {
    final BigDecimal d = new BigDecimal(
            "100111111111111111111111111111111111.00000000000000000000000000000000000000000000000000001");
    final Object[] expected = new Object[] { Math.cbrt(1000), Math.log(10), Math.log10(5),
            (Math.log(64.0) / Math.log(2.0)), Math.exp(10), Math.toDegrees(0.5), Math.toRadians(45.0), Math.PI,
            Math.cbrt(d.doubleValue()), Math.log(d.doubleValue()), (Math.log(d.doubleValue()) / Math.log(2)),
            Math.exp(d.doubleValue()), Math.toDegrees(d.doubleValue()), Math.toRadians(d.doubleValue()) };
    runTest(expected, "functions/testExtendedMathFunctions.json");
}

From source file:ActualizadorLocal.Clientes.ClienteNodos.java

public void procesarDatos(String datos) throws SQLException {
    //Preprocesamos los datos, para darle un nombre al array:

    datos = "{\"nodos\":" + datos + "}";

    JSONParser parser = new JSONParser();

    try {//w  w w.j a  v  a  2  s  . co  m
        JSONObject obj = (JSONObject) parser.parse(datos);
        JSONArray lista = (JSONArray) obj.get("nodos");

        for (int i = 0; i < lista.size(); i++) {
            long a0 = (long) ((JSONObject) lista.get(i)).get("idNodo");
            String a1 = (String) ((JSONObject) lista.get(i)).get("nombre");
            double a2 = (double) ((JSONObject) lista.get(i)).get("latitud");
            double a3 = (double) ((JSONObject) lista.get(i)).get("longitud");

            nodos.add(a0);

            //Tenemos que calcular el polgono para la visualizacin de los datos mediante GOOGLE FUSION TABLES:

            double lat = Math.toRadians(new Double(a2));
            double lon = Math.toRadians(new Double(a3));

            double radio = 50.0 / 6378137.0;

            String cadena_poligono = "<Polygon><outerBoundaryIs><LinearRing><coordinates>";

            for (int j = 0; j <= 360; j = j + 15) {
                double r = Math.toRadians(j);
                double lat_rad = Math
                        .asin(Math.sin(lat) * Math.cos(radio) + Math.cos(lat) * Math.sin(radio) * Math.cos(r));
                double lon_rad = Math.atan2(Math.sin(r) * Math.sin(radio) * Math.cos(lat),
                        Math.cos(radio) - Math.sin(lat) * Math.sin(lat_rad));
                double lon_rad_f = ((lon + lon_rad + Math.PI) % (2 * Math.PI)) - Math.PI;

                cadena_poligono = cadena_poligono + Math.toDegrees(lon_rad_f) + "," + Math.toDegrees(lat_rad)
                        + ",0.0 ";
            }

            cadena_poligono = cadena_poligono + "</coordinates></LinearRing></outerBoundaryIs></Polygon>";

            this.InsertarDatos("\"" + (String) Long.toString(a0) + "\",\"" + a1 + "\",\"" + Double.toString(a2)
                    + "\",\"" + Double.toString(a3) + "\",\"" + cadena_poligono + "\"");

        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }

    syncDB();

}