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:magma.agent.behavior.complex.RunToBall.java

@Override
public void perform(float intensity) {

    if (currentBehavior == null || currentBehavior.isFinished()) {
        double ballAngle = Math.toDegrees(worldModel.getBall().getHorizontalDirection());

        logger.log(Level.FINE, "runToBall angle: {0}", ballAngle);

        if (ballAngle > 40) {
            currentBehavior = behaviors.get(IBehavior.TURN_LEFT_40);
        } else if (ballAngle < -40) {
            currentBehavior = behaviors.get(IBehavior.TURN_RIGHT_40);
        } else {/*from  ww  w.j  a v a  2 s . c  om*/
            currentBehavior = behaviors.get(IBehavior.WALK);
        }

        // Calculate whether the straight line between player and ball hits the
        // goal
        IThisPlayer thisPlayer = worldModel.getThisPlayer();
        IMoveableObject ball = worldModel.getBall();
        Vector3D ballPos = ball.getPosition();
        Vector3D ownPos = thisPlayer.getPosition();
        // double goalDistance = thisPlayer.getDistanceTo(worldModel
        // .getOtherGoalPosition());
        // double ownGoalDistance = thisPlayer.getDistanceTo(worldModel
        // .getOwnGoalPosition());
        Angle ballAngle1 = thisPlayer.getBodyDirectionTo(ballPos);
        // Angle goalAngle1 = thisPlayer.getBodyDirectionTo(worldModel
        // .getOtherGoalPosition());
        // Angle delta = goalAngle1.subtract(ballAngle1);

        double ballAngle2 = ballAngle1.degrees();
        // double goalAngle = goalAngle1.degrees();

        // Calculate the position where the straight line through the player
        // and
        // the ball will cross the end of the field

        double m = 0;
        double b = 0;

        // Decide on which goal are we playing and calculate the straight line
        double x = worldModel.getOtherGoalPosition().getX();
        if (x < 0) {
            // Playing to the left goal
            m = (ballPos.getY() - ownPos.getY()) / (ballPos.getX() - ownPos.getX());

            b = ballPos.getY() - m * ownPos.getX();

        } else {
            // Playing to the right goal
            m = (ownPos.getY() - ballPos.getY()) / (ownPos.getX() - ballPos.getX());

            b = ownPos.getY() - m * ballPos.getX();

        }

        // Calculate the Y point of the goal line where the ball will cross the
        // line if we perform a straight kick
        double y = m * x + b;

        // The straight line will not hit the goal
        logger.log(Level.FINE, "runToBall2 ballAngle2: {0} y:{1}", new Object[] { ballAngle2, y });

        if (y > 0.7 && ballAngle2 < 15) {
            currentBehavior = behaviors.get(IBehavior.TURN_RIGHT_40);
        } else if (y < -0.7 && ballAngle2 > -15) {
            currentBehavior = behaviors.get(IBehavior.TURN_LEFT_40);
        } else {
            currentBehavior = behaviors.get(IBehavior.WALK);
        }

        currentBehavior.init();
    }

    currentBehavior.perform(intensity);
}

From source file:it.inserpio.mapillary.gopro.importer.matcher.Image2GeoMatcher.java

/**
 * Determine GPSImgDirection/*from  w  w w  .  ja v a 2  s  .  c  om*/
 * 
 * @param dateTimePoint1
 * @param dateTimePoint2
 * @return
 */
public static double computeGPSImgDirection(GPXDateTimePoint dateTimePoint1, GPXDateTimePoint dateTimePoint2) {
    double deltaY = dateTimePoint1.getLatitude() - dateTimePoint2.getLatitude();
    double deltaX = dateTimePoint1.getLongitude() - dateTimePoint2.getLongitude();

    double degrees = Math.toDegrees(Math.atan2(deltaY, deltaX));

    if (degrees < 0) {
        degrees = 360 + degrees;
    }

    return degrees;
}

From source file:magma.agent.perception.impl.VisibleObjectPerceptor.java

@Override
public double getLatitudeAngleDeg() {
    return Math.toDegrees(position.getDelta());
}

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

