Package eas.math.geometry

Examples of eas.math.geometry.Vector2D


        for (int i = 0; i < list.size(); i++) {
            this.setAgentAngleAndPositionAndScaleSimultaneously(
                    list.get(i).id(),
                    this.vecPhysToVec2D(list.get(i).getPosition()),
                    list.get(i).getRotation() / Math.PI * 180,
                    new Vector2D(1, 1));
        }
    }
View Full Code Here


      }

      @Override
      public Integer sense(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
        int result = -1;
        Vector2D angle= new Vector2D(env.getNormalizedLOV(agent.id()).x,env.getNormalizedLOV(agent.id()).y);
        angle.rotate(Vector2D.NULL_VECTOR, -45+0*(90/(3-1.0))*Math.PI/180);

        CollisionData coll = env.nearestRayCollision(
            env.getAgentPosition(agent.id()),
            angle,
            agent);

        if ((coll.getCollisionPoint()!=null&&coll.getCollisionPoint().distance(env.getAgentPosition(agent.id()))<15)){
          result = coll.getAgent().id();
        }

        return result;
      }
    });

    this.addSensor(new GenericSensor<Integer, AbstractEnvironment2D<AbstractAgent2D<?>>, AbstractAgent2D<?>>() {

      /**
             *
             */
            private static final long serialVersionUID = 187236060508880836L;

            @Override
      public String id() {
        return "sensing-agent-1";
      }

      @Override
      public Integer sense(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
        int result = -1;
        Vector2D angle= new Vector2D(env.getNormalizedLOV(agent.id()).x,env.getNormalizedLOV(agent.id()).y);
        angle.rotate(Vector2D.NULL_VECTOR, -45+1*(90/(3-1.0))*Math.PI/180);

        CollisionData coll = env.nearestRayCollision(
            env.getAgentPosition(agent.id()),
            angle,
            agent);

        if ((coll.getCollisionPoint()!=null&&coll.getCollisionPoint().distance(env.getAgentPosition(agent.id()))<15)){
          result = coll.getAgent().id();
        }

        return result;
      }
    });

    this.addSensor(new GenericSensor<Integer, AbstractEnvironment2D<AbstractAgent2D<?>>, AbstractAgent2D<?>>() {

      /**
             *
             */
            private static final long serialVersionUID = -2034243692637537731L;

            @Override
      public String id() {
        return "sensing-agent-2";
      }

      @Override
      public Integer sense(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
        int result = -1;
        Vector2D angle= new Vector2D(env.getNormalizedLOV(agent.id()).x,env.getNormalizedLOV(agent.id()).y);
        angle.rotate(Vector2D.NULL_VECTOR, -45+2*(90/(3-1.0))*Math.PI/180);

        CollisionData coll = env.nearestRayCollision(
            env.getAgentPosition(agent.id()),
            angle,
            agent);

        if ((coll.getCollisionPoint()!=null&&coll.getCollisionPoint().distance(env.getAgentPosition(agent.id()))<15)){
          result = coll.getAgent().id();
        }

        return result;
      }
    });

    this.addSensor(new GenericSensor<Boolean, AbstractEnvironment2D<AbstractAgent2D<?>>, AbstractAgent2D<?>>() {

      /**
             *
             */
            private static final long serialVersionUID = 3223404861645168405L;

            @Override
      public String id() {
        return "sheepInDetectionRadius";
      }

      @Override
      public Boolean sense(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
        Boolean result=false;
        double detectionRadius = ((WolfAgent) env.getAgent(agent.id())).getDetectionRadius();
        for (AbstractAgent<?> agentX: env.getAgents() ){
          double distance = env.getAgentPosition(agent.id()).distance(env.getAgentPosition(agentX.id()));
          if (agentX.id()>=10 && agentX.id()%2==0 && distance<=detectionRadius){ //isSheepInSight
            result=true;
            break;
          }
        }
        return result;
      }
    });

    this.addSensor(new GenericSensor<Vector2D, AbstractEnvironment2D<AbstractAgent2D<?>>, AbstractAgent2D<?>>() {

      /**
             *
             */
            private static final long serialVersionUID = -3733776000131900630L;

            @Override
      public String id() {
        return "targetPositionInDetectionRadius";
      }

      @Override
      public Vector2D sense(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
        Vector2D result=null;
        double detectionRadius = ((WolfAgent) env.getAgent(agent.id())).getDetectionRadius();
        if (target!=null){
          double distance = env.getAgentPosition(agent.id()).distance(env.getAgentPosition(target.id()));
          if(target!=null && target.id()>=10 && target.id()%2==0 && distance<=detectionRadius){
            result=env.getAgentPosition(target.id());
          }
        }
        return result;
      }
    });

    this.addSensor(new GenericSensor<Integer, AbstractEnvironment2D<AbstractAgent2D<?>>, AbstractAgent2D<?>>() {

      /**
             *
             */
            private static final long serialVersionUID = 1300915943928511209L;

            @Override
      public String id() {
        return "targetID";
      }

      @Override
      public Integer sense(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
        int result=-1;
        if(target!=null){
          result=target.id();
        }
        return result;
      }
    });


    this.addActuator(new GenericActuator<CoEvolutionEnv, AbstractAgent2D<?>>() {
      /**
             *
             */
            private static final long serialVersionUID = -5017791341484085564L;

            @Override
      public String id() {
        return "drive";
      }

      @Override
      public void actuate(CoEvolutionEnv env, AbstractAgent2D<?> agent) {
        if(env.differentialDriveForward(agent.id())){
          //no collision
        } else{
          env.unfallSimulation(env.getAgent(agent.id()),360);
        }
      }
    });

    this.addActuator(new GenericActuator<AbstractEnvironment2D<AbstractAgent2D<?>>, AbstractAgent2D<?>>() {
      /**
             *
             */
            private static final long serialVersionUID = -6021940550682006287L;
            @Override
      public String id() {
        return "chooseSheep";
      }
      @Override
      public void actuate(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
        List<AbstractAgent<?>> sheepAgentsInSight = new LinkedList<AbstractAgent<?>>();
        double detectionRadius = ((WolfAgent) env.getAgent(agent.id())).getDetectionRadius();
        for (AbstractAgent<?> agentX: env.getAgents() ){
          double distance = env.getAgentPosition(agent.id()).distance(env.getAgentPosition(agentX.id()));
          if (agentX.id()>=10 && agentX.id()%2==0 && distance<=detectionRadius){ //isSheepInSight
            sheepAgentsInSight.add(agentX);
          }
        }

        SheepAgent targetSheep;
        if (sheepAgentsInSight.size()==0){
          targetSheep=null;
        }
        else{
          targetSheep = (SheepAgent) sheepAgentsInSight.get(random.nextInt(sheepAgentsInSight.size()));
        }
        target = targetSheep;
      }
    });

    this.addActuator(new GenericActuator<AbstractEnvironment2D<AbstractAgent2D<?>>, AbstractAgent2D<?>>() {

      /**
             *
             */
            private static final long serialVersionUID = 7636597494956377900L;

            @Override
      public String id() {
        return "focus";
      }

      @Override
      public void actuate(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
        if (target!=null){
          Vector2D ownPosition = env.getAgentPosition(agent.id());
          Vector2D targetPosition = env.getAgentPosition(target.id());
          Vector2D direction = new Vector2D(-ownPosition.x+targetPosition.x,-ownPosition.y+targetPosition.y);
          double angle = new Vector2D (0,-1).angle(direction)*180/Math.PI;
          if (targetPosition.x<ownPosition.x){
            env.setAgentAngle(agent.id(), 180-angle);
          }
          else{
            env.setAgentAngle(agent.id(), 180+angle);
          }
        }
      }
    });

    this.addActuator(new GenericActuator<AbstractEnvironment2D<AbstractAgent2D<?>>, AbstractAgent2D<?>>() {
      /**
             *
             */
            private static final long serialVersionUID = -468119785924419114L;

            @Override
      public String id() {
        return "avoid-collision";
      }

      @Override
      public void actuate(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
        env.differentialDriveBackward(agent.id());
      }
    });

    this.addActuator(new GenericActuator<AbstractEnvironment2D<AbstractAgent2D<?>>, AbstractAgent2D<?>>() {
      /**
             *
             */
            private static final long serialVersionUID = 7180465767124900868L;

            @Override
      public String id() {
        return "change-angle";
      }

      @Override
      public void actuate(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
        double randomAngle = random.nextDouble()*360;
        env.setAgentAngle(agent.id(), randomAngle);
      }
    });   

    this.addActuator(new GenericActuator<CoEvolutionEnv, AbstractAgent2D<?>>() {
      /**
             *
             */
            private static final long serialVersionUID = -5762477080882311524L;
            @Override
      public String id() {
        return "catchSheepIfPossible";
      }
      @Override
      public void actuate(CoEvolutionEnv env, AbstractAgent2D<?> agent) {
        SheepAgent randomReachedSheepAgent;
        if (target!=null&&env.getAgentPosition(agent.id()).distance(env.getAgentPosition(target.id()))<=((WolfAgent)agent).getCatchRadius()){
          long now = env.getSimTime().getCurrentTime().getLastTick();
          if (catchReturnValues==null){
            catchReturnValues = new HashSet<Long>();
          }         
          catchReturnValues.add(now - lastTimeSheepCaught)//add new catch record using autoboxing
          lastTimeSheepCaught = now;
          env.replaceBrain(target.id(), random);
          env.setRandomPosition(target.id(), random);
          target=null;
        } else if (env.getAgentPosition(agent.id()).distance(env.getAgentPosition(env.nearestAgent(agent).id()))<=((WolfAgent)agent).getCatchRadius()
            && env.nearestAgent(agent).id()%2==0
            && env.nearestAgent(agent).id()>=10){
          randomReachedSheepAgent =(SheepAgent) env.nearestAgent(agent);
          long now = env.getSimTime().getCurrentTime().getLastTick();
          if (catchReturnValues==null){
            catchReturnValues = new HashSet<Long>();
          }         
          catchReturnValues.add(now - lastTimeSheepCaught)//add new catch record using autoboxing
          lastTimeSheepCaught = now;
          env.replaceBrain(randomReachedSheepAgent.id(), random);
          env.setRandomPosition(randomReachedSheepAgent.id(), random);
        }
      }
    });

    this.shape = new Polygon2D();
    this.shape.add(new Vector2D(-.5, .5));
    this.shape.add(new Vector2D(0, 0));
    this.shape.add(new Vector2D(.5, .5));
    this.shape.add(new Vector2D(.5, -.5));
    this.shape.add(new Vector2D(-.5, -.5));
  }
