Пример #1
0
 @Override
 public Position getXWallRight(Dimension dim, Position p) {
   // See getXWallLeft
   double radius = dim.getHeight() / 2;
   double angle = Math.asin((p.getY() - radius) / radius);
   double xPos = radius * Math.cos(angle);
   return new Position(radius + xPos, p.getY());
 }
Пример #2
0
 @Override
 public Position getXWallLeft(Dimension dim, Position p) {
   // Using trigonometry to get the X position where the current Y position
   // hits the side, only "magic" is converting the positions so they
   // originate in the middle of the circle, and then back again.
   double radius = dim.getHeight() / 2;
   double angle = Math.asin((p.getY() - radius) / radius);
   double xPos = radius * Math.cos(angle);
   return new Position(radius - xPos, p.getY());
 }
 @Override
 public String toBinaryString() {
   StringBuilder sb = new StringBuilder();
   sb.append(roundTwoDecimals(position.getX()));
   sb.append(';');
   sb.append(roundTwoDecimals(position.getY()));
   sb.append(';');
   sb.append(color.getRed());
   sb.append(';');
   sb.append(color.getGreen());
   sb.append(';');
   sb.append(color.getBlue());
   sb.append(';');
   sb.append(width);
   sb.append(';');
   sb.append(height);
   sb.append(';');
   sb.append(roundTwoDecimals(velocity.x));
   sb.append(';');
   sb.append(roundTwoDecimals(velocity.y));
   // sb.append(';');
   // sb.append(maxSpeed);
   // sb.append(';');
   // sb.append(visionRange);
   // sb.append(';');
   // sb.append(maxAcceleration);
   return sb.toString();
 }
Пример #4
0
  @Override
  public Position getRandomPosition(Dimension dim) {
    // Create a random position, and make sure it lies inside the circle.
    // Doesn't loop too many times, since pi/4 of the square area is
    // inside the circle i.e 78.54%. Should only be used during creation of
    // agents and thus doesn't really impact the runtime speed.
    Position pos;
    do {
      pos = new Position(dim.getWidth() * Math.random(), dim.getHeight() * Math.random());
    } while ((Double.compare(pos.getX(), getXWallLeft(dim, pos).getX())
            + Double.compare(getXWallRight(dim, pos).getX(), pos.getX())
            + Double.compare(pos.getY(), getYWallBottom(dim, pos).getY())
            + Double.compare(getYWallTop(dim, pos).getY(), pos.getY()))
        != 4);

    return pos;
  }