public static float getYRotationAngle(GVRSceneObject rotatingObject, GVRTransform targetObject) {
    return (float) Math
            .toDegrees(Math.atan2(targetObject.getPositionX() - rotatingObject.getTransform().getPositionX(),
                    targetObject.getPositionZ() - rotatingObject.getTransform().getPositionZ()));
}

From source file:edu.mit.fss.tutorial.part2.MobileElement.java

@Override
public double getLongitude() {
    return Math.toDegrees(Math.atan2(position.getY(), position.getX()));
}

From source file:org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord.java

public double distance(ZipcodeRecord other) {
    if (other.getZipcode().equals(zipcode))
        return 0.0;

    Pair<Double, Double> otherCoords = other.getCoordinates();

    double dist = Math.sin(Math.toRadians(coordinates.getLeft()))
            * Math.sin(Math.toRadians(otherCoords.getLeft()))
            + Math.cos(Math.toRadians(coordinates.getLeft())) * Math.cos(Math.toRadians(otherCoords.getLeft()))
                    * Math.cos(Math.toRadians(coordinates.getRight() - otherCoords.getRight()));
    dist = Math.toDegrees(Math.acos(dist)) * 69.09;

    return dist;/*  ww  w  .j a  v  a 2  s  . c o  m*/
}

From source file:org.apache.bigtop.datagenerators.locations.Location.java

public double distance(Pair<Double, Double> otherCoords) {
    if (Math.abs(coordinates.getLeft() - otherCoords.getLeft()) < 1e-5
            || Math.abs(coordinates.getRight() - otherCoords.getRight()) < 1e-5)
        return 0.0;

    double dist = Math.sin(Math.toRadians(coordinates.getLeft()))
            * Math.sin(Math.toRadians(otherCoords.getLeft()))
            + Math.cos(Math.toRadians(coordinates.getLeft())) * Math.cos(Math.toRadians(otherCoords.getLeft()))
                    * Math.cos(Math.toRadians(coordinates.getRight() - otherCoords.getRight()));
    dist = Math.toDegrees(Math.acos(dist)) * 69.09;

    return dist;// w w  w.ja v a  2  s. c  o m
}

From source file:uk.ac.diamond.scisoft.analysis.diffraction.powder.PixelIntegrationUtils.java

public static Dataset generateAzimuthalArray(double[] beamCentre, int[] shape, boolean radians) {

    Dataset out = DatasetFactory.zeros(shape, Dataset.FLOAT64);
    PositionIterator iter = out.getPositionIterator();

    int[] pos = iter.getPos();

    //+0.5 for centre of pixel
    while (iter.hasNext()) {
        double val = Math.atan2(pos[0] + 0.5 - beamCentre[1], pos[1] + 0.5 - beamCentre[0]);
        if (radians)
            out.set(val, pos);
        else/*from  w  ww  . j a va2s.com*/
            out.set(Math.toDegrees(val), pos);
    }

    return out;
}

From source file:org.interpss.mapper.bean.aclf.BaseAclfNet2BeanMapper.java

/**
 * map an AclfBus object to an AclfBusBean 
 * //from  www.  j av  a 2s .  com
 * @param bus
 * @param bean
 */