View Full Code Here

     */
    @Override
    public synchronized Polygon2D getAgentShape() {
        if (pol == null) {
            pol = new Polygon2D();
            pol.add(new Vector2D(-1, -1));
            pol.add(new Vector2D(1, -1));
            pol.add(new Vector2D(1, 1));
            pol.add(new Vector2D(-1, 1));
        }
        return pol;
    }
View Full Code Here

      return "distance-" + sensorNumber;
    }

    @Override
    public Double sense(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
      Vector2D angle= new Vector2D(env.getNormalizedLOV(agent.id()).x,env.getNormalizedLOV(agent.id()).y);
      if (numberOfDistanceSensors>1)
        angle.rotate(Vector2D.NULL_VECTOR, -45+sensorNumber*(90/(numberOfDistanceSensors-1.0))*Math.PI/180);
      Vector2D poi = env.nearestRayCollision(
          env.getAgentPosition(agent.id()),
          angle,
          agent).getCollisionPoint();
      if (poi == null) {
        return Double.POSITIVE_INFINITY;
View Full Code Here

        // Kollisionen
        int fitKoll = (int) (rob.getAnzUnfaelle()
                 * rob.getPars().getParValueDouble(EAPlugin.UNFALL_ABZUG));
        rob.resetAnzUnf();
        double abstand1, abstand2;
        Vector2D mitte1, mitte2;
       
        // Aus Collision avoidance (nur MOVE-Teil):
        int bef0 = (rob.getBefehle().get(0)).intValue();
        String befehl0 = eas.simulation.ConstantsSimulation.befehlName(bef0, rob.getPars()).toUpperCase();
        int fitCollAvoid = 1;
View Full Code Here

            final double precision = 7;
            pacman = new Polygon2D();
            final double beg = -1 * Math.PI / 8;
           
            for (double d = beg; d < Math.PI * 2.1 + beg; d += Math.PI * 2 / precision) {
                pacman.add(new Vector2D(Math.sin(d) * radius, Math.cos(d) * radius));
            }
//            pacman.add(new Vector2D(0, 0));
            pacman.rotate(Vector2D.NULL_VECTOR, -Math.PI * 0.125);
           
//            pacman = new CircleAsPolygon2D(new Vector2D(0, 0), radius);
View Full Code Here

 
  @Override
  public Polygon2D getAgentShape() {
    if (shape == null) {
      shape = new Polygon2D();
      shape.add(new Vector2D(0.5, 0.5));
      shape.add(new Vector2D(-0.5, 0.5));
      shape.add(new Vector2D(-0.5, -0.5));
      shape.add(new Vector2D(0.5, -0.5));
      }
      return shape;
  }
View Full Code Here

            final double precision = 60;
            final double radius = 1;
            circle = new Polygon2D();
           
            for (double d = 0; d < Math.PI * 2; d += Math.PI * 2 / precision) {
                circle.add(new Vector2D(Math.sin(d) * radius, Math.cos(d) * radius));
            }
        }
       
        return circle;
    }
