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.opentripplanner.analyst.request.IsoChroneSPTRendererAccSampling.java

/**
 * @param isoChroneRequest//from w  ww.j  a  v  a  2 s .c  o  m
 * @param sptRequest
 * @return
 */
@Override
public List<IsochroneData> getIsochrones(IsoChroneRequest isoChroneRequest, RoutingRequest sptRequest) {

    // Off-road max distance MUST be APPROX EQUALS to the grid precision
    final double D0 = isoChroneRequest.getPrecisionMeters() * 0.8;
    final double V0 = 1.00; // m/s, off-road walk speed

    // 1. Compute the Shortest Path Tree.
    long t0 = System.currentTimeMillis();
    long tOvershot = (long) (2 * D0 / V0);
    sptRequest.setWorstTime(
            sptRequest.dateTime + (sptRequest.arriveBy ? -isoChroneRequest.getMaxTimeSec() - tOvershot
                    : isoChroneRequest.getMaxTimeSec() + tOvershot));
    sptRequest.setBatch(true);
    sptRequest.setRoutingContext(graphService.getGraph(sptRequest.getRouterId()));
    final ShortestPathTree spt = sptService.getShortestPathTree(sptRequest);

    // 3. Create a sample grid based on the SPT.
    long t1 = System.currentTimeMillis();
    Coordinate center = sptRequest.getFrom().getCoordinate();
    final double gridSizeMeters = isoChroneRequest.getPrecisionMeters();
    final double cosLat = FastMath.cos(toRadians(center.y));
    double dY = Math.toDegrees(gridSizeMeters / SphericalDistanceLibrary.RADIUS_OF_EARTH_IN_M);
    double dX = dY / cosLat;

    SparseMatrixZSampleGrid<WTWD> sampleGrid = new SparseMatrixZSampleGrid<WTWD>(16, spt.getVertexCount(), dX,
            dY, center);
    sampleSPT(spt, sampleGrid, gridSizeMeters * 0.7, gridSizeMeters, V0, sptRequest.getMaxWalkDistance(),
            cosLat);
    sptRequest.cleanup();

    // 4. Compute isolines
    ZMetric<WTWD> zMetric = new ZMetric<WTWD>() {
        @Override
        public int cut(WTWD zA, WTWD zB, WTWD z0) {
            double t0 = z0.tw / z0.w;
            double tA = zA.d > z0.d ? Double.POSITIVE_INFINITY : zA.tw / zA.w;
            double tB = zB.d > z0.d ? Double.POSITIVE_INFINITY : zB.tw / zB.w;
            if (tA < t0 && t0 <= tB)
                return 1;
            if (tB < t0 && t0 <= tA)
                return -1;
            return 0;
        }

        @Override
        public double interpolate(WTWD zA, WTWD zB, WTWD z0) {
            if (zA.d > z0.d || zB.d > z0.d) {
                if (zA.d > z0.d && zB.d > z0.d)
                    throw new AssertionError("dA > d0 && dB > d0");
                // Interpolate on d
                double k = zA.d == zB.d ? 0.5 : (z0.d - zA.d) / (zB.d - zA.d);
                return k;
            } else {
                // Interpolate on t
                double tA = zA.tw / zA.w;
                double tB = zB.tw / zB.w;
                double t0 = z0.tw / z0.w;
                double k = tA == tB ? 0.5 : (t0 - tA) / (tB - tA);
                return k;
            }
        }
    };
    DelaunayIsolineBuilder<WTWD> isolineBuilder = new DelaunayIsolineBuilder<WTWD>(sampleGrid, zMetric);
    isolineBuilder.setDebug(isoChroneRequest.isIncludeDebugGeometry());

    long t2 = System.currentTimeMillis();
    List<IsochroneData> isochrones = new ArrayList<IsochroneData>();
    for (Integer cutoffSec : isoChroneRequest.getCutoffSecList()) {
        WTWD z0 = new WTWD();
        z0.w = 1.0;
        z0.tw = cutoffSec;
        z0.d = D0;
        IsochroneData isochrone = new IsochroneData(cutoffSec, isolineBuilder.computeIsoline(z0));
        if (isoChroneRequest.isIncludeDebugGeometry())
            isochrone.setDebugGeometry(isolineBuilder.getDebugGeometry());
        isochrones.add(isochrone);
    }

    long t3 = System.currentTimeMillis();
    LOG.info("Computed SPT in {}msec, {} isochrones in {}msec ({}msec for sampling)", (int) (t1 - t0),
            isochrones.size(), (int) (t3 - t1), (int) (t2 - t1));

    return isochrones;
}