public static void mapBaseBus(AclfBus bus, AclfBusBean bean) {
    bean.number = bus.getNumber();
    bean.id = bus.getId();
    bean.name = bus.getName();
    boolean status = bus.isActive();
    bean.status = 1;
    if (!status)
        bean.status = 0;
    bean.base_v = bus.getBaseVoltage() / 1000;
    bean.v_mag = format(bus.getVoltageMag());
    bean.v_ang = format(bus.getVoltageAng(UnitType.Deg));
    bean.vDesired_mag = format(bus.getDesiredVoltMag());
    bean.vDesired_ang = format(Math.toDegrees(bus.getDesiredVoltAng()));
    //bean.vmax = format(bus.getVLimit().getMax()) == 0? bean.vmax : format(bus.getVLimit().getMax());
    //bean.vmin = format(bus.getVLimit().getMin()) == 0? bean.vmin : format(bus.getVLimit().getMin());

    bean.vmax = format(bus.getVLimit().getMax());
    bean.vmin = format(bus.getVLimit().getMin());

    bean.gen_code = bus.isGenPQ() ? AclfBusBean.GenCode.PQ
            : (bus.isGenPV() ? AclfBusBean.GenCode.PV
                    : (bus.isSwing() ? AclfBusBean.GenCode.Swing : AclfBusBean.GenCode.NonGen));

    Complex gen = bus.getNetGenResults();
    bean.lfGenResult = new ComplexBean(format(gen));

    double genp = bus.getGenP();
    double genq = bus.getGenQ();
    bean.gen = new ComplexBean(format(new Complex(genp, genq)));

    if (bus.getPGenLimit() != null) {
        bean.pmax = bus.getPGenLimit().getMax();
        bean.pmin = bus.getPGenLimit().getMin();
    }
    if (bus.getQGenLimit() != null) {
        bean.qmax = bus.getQGenLimit().getMax();
        bean.qmin = bus.getQGenLimit().getMin();
    }
    if (bus.isRemoteQBus()) {
        if (bus.getRemoteQBus() != null)
            if (bus.getRemoteQBus().getRemoteBus() != null) {
                String remoteBusId = bus.getRemoteQBus().getRemoteBus().getId();
                bean.remoteVControlBusId = remoteBusId;
            }
    }

    bean.load_code = bus.isConstPLoad() ? AclfBusBean.LoadCode.ConstP
            : (bus.isConstZLoad() ? AclfBusBean.LoadCode.ConstZ
                    : (bus.isConstILoad() ? AclfBusBean.LoadCode.ConstI : AclfBusBean.LoadCode.NonLoad));

    Complex load = bus.getNetLoadResults();
    bean.lfLoadResult = new ComplexBean(format(load));

    double loadp = bus.getLoadP();
    double loadq = bus.getLoadQ();
    bean.load = new ComplexBean(format(new Complex(loadp, loadq)));

    Complex sh = bus.getShuntY();
    bean.shunt = new ComplexBean(format(sh));

    bean.area = 1;
    bean.zone = 1;
    bean.areaName = "";
    bean.zoneName = "";
    if (bus.getArea() != null) {
        bean.area = bus.getArea().getNumber();
        bean.areaName = bus.getArea().getName();
    }
    if (bus.getZone() != null) {
        bean.zone = bus.getZone().getNumber();
        bean.zoneName = bus.getZone().getName();
    }

    // map switched shunt data
    if (bus.getSwitchedShunt() != null) {
        SwitchedShunt ss = bus.getSwitchedShunt();
        SwitchShuntBean ssb = new SwitchShuntBean();
        mapSwitchShuntData(ss, ssb);
        bean.switchShunt = ssb;
    }
}

From source file:org.hbird.business.navigation.processors.orekit.ElevationCalculator.java

/**
 * @see org.hbird.business.navigation.processors.orekit.IContactDetailCalculator#calculate(org.orekit.propagation.SpacecraftState,
 *      org.orekit.propagation.SpacecraftState, org.orekit.frames.TopocentricFrame, org.orekit.frames.Frame,
 *      org.hbird.exchange.navigation.LocationContactEvent)
 *//* w  ww. j  a v a 2  s  .co  m*/
@Override
public void calculate(SpacecraftState startState, SpacecraftState endState, TopocentricFrame locationOnEarth,
        Frame inertialFrame, LocationContactEvent event) throws OrekitException {

    double startElevation = calculateElevation(startState, locationOnEarth, inertialFrame);
    double endElevation = calculateElevation(startState, locationOnEarth, inertialFrame);
    double maxElevation = calculateMaxElevation(startState, endState.getDate(), locationOnEarth, inertialFrame,
            calculationStep);
    double minElevation = Math.min(startElevation, endElevation);
    ExtendedContactParameterRange range = new ExtendedContactParameterRange(Math.toDegrees(startElevation),
            Math.toDegrees(endElevation));
    range.setMax(Math.toDegrees(maxElevation));
    range.setMin(Math.toDegrees(minElevation));
    event.setElevation(range);
}