Example usage for org.apache.commons.math.geometry Vector3D getAlpha

List of usage examples for org.apache.commons.math.geometry Vector3D getAlpha

Introduction

In this page you can find the example usage for org.apache.commons.math.geometry Vector3D getAlpha.

Prototype

public double getAlpha() 

Source Link

Document

Get the azimuth of the vector.

Usage

From source file:magma.agent.behavior.complex.GetToInitialPosition.java

/**
 * calculates a point on a circle from the own goal to which to go
 *///www  .  j  a v  a  2  s . com
private boolean getCurrentBehavior() {
    IThisPlayer thisPlayer = worldModel.getThisPlayer();
    Vector3D home = thisPlayer.getHomePosition("doesNotMatter");
    Vector3D ourPos = thisPlayer.getPosition();
    Vector3D ownGoal = worldModel.getOwnGoalPosition();
    Vector3D ball = worldModel.getBall().getPosition();
    double distanceX = IServerConfigFilesConstants.FIELD_LENGTH - Math.abs(home.getX());

    // destination position is certain distance from goal in line with ball
    Vector3D goalBallDir = new Vector3D(distanceX, ball.subtract(ownGoal).normalize());
    Vector3D goalBall = ownGoal.add(goalBallDir);

    setPosition((float) goalBall.getX(), (float) goalBall.getY(), (float) goalBall.getAlpha());
    double directionToTarget = thisPlayer.getBodyDirectionTo(position).degrees();

    rotation = (float) directionToTarget;
    float distanceToTarget = (float) thisPlayer.getDistanceToXY(position);

    if (distanceToTarget < DISTANCE_PRECISION) {
        directionToTarget = thisPlayer.getBodyDirectionTo(ball).degrees();
        rotation = (float) directionToTarget;
    }

    logger.log(Level.FINE,
            "initial pos: ({0},{1}) distanceToTarget: {2} directionToTarget: {3} " + "ourpos: ({4},{5})",
            new Object[] { goalBall.getX(), goalBall.getY(), distanceToTarget, directionToTarget, ourPos.getX(),
                    ourPos.getY() });

    if (distanceToTarget < DISTANCE_PRECISION) {
        // we are at the desired position
        // make sure that we are also in desired direction
        if (!turnedLeftBefore && directionToTarget > ANGULAR_PRECISION && directionToTarget <= 90) {
            turnLeft(directionToTarget);
            return true;
        }

        if (!turnedLeftBefore && directionToTarget < -ANGULAR_PRECISION && directionToTarget >= -90) {
            turnRight(directionToTarget - 180);
            return true;
        }

        if (!turnedLeftBefore && directionToTarget > 90 && directionToTarget < (180 - ANGULAR_PRECISION)) {
            turnRight(directionToTarget - 180);
            return true;
        }

        if (!turnedRightBefore && directionToTarget < -90 && directionToTarget > -180 + ANGULAR_PRECISION) {
            turnLeft(180 + directionToTarget);
            return true;
        }
    }

    if (directionToTarget > 50 && directionToTarget < 130) {
        // position is left
        currentBehavior = behaviors.get(IBehavior.STEP_LEFT);
        return true;
    }

    if (directionToTarget < -50 && directionToTarget > -130) {
        // position is right
        currentBehavior = behaviors.get(IBehavior.STEP_RIGHT);
        return true;
    }

    if (directionToTarget > 90 || directionToTarget < -90) {
        // or do we prefer to turn
        if (!turnedLeftBefore && directionToTarget > 0 && directionToTarget < (180 - ANGULAR_PRECISION)) {
            turnRight(directionToTarget - 180);
            return true;
        }

        if (!turnedRightBefore && directionToTarget < -ANGULAR_PRECISION) {
            turnLeft(180 + directionToTarget);
            return true;
        }
        currentBehavior = behaviors.get(IBehavior.STEP_BACKWARD);
        return true;
    }
    return false;
}

From source file:magma.agent.behavior.complex.GetInScorePosition.java

double[] getPosition() {
    Vector3D ballPosition = worldModel.getBall().getPosition();
    IThisPlayer thisPlayer = worldModel.getThisPlayer();

    Vector3D shootVector = worldModel.getOtherGoalPosition().subtract(ballPosition);
    Vector3D scorePosition = ballPosition.add(-0.25, shootVector.normalize());

    if (thisPlayer.getDistanceTo(ballPosition) < thisPlayer.getDistanceTo(scorePosition)) {
        Angle delta1 = thisPlayer.getDirectionTo(ballPosition)
                .subtract(thisPlayer.getDirectionTo(scorePosition));
        double delta = Math.abs(delta1.degrees());

        if (delta < 90) {
            // We have to run around the ball
            scorePosition = calculateAlternativePosition(ballPosition, thisPlayer, scorePosition);
        } else if (delta < 140) {
            scorePosition = ballPosition.add(-BALL_KEEP_AWAY_DISTANCE, shootVector.normalize());
        }/* w  ww. ja v a 2 s  .  co m*/
    }
    return new double[] { scorePosition.getX(), scorePosition.getY(), shootVector.getAlpha() };
}