Example usage for org.apache.commons.math3.geometry.euclidean.twod Vector2D ZERO

List of usage examples for org.apache.commons.math3.geometry.euclidean.twod Vector2D ZERO

Introduction

In this page you can find the example usage for org.apache.commons.math3.geometry.euclidean.twod Vector2D ZERO.

Prototype

Vector2D ZERO

To view the source code for org.apache.commons.math3.geometry.euclidean.twod Vector2D ZERO.

Click Source Link

Document

Origin (coordinates: 0, 0).

Usage

From source file:edu.snu.leader.discrete.behavior.DoNothing.java

@Override
public void choose() {
    // set velocity to move towards leader's current position
    if (!_agent.getCurrentDestination().subtract(_agent.getCurrentLocation()).equals(Vector2D.ZERO)) {
        _agent.setCurrentVelocity((_agent.getCurrentDestination().subtract(_agent.getCurrentLocation()))
                .normalize().scalarMultiply(_agent.getSpeed()));
    }/*  w  w w.  j  a  v  a  2s.  c  om*/
}

From source file:edu.snu.leader.discrete.behavior.Reached.java

@Override
public void choose() {
    // stop this agent from moving since its in a destination
    _agent.setCurrentVelocity(Vector2D.ZERO);
}

From source file:edu.snu.leader.discrete.behavior.Cancel.java

@Override
public void choose() {
    // dissolve group
    _agent.getGroup().dissolve();//from   ww w .j a  v  a2  s. c  o  m
    // set leader to self
    _agent.setLeader(_agent);
    // set destination to starting location
    _agent.setCurrentDestination(_agent.getInitialLocation());
    // move towards the initial location
    if (!_agent.getCurrentDestination().subtract(_agent.getCurrentLocation()).equals(Vector2D.ZERO)) {
        _agent.setCurrentVelocity((_agent.getCurrentDestination().subtract(_agent.getCurrentLocation()))
                .normalize().scalarMultiply(_agent.getSpeed()));
    }
    // add group to the none group
    _agent.getSimState().noneGroup.addAgent(_agent, _agent.getTime());
}

From source file:edu.snu.leader.discrete.behavior.Follow.java

@Override
public void choose() {
    // set leader to the new leader
    _agent.setLeader(_leader);//from www . j a  v a2s  . c  o  m
    // set group to the leader's group
    _leader.getGroup().addAgent(_agent, _agent.getTime());
    // set destination to the leader's destination
    _agent.setCurrentDestination(_leader.getCurrentLocation());
    // set velocity to move towards leader's current position
    if (!_agent.getCurrentDestination().subtract(_agent.getCurrentLocation()).equals(Vector2D.ZERO)) {
        _agent.setCurrentVelocity((_agent.getCurrentDestination().subtract(_agent.getCurrentLocation()))
                .normalize().scalarMultiply(_agent.getSpeed()));
    }
}

From source file:edu.unc.cs.gamma.rvo.Circle.java

private void setupScenario() {
    // Specify the global time step of the simulation.
    Simulator.instance.setTimeStep(0.25);

    // Specify the default parameters for agents that are subsequently
    // added./*  ww w  .  ja  va 2  s.co m*/
    Simulator.instance.setAgentDefaults(15.0, 10, 10.0, 10.0, 1.5, 2.0, Vector2D.ZERO);

    // Add agents, specifying their start position, and store their goals on
    // the opposite side of the environment.
    final double angle = 0.008 * FastMath.PI;

    for (int i = 0; i < 250; i++) {
        Simulator.instance
                .addAgent(new Vector2D(FastMath.cos(i * angle), FastMath.sin(i * angle)).scalarMultiply(200.0));
        goals.add(Simulator.instance.getAgentPosition(i).negate());
    }
}

From source file:edu.snu.leader.discrete.behavior.Initiate.java

