Package eas.math.geometry

Examples of eas.math.geometry.Vector2D


        return eas.simulation.ConstantsSimulation.DEFAULT_MASTER_SCHEDULER_ID
                + "-co";
    }

    public Vector2D getRandomVector2D(Random random) {
        Vector2D result = null;
        result = new Vector2D(24 + random.nextDouble() * (476 - 34), 14
                + random.nextDouble() * (496 - 24));
        return result;
    }
View Full Code Here


        1, params);
   
    //env.addCollidingAgent(agent, position, angle, scale)
    env.addCollidingAgent(                                    //oben
            new ObstacleAgent(0, null, null),
            new Vector2D(250, -5),
            0,
            new Vector2D(4, 1));
    env.addCollidingAgent(                                    //unten
            new ObstacleAgent(1, null, null),
            new Vector2D(250, 1200),
            0,
            new Vector2D(4, 1));
    env.addCollidingAgent(                                    //links
            new ObstacleAgent(2, null, null),
            new Vector2D(-740, 597),
            90,
            new Vector2D(2.365, 1));
    env.addCollidingAgent(                                    //rechts
            new ObstacleAgent(3, null, null),
            new Vector2D(1240, 597),
            90,
            new Vector2D(2.365, 1));
   

   
    env.addCollidingAgent(                                 //Hindernis
                new ObstacleAgent(4, null, null),
                new Vector2D(450, 400),
                0,
                new Vector2D(1, 1));
   
    Random rand = new Random(params.getSeed());
  /* Fuer Schwarmsimulationen. */
      for (int i = 0; i < 5; i++) {
      WandaAgent agent = new WandaAgent(i, env, params);
      agent.implantBrain(new MDL2eBrain<AbstractAgent2D<?>>(agent, new File("eas/users/oclrss12/gruppe4/aufgabe4/TypeBasiert.xml")));
     
      agent.addActuator(new AFOLLOW());
     
      env.addCollidingAgent(agent,
          new Vector2D(200 + i*100 + (rand.nextInt(20) - 10),200),
          90, new Vector2D(0.5,0.5));
    }
   
    return new WandaEnvironment[] { env };
  }
View Full Code Here

    public SutherlandHodgmanClipping() {
        setPreferredSize(new Dimension(600, 500));
        // these subject and clip points are assumed to be valid
        Polygon2D subjPoints = new Polygon2D();
        subjPoints.add(new Vector2D(50, 150));
        subjPoints.add(new Vector2D(200, 50));
        subjPoints.add(new Vector2D(350, 150));
        subjPoints.add(new Vector2D(350, 300));
        subjPoints.add(new Vector2D(250, 300));
        subjPoints.add(new Vector2D(200, 250));
        subjPoints.add(new Vector2D(150, 350));
        subjPoints.add(new Vector2D(100, 250));
        subjPoints.add(new Vector2D(100, 200));
        Polygon2D clipPoints = new Polygon2D();
        clipPoints.add(new Vector2D(125, 40));
        clipPoints.add(new Vector2D(300, 100));
        clipPoints.add(new Vector2D(350, 350));
        clipPoints.add(new Vector2D(200, 350));
        clipPoints.add(new Vector2D(100, 300));
        p1 = new Polygon2D(subjPoints);
        p2 = new Polygon2D(clipPoints);
        result = p1.clipPolygonOneConvex(p2);
    }
View Full Code Here

    private void drawPolygon(Graphics2D g2, Polygon2D points, Color color) {
        g2.setColor(color);
        int len = points.size();
        for (int i = 0; i < len; i++) {
            Vector2D p1 = points.get(i);
            Vector2D p2 = points.get((i + 1) % len);
            g2.draw(new Line2D.Double(p1.x, p1.y, p2.x, p2.y));
        }
    }