From source file:uk.ac.diamond.scisoft.ncd.core.DegreeOfOrientation.java

public Object[] process(Serializable buffer, Serializable axis, final int[] dimensions) {

    double[] parentaxis = (double[]) ConvertUtils.convert(axis, double[].class);
    float[] parentdata = (float[]) ConvertUtils.convert(buffer, float[].class);

    int size = dimensions[dimensions.length - 1];
    double[] myaxis = new double[size];
    double[] mydata = new double[size];
    double[] cos2data = new double[size];
    double[] sin2data = new double[size];
    double[] sincosdata = new double[size];

    for (int i = 0; i < parentaxis.length; i++) {
        myaxis[i] = Math.toRadians(parentaxis[i]);
        mydata[i] = parentdata[i];//from  w w  w.j a  va 2s .  co m
        float cos2alpha = (float) Math.cos(2.0 * myaxis[i]);
        float sin2alpha = (float) Math.sin(2.0 * myaxis[i]);
        cos2data[i] = (1.0f + cos2alpha) * parentdata[i] / 2.0;
        sin2data[i] = (1.0f - cos2alpha) * parentdata[i] / 2.0;
        sincosdata[i] = sin2alpha * parentdata[i] / 2.0;
    }

    UnivariateInterpolator interpolator = new SplineInterpolator();
    UnivariateFunction function = interpolator.interpolate(myaxis, mydata);
    UnivariateFunction cos2Function = interpolator.interpolate(myaxis, cos2data);
    UnivariateFunction sin2Function = interpolator.interpolate(myaxis, sin2data);
    UnivariateFunction sincosFunction = interpolator.interpolate(myaxis, sincosdata);

    UnivariateIntegrator integrator = new IterativeLegendreGaussIntegrator(15,
            BaseAbstractUnivariateIntegrator.DEFAULT_RELATIVE_ACCURACY,
            BaseAbstractUnivariateIntegrator.DEFAULT_ABSOLUTE_ACCURACY);

    try {
        float cos2mean = (float) integrator.integrate(INTEGRATION_POINTS, cos2Function, myaxis[0],
                myaxis[myaxis.length - 1]);
        float sin2mean = (float) integrator.integrate(INTEGRATION_POINTS, sin2Function, myaxis[0],
                myaxis[myaxis.length - 1]);
        float sincosmean = (float) integrator.integrate(INTEGRATION_POINTS, sincosFunction, myaxis[0],
                myaxis[myaxis.length - 1]);
        float norm = (float) integrator.integrate(INTEGRATION_POINTS, function, myaxis[0],
                myaxis[myaxis.length - 1]);

        cos2mean /= norm;
        sin2mean /= norm;
        sincosmean /= norm;

        float result = (float) Math.sqrt(Math.pow(cos2mean - sin2mean, 2) - 4.0 * sincosmean * sincosmean);
        double angle = MathUtils.normalizeAngle(Math.atan2(2.0 * sincosmean, cos2mean - sin2mean) / 2.0,
                Math.PI);

        Object[] output = new Object[] { new float[] { result }, new float[] { (float) Math.toDegrees(angle) },
                new float[] { (float) (result * Math.cos(angle)), (float) (result * Math.sin(angle)) }, };

        return output;

    } catch (TooManyEvaluationsException e) {
        return new Object[] { new float[] { Float.NaN }, new double[] { Double.NaN } };
    } catch (MaxCountExceededException e) {
        return new Object[] { new float[] { Float.NaN }, new double[] { Double.NaN } };
    }
}

From source file:com.l2jfree.gameserver.util.Util.java

public final static int calculateHeadingFrom(int obj1X, int obj1Y, int obj2X, int obj2Y) {
    double angleTarget = Math.toDegrees(Math.atan2(obj2Y - obj1Y, obj2X - obj1X));

    return (int) getValidHeading(angleTarget * 182.044444444);
}

From source file:org.jlab.clas.swimtools.Swim.java

/**
 * Sets the parameters used by swimmer based on the input track parameters
 *
 * @param x0//from  w w w  .j  a  va 2  s .  c om
 * @param y0
 * @param z0
 * @param px
 * @param py
 * @param pz
 * @param charge
 */
public void SetSwimParameters(double x0, double y0, double z0, double px, double py, double pz, int charge) {
    _x0 = x0 / 100;
    _y0 = y0 / 100;
    _z0 = z0 / 100;
    this.checkR(_x0, _y0, _z0);
    _phi = Math.toDegrees(FastMath.atan2(py, px));
    _pTot = Math.sqrt(px * px + py * py + pz * pz);
    _theta = Math.toDegrees(Math.acos(pz / _pTot));

    _charge = charge;

}

From source file:com.l2jfree.gameserver.util.Util.java

public final static int calculateHeadingFrom(double dx, double dy) {
    double angleTarget = Math.toDegrees(Math.atan2(dy, dx));

    return (int) getValidHeading(angleTarget * 182.044444444);
}

From source file:org.apache.flink.table.runtime.functions.SqlFunctionUtils.java

public static double degrees(Decimal angrad) {
    return Math.toDegrees(angrad.doubleValue());
}

From source file:gr.iit.demokritos.cru.cps.ai.ProfileMerger.java

public ArrayList<Double> CalculateUserTrends(ArrayList<String> users_features) throws ParseException {

    SimpleDateFormat sdfu = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
    ArrayList<Double> result = new ArrayList<Double>();

    for (int i = 0; i < users_features.size(); i++) {
        SimpleRegression regression = new SimpleRegression();
        String[] features = ((String) users_features.get(i)).split(";");

        double average = 0.0;
        double f = 0.0;
        for (String s : features) {

            String[] inside_feature = s.split(",");

            //make timestamp secs
            Date udate = sdfu.parse(inside_feature[1]);
            double sec = udate.getTime();
            average += Double.parseDouble(inside_feature[0]);
            //fix mls regr

            regression.addData(sec, Double.parseDouble(inside_feature[0]));

            average = average / features.length;

            f = Math.atan(regression.getSlope());// atan of slope is the angle of the regression in rad
            if (Double.isNaN(f)) {
                f = 0;//  ww w .  j a v  a  2  s  .  co m
            }
            if (f != 0 && (Math.toDegrees(f) > 90 || Math.toDegrees(f) < -90)) {
                if ((Math.toDegrees(f) / 90) % 2 == 0) {//make angles in [-90,90]
                    f = Math.toDegrees(f) % Math.toDegrees(Math.PI / 2);
                } else {
                    f = -Math.toDegrees(f) % Math.toDegrees(Math.PI / 2);
                }
            }
            f = f + Math.PI / 2;//refrain trend=0                    

        }

        result.add(f);
        result.add(f * average);

    }
    return result;

}

From source file:org.interpss.core.adapter.psse.aclf.SixBus_DclfPsXfr.java

@Test
public void dclfRef() throws Exception {
    IpssCorePlugin.init();/*  www.j  a v a2s .c  o m*/
    //IpssCorePlugin.setSparseEqnSolver(SolverType.Native);
    ODMLogger.getLogger().setLevel(Level.WARNING);

    AclfNetwork net = IpssAdapter.importAclfNet("testData/adpter/psse/v30/SixBus_2WPsXfr.raw")
            .setFormat(IpssAdapter.FileFormat.PSSE).setPsseVersion(PsseVersion.PSSE_30).load().getImportedObj();

    DclfAlgorithm algo = DclfObjectFactory.createDclfAlgorithm(net);

    net.setRefBusId("Bus3");
    net.setRefBusType(RefBusType.USER_DEFINED);

    //      net.getBus("Bus1").setGenP(3.0723);

    algo.calculateDclf();

    //System.out.println(DclfOutFunc.dclfResults(algo, false));
    System.out.println(algo.getBusPower(net.getBus("Bus1")) + ", " + Math.toDegrees(algo.getBusAngle("Bus1")));
    assertTrue(Math.abs(algo.getBusPower(net.getBus("Bus1")) - 1.99) < 0.0001);
    assertTrue(Math.abs(Math.toDegrees(algo.getBusAngle("Bus1")) - 2.848746) < 0.001);

    algo.destroy();
}

From source file:org.interpss.core.adapter.psse.SixBus_DclfPsXfr.java

@Test
public void dclfRef() throws Exception {
    IpssCorePlugin.init();/*from  w ww . j ava2 s. c  o  m*/
    //IpssCorePlugin.setSparseEqnSolver(SolverType.Native);
    ODMLogger.getLogger().setLevel(Level.WARNING);

    AclfNetwork net = IpssAdapter.importAclfNet("testData/psse/v30/SixBus_2WPsXfr.raw")
            .setFormat(IpssAdapter.FileFormat.PSSE).setPsseVersion(PsseVersion.PSSE_30).load().getAclfNet();

    DclfAlgorithm algo = DclfObjectFactory.createDclfAlgorithm(net);

    net.setRefBusId("Bus3");
    net.setRefBusType(RefBusType.USER_DEFINED);

    net.getBus("Bus1").setGenP(3.0723);

    algo.calculateDclf();

    System.out.println(DclfOutFunc.dclfResults(algo, false));
    //System.out.println(algo.getBusPower(net.getAclfBus("Bus1")));
    assertTrue(Math.abs(algo.getBusPower(net.getBus("Bus1")) - 3.0623) < 0.0001);
    assertTrue(Math.abs(Math.toDegrees(algo.getBusAngle("Bus1")) - 4.38) < 0.01);

    algo.destroy();
}

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

/**
 * Sets the Path defining a pattern of motion between two coordinates.
 * The pattern will be translated, rotated, and scaled to fit between the start and end points.
 * The pattern must not be empty and must have the end point differ from the start point.
 *
 * @param patternPath A Path to be used as a pattern for two-dimensional motion.
 *//*from   w w w  . j a  v a 2s.  c o  m*/
public void setPatternPath(Path patternPath) {
    PathMeasure pathMeasure = new PathMeasure(patternPath, false);
    float length = pathMeasure.getLength();
    float[] pos = new float[2];
    pathMeasure.getPosTan(length, pos, null);
    float endX = pos[0];
    float endY = pos[1];
    pathMeasure.getPosTan(0, pos, null);
    float startX = pos[0];
    float startY = pos[1];

    if (startX == endX && startY == endY) {
        throw new IllegalArgumentException("pattern must not end at the starting point");
    }

    mTempMatrix.setTranslate(-startX, -startY);
    float dx = endX - startX;
    float dy = endY - startY;
    float distance = distance(dx, dy);
    float scale = 1 / distance;
    mTempMatrix.postScale(scale, scale);
    double angle = Math.atan2(dy, dx);
    mTempMatrix.postRotate((float) Math.toDegrees(-angle));
    patternPath.transform(mTempMatrix, mPatternPath);
    mOriginalPatternPath = patternPath;
}