@Override
public void choose() {
    // set leader to self
    _agent.setLeader(_agent);//from  ww w. ja  v a  2  s .c om
    // set group to a new group
    _agent.setGroup(new Group(_agent, _agent.getTime()));
    // set destination to preferred destination
    _agent.setCurrentDestination(_agent.getPreferredDestination().getVector());
    // set current velocity to that of going towards the preferred
    // destination
    if (!_agent.getCurrentDestination().subtract(_agent.getCurrentLocation()).equals(Vector2D.ZERO)) {
        // set velocity to the the destination vector - current location
        // vector, normalized and multiplied by speed
        _agent.setCurrentVelocity((_agent.getCurrentDestination().subtract(_agent.getCurrentLocation()))
                .normalize().scalarMultiply(_agent.getSpeed()));
    }
}

From source file:edu.unc.cs.gamma.rvo.Blocks.java

private void setupScenario() {
    // Specify the global time step of the simulation.
    Simulator.instance.setTimeStep(0.25);

    // Specify the default parameters for agents that are subsequently
    // added./*from   w  w w.  j av a 2  s. c  om*/
    Simulator.instance.setAgentDefaults(15.0, 10, 5.0, 5.0, 2.0, 2.0, Vector2D.ZERO);

    // Add agents, specifying their start position, and store their goals on
    // the opposite side of the environment.
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            Simulator.instance.addAgent(new Vector2D(55.0 + i * 10.0, 55.0 + j * 10.0));
            goals.add(new Vector2D(-75.0, -75.0));

            Simulator.instance.addAgent(new Vector2D(-55.0 - i * 10.0, 55.0 + j * 10.0));
            goals.add(new Vector2D(75.0, -75.0));

            Simulator.instance.addAgent(new Vector2D(55.0 + i * 10.0, -55.0 - j * 10.0));
            goals.add(new Vector2D(-75.0, 75.0));

            Simulator.instance.addAgent(new Vector2D(-55.0 - i * 10.0, -55.0 - j * 10.0));
            goals.add(new Vector2D(75.0, 75.0));
        }
    }

    // Add (polygonal) obstacles, specifying their vertices in
    // counterclockwise order.
    final List<Vector2D> obstacle1 = new ArrayList<>();
    obstacle1.add(new Vector2D(-10.0, 40.0));
    obstacle1.add(new Vector2D(-40.0, 40.0));
    obstacle1.add(new Vector2D(-40.0, 10.0));
    obstacle1.add(new Vector2D(-10.0, 10.0));
    Simulator.instance.addObstacle(obstacle1);

    final List<Vector2D> obstacle2 = new ArrayList<>();
    obstacle2.add(new Vector2D(10.0, 40.0));
    obstacle2.add(new Vector2D(10.0, 10.0));
    obstacle2.add(new Vector2D(40.0, 10.0));
    obstacle2.add(new Vector2D(40.0, 40.0));
    Simulator.instance.addObstacle(obstacle2);

    final List<Vector2D> obstacle3 = new ArrayList<>();
    obstacle3.add(new Vector2D(10.0, -40.0));
    obstacle3.add(new Vector2D(40.0, -40.0));
    obstacle3.add(new Vector2D(40.0, -10.0));
    obstacle3.add(new Vector2D(10.0, -10.0));
    Simulator.instance.addObstacle(obstacle3);

    final List<Vector2D> obstacle4 = new ArrayList<>();
    obstacle4.add(new Vector2D(-10.0, -40.0));
    obstacle4.add(new Vector2D(-10.0, -10.0));
    obstacle4.add(new Vector2D(-40.0, -10.0));
    obstacle4.add(new Vector2D(-40.0, -40.0));
    Simulator.instance.addObstacle(obstacle4);

    // Process the obstacles so that they are accounted for in the
    // simulation.
    Simulator.instance.processObstacles();
}

From source file:edu.snu.leader.spatial.AgentSpatialState.java

/**
 * Reset's the agent's spatial state/*from w w w .  j  av  a2 s.  c o  m*/
 */
public void reset() {
    // Move back to our initial position and stop moving
    _position = _initialPosition;
    _velocity = Vector2D.ZERO;
}

From source file:haxball.networking.ServerMainLoop.java