View Full Code Here

     * @param rob  Der Roboter, dessen Positionierung bestimmt werden soll.
     *
     * @return  Der Quadrant des Roboters.
     */
    private String quadrant(final RobEA rob) {
        Vector2D mitte = rob.getEnvironmentEA().getDynWaende()[221].centerPoint();
        Vector2D robPos = rob.getPosition();
        String quadrant = "";
       
        if (robPos.x > mitte.x && robPos.y > mitte.y) {
            quadrant = "SO";
        }
View Full Code Here

   
    int i = 0;
    //Cleaning Agents
    for (; i < 30; i++) {
      env.addCollidingAgent(new CleaningAgent(i, env, params),
          new Vector2D(
              rand.nextInt(env.getWidth()),
              rand.nextInt(env.getHeight())),
          0,
          new Vector2D(0.5,0.5));
     
    }
   
    //Dirt Agents
    for (; i < 40; i++) {
      env.addCollidingAgent(new DirtAgent(i, env, params),
          new Vector2D(
              rand.nextInt(env.getWidth()),
              rand.nextInt(env.getHeight())),
          0,
          new Vector2D(0.5,0.5));
     
    }
   
    return new CleaningEnvironment[] {env};
  }
View Full Code Here

TOP

Related Classes of eas.math.geometry.Vector2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.