View Full Code Here

              distance = currentDistance;
            }
          }
        }
        if(nearestWolfAgent!=null){
          Vector2D ownPosition = env.getAgentPosition(agent.id());
          Vector2D targetPosition = env.getAgentPosition(nearestWolfAgent.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){
            result = 180-angle;
          }
          else{
            result = 180+angle;
          }
        }
        return result;
      }
    });
    k.setEvolvable(true);

    this.addSensor(k=new GenericSensor<Double, AbstractEnvironment2D<AbstractAgent2D<?>>, AbstractAgent2D<?>>() {

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

            @Override
      public String id() {
        return "sensing-sheep-distance";
      }

      @Override
      public Double sense(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
        Double result=MAX_DISTANCE;
        double currentDistance;
        for (AbstractAgent<?> agentX: env.getAgents() ){
          if (agentX.id()>=10 && agentX.id()%2==0 && agentX.id()!=agent.id()){ //isSheep
            currentDistance = env.getAgentPosition(agent.id()).distance(env.getAgentPosition(agentX.id()));
            if (currentDistance < result)  {
              result = currentDistance;
            }
          }
        }
        return result;
      }
    });
    k.setEvolvable(true);

    this.addSensor(k=new GenericSensor<Double, AbstractEnvironment2D<AbstractAgent2D<?>>, AbstractAgent2D<?>>() {

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

            @Override
      public String id() {
        return "sensing-sheep-direction";
      }

      @Override
      public Double sense(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
        Double result= MAX_ANGLE;
        AbstractAgent<?> nearestSheepAgent = null;
        double distance = MAX_DISTANCE;
        double currentDistance;
        for (AbstractAgent<?> agentX: env.getAgents() ){
          if (agentX.id()>=10 && agentX.id()%2==0 && agentX.id()!=agent.id()){ //isSheep
            currentDistance = env.getAgentPosition(agent.id()).distance(env.getAgentPosition(agentX.id()));
            if (currentDistance < distance)  {
              nearestSheepAgent = agentX;
              distance = currentDistance;
            }
          }
        }
        if (nearestSheepAgent!=null){
          Vector2D ownPosition = env.getAgentPosition(agent.id());
          Vector2D targetPosition = env.getAgentPosition(nearestSheepAgent.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){
            result = 180-angle;
          }
          else{
            result = 180+angle;
          }
        }
        return result;
      }
    });
    k.setEvolvable(true);

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

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

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

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

    this.shape = new Polygon2D();
    this.shape.add(new Vector2D(-.5, -.5));
    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

      return "distance-" + sensorNumber;
    }

    @Override
    public Double sense(AbstractEnvironment2D<AbstractAgent2D<?>> env, AbstractAgent2D<?> agent) {
      Vector2D angle0= new Vector2D(env.getNormalizedLOV(agent.id()).x,env.getNormalizedLOV(agent.id()).y);
      //      Vector2D angle1= new Vector2D(env.getNormalizedLOV(agent.id()).x,env.getNormalizedLOV(agent.id()).y);
      //      angle1.drehe(Vector2D.NULL_VEKTOR, (sensorNumber)*(360/(double)numberOfDistanceSensors)*Math.PI/180);
      //      Vector2D angle2= new Vector2D(env.getNormalizedLOV(agent.id()).x,env.getNormalizedLOV(agent.id()).y);
      //      angle2.drehe(Vector2D.NULL_VEKTOR, (sensorNumber+1)*(360/(double)numberOfDistanceSensors)*Math.PI/180);
      //      System.out.println("AHHHHHH!");
      Vector2D thisAgentsPosition = env.getAgentPosition(agent.id());
      double currentDistance;
      double distance = MAX_DISTANCE;
      AbstractAgent<?> nearestAgent = null;
      for(AbstractAgent<?> otherAgent:env.getAgents()){
        if(otherAgent!=agent){
          Vector2D otherAgentsPosition = env.getAgentPosition(otherAgent.id());
          Vector2D angleFromThisToOther = new Vector2D (otherAgentsPosition.x-thisAgentsPosition.x,otherAgentsPosition.y-thisAgentsPosition.y);
          double calculatedAngle = angle0.angle(angleFromThisToOther);
          double calculatedAngleDEG = calculatedAngle*180/Math.PI;
          if (angle0.drehrichtung(angleFromThisToOther)){
            calculatedAngleDEG = 360-calculatedAngleDEG;
          }
View Full Code Here

    return result;
  }

  public boolean setRandomPosition(int targetID, Random random){
    boolean result =false, agentCollides = true;
    Vector2D position=null;
    double angle=0.0;
    do {
      position = getRandomVector2D(random);
      angle = random.nextDouble()*360;
      if(!collides(
 
View Full Code Here

        break;
      default:
        break;
      }

      Vector2D currentPosition = this.getAgentPosition(agent.id());
      if (this.setAgentPosition(agent.id(), new Vector2D(
          currentPosition.x+ xVersch * ConstantsSimulation.SCHRITTW,
          currentPosition.y+ yVersch * ConstantsSimulation.SCHRITTW))){
        erfolgreich = true;

      }
View Full Code Here

    return erfolgreich;
  }

  public Vector2D getRandomVector2D(Random random){
    Vector2D result = null;
    result = new Vector2D(24+random.nextDouble()*(476-34), 14+random.nextDouble()*(496-24));
    return result;
  }
View Full Code Here

   
    @Override
    public synchronized Polygon2D getAgentShape() {
        if (shape == null) {
            shape = new Polygon2D();
            shape.add(new Vector2D(-1, -1));
            shape.add(new Vector2D(-1, 1));
            shape.add(new Vector2D(1, 1));
            shape.add(new Vector2D(1, -1));
//            shape.convertRootPointToMiddle();
        }
        return shape;
    }
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.