@Override
public void run() {

    resetField();/*from w ww .j  a v  a2s.c  o  m*/
    byte score0 = 0, score1 = 0;

    while (!stopped) {
        // Move players
        for (Player player : players) {

            byte input = player.getLastInput();

            float vx = 0;
            float vy = 0;

            if ((input & 0b00_00_00_01) != 0) {
                vy += speed;
            }
            if ((input & 0b00_00_00_10) != 0) {
                vx -= speed;
            }
            if ((input & 0b00_00_01_00) != 0) {
                vy -= speed;
            }
            if ((input & 0b00_00_10_00) != 0) {
                vx += speed;
            }
            if ((input & 0b00_01_00_00) != 0) {
                player.setShooting(true);
            } else {
                player.setShooting(false);
            }

            Vector2D v = new Vector2D(vx, vy);
            if (v.distance(Vector2D.ZERO) > 0) {
                v = v.normalize().scalarMultiply(speed);
            }

            player.velocity = player.velocity.add(v.subtract(player.velocity).scalarMultiply(acceleration));
            player.position = player.position.add(player.velocity);
        }

        // Move ball
        ball.velocity = ball.velocity.scalarMultiply(1 - friction);
        ball.position = ball.position.add(ball.velocity);

        // Check for collisions
        for (Player p : players) {
            // collisions between players
            for (Player p0 : players) {
                if (!p.equals(p0)) {
                    p.uncollide(p0);
                }
            }
            p.uncollide(ball);
            p.setInsideMap(true);

            if (p.isShooting()
                    && p.position.distance(ball.position) < (p.getRadius() + ball.getRadius()) * 1.4f) {
                Vector2D norm = ball.position.subtract(p.position).normalize();
                ball.velocity = ball.velocity.add(norm.scalarMultiply(shootingPower));
            }

        }
        int result;
        if ((result = ball.setInsideMap(false)) >= 0) {
            if (result == 0) {
                score0++;
            } else {
                score1++;
            }
            resetField();
        }

        // send position to every connection
        for (ConnectionHandler handler : connectionHandlers) {
            handler.writeState(ball, score0, score1, players);
        }
        // sleep
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    } // while !stopped
}

From source file:edu.snu.leader.discrete.behavior.SimpleAngularMovement.java

@Override
public void move() {
    boolean isInDestination = false;

    // if agents should stop at any destination
    if (_agent.getSimState().shouldStopAnywhere()) {
        // iterate through all the destinations
        Iterator<Vector2D> destinations = _agent.getSimState().getDestinationsIterator();
        while (destinations.hasNext()) {
            // get next destination to check
            Vector2D temp = destinations.next();
            // if the agent is inside this destination
            if (_agent.getCurrentLocation().distance(temp) < _agent.getPreferredDestination().getRadius()) {
                // agent reached the destination
                _agent.reachedDestination();
                // set whether it was good or not
                _agent.setReachedGoodDestination(_agent.getLeader().getPreferredDestination().isGood());
                // agent is now in a destination
                isInDestination = true;//from w w  w. ja v  a  2 s.  c  o m
            }
        }
    }

    if (isInDestination) {
        // nothing to do here
    }
    // if agent is initiating and is within their destination then they have
    // reached their destination
    else if (!_agent.getPreferredDestination().getID().equals("D-N")
            && _agent.getCurrentLocation().distance1(_agent.getPreferredDestination().getVector()) < _agent
                    .getPreferredDestination().getRadius()) {
        _agent.reachedDestination();
    }
    // if they are moving back towards the start, make sure the stop before
    // going through it
    else if (_agent.getGroup().getId().equals(_agent.getSimState().noneGroup.getId())
            && _agent.getCurrentLocation().distance(
                    _agent.getInitialLocation()) < _agent.getSimState().startingDestination.getRadius()) {
        _agent.setCurrentVelocity(Vector2D.ZERO);
    }
    // otherwise move normally
    else {
        _agent.setCurrentLocation(_agent.getCurrentLocation().add(_agent.getCurrentVelocity()));
    }
}