Example #1
0
  // Velocity init
  public static void initVelocity() {
    if (velocityCatch == null) {
      System.out.println("init VM");
      velocityCatch = new Object();

      Properties props = new Properties();
      props.setProperty("input.encoding", "UTF-8");
      props.setProperty("output.encoding", "UTF-8");

      if (getConfig().getChild("vmtemplatepath") != null) {
        props.setProperty("file.resource.loader.path", getConfig().getChildText("vmtemplatepath"));
      }
      if (System.getProperty("vmtemplatepath") != null) {
        props.setProperty("file.resource.loader.path", System.getProperty("vmtemplatepath"));
        // Velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,
        // System.getProperty("vmtemplatepath"));//oder new FIle()?
      }
      System.out.println("vmtemplatepath=" + props.getProperty("vmtemplatepath"));
      try {
        Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, VeloLog.getInstance());
        Velocity.init(props);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }
Example #2
0
 public static Velocity getCollisonFriendlz(Velocity v) {
   Velocity ve = new Velocity(0, 0);
   //		ve.setX(v.getX()/(0.25f/4)*(0.25f/4));
   //		ve.setZ(v.getZ()/(0.25f/4)*(0.25f/4));
   ve.setX((((int) (v.getX() * 10000)) / 625 * 625) / 10000f);
   ve.setZ((((int) (v.getZ() * 10000)) / 625 * 625) / 10000f);
   return ve;
 }
Example #3
0
  public float angle(Velocity l2) {
    float scalar = (this.getX() * l2.getX()) + (this.getZ() * l2.getZ());
    float distance1 = (float) Velocity.getDistance(new Velocity(0, 0), this);
    float distance2 = (float) Velocity.getDistance(new Velocity(0, 0), l2);
    float distance = distance1 * distance2;
    //		Szstem.out.println(distance1+","+distance2+","+Math.acos(scalar/distance));
    return (float) Math.toDegrees(Math.acos(scalar / distance));

    // |1|	* |2|
    // |1|	* |2|
  }
Example #4
0
 /**
  * Called for moving events, increase age of velocity, decrease amounts, check which entries are
  * invalid. Both horizontal and vertical.
  */
 public void tick() {
   // Decrease counts for active.
   // TODO: Actual friction. Could pass as an argument (special value for not to be used).
   // TODO: Consider removing already invalidated here.
   for (final Velocity vel : active) {
     vel.valCount--;
     vel.sum += vel.value;
     vel.value *= 0.93; // vel.frictionFactor;
     // (Altered entries should be kept, since they get used right away.)
   }
   // Decrease counts for queued.
   final Iterator<Velocity> it = queued.iterator();
   while (it.hasNext()) {
     it.next().actCount--;
   }
 }
Example #5
0
 @Test
 public void math() throws SlxException {
   Map map = new HashMap();
   map.put("DateUtils", new DateUtils());
   String s =
       "#set($ceria=\"201109\")  \n$DateUtils.getFirstDayofMouth($ceria,\"yyyyMM\",\"yyyyMMdd\")";
   String str = Velocity.evaluateAsString(s, map);
   Assert.assertEquals("20110901", str);
 }
Example #6
0
 public void tick() {
   if (!mIsStatic) {
     changeVelocity();
     mCurPosition =
         new Position(
             mCurPosition.getPositionX(), mCurPosition.getPositionY() + mVelocity.getVelocityY());
     collider.setPosition(mCurPosition);
   }
 }
  /**
   * Validates that the sum is computed correctly.
   *
   * @param aInitialValue
   * @param aValueToAdd
   * @param aExpectedResult
   */
  @Test(dataProvider = "addTestValues")
  public void add_variousValues_returnCorrectSum(
      final Velocity aInitialValue, final Velocity aValueToAdd, final Velocity aExpectedResult) {
    // Act
    final Velocity result = aInitialValue.add(aValueToAdd);

    // Assert
    Assert.assertEquals(aExpectedResult, result, "Sum");
  }
Example #8
0
  public static void main(String[] args) {
    Velocity vel = new Velocity();
    final double DELTA_T = 0.01;
    double position = 0, velocity = 0, time = 0, gravity = 9.81;
    double standardEquation = (0.5 * gravity * Math.pow(time, 2)) + (velocity * time);
    Scanner huerta = new Scanner(System.in);
    int x = 1, y = 2;

    System.out.print("Enter a velocity: ");
    velocity = huerta.nextDouble();

    for (int i = 0; i < 100; i++) {
      velocity = velocity - gravity * DELTA_T;
      position = position + velocity * DELTA_T;
      time = Math.abs(Math.cbrt((position - velocity) / (-0.5 * gravity)));

      standardEquation = (0.5 * gravity * Math.pow(time, 2)) + (velocity * time);
    }

    System.out.println("Accurate Position: " + position);
    System.out.println("Standard Equation Position: " + standardEquation);
    System.out.println(vel.add(x, y));
  }
Example #9
0
 public Position translate(Velocity velocity) {
   Position result = new Position(this.deltaX + velocity.onX(), deltaY + velocity.onY());
   return result;
 }
Example #10
0
  public List<SampleData> run() {
    init();
    for (int c = 0; c < ITERATION_COUNT; c++) {
      List<Boid> newBoids = new ArrayList<>();
      for (int bid = 0; bid < boids.size(); bid++) {
        Boid b = boids.get(bid);
        int localCount = 0;
        Velocity varTotal = new Velocity(0, 0); // alignment
        Velocity vsr = new Velocity(0, 0); // separation
        Velocity vcr = new Velocity(0, 0); // cohesion
        Velocity vds = new Velocity(0, 0); // similarity
        Velocity vdd = new Velocity(0, 0); // dissimilarity
        for (int xid = 0; xid < boids.size(); xid++) {
          Boid x = boids.get(xid);
          double d = getDistance(b, x);
          if (d > SENSE_RANGE) {
            continue;
          }
          varTotal.vx += x.v.vx;
          varTotal.vy += x.v.vy;

          vsr.vx += d == 0 ? 0 : (x.v.vx + b.v.vx) / d;
          vsr.vy += d == 0 ? 0 : (x.v.vy + b.v.vy) / d;

          vcr.vx += x.x - b.x;
          vcr.vy += x.y - b.y;

          double sim = computeSimilarity(xid, bid);
          vds.vx += sim * d * x.v.vx;
          vds.vy += sim * d * x.v.vy;

          vdd.vx += sim * d == 0 ? 0 : (1 / (sim * d)) * x.v.vx;
          vdd.vy += sim * d == 0 ? 0 : (1 / (sim * d)) * x.v.vy;

          localCount++;
        }
        Velocity var =
            localCount == 0
                ? new Velocity(0, 0)
                : new Velocity(varTotal.vx / localCount, varTotal.vy / localCount);
        // compute updated weighted velocity for b
        Velocity newV = updateVelocity(var, vsr, vcr, vds, vdd);
        newBoids.add(new Boid(newV, b.x - newV.vx, newV.vy));
      }
      boids = newBoids;
    }
    // update dataset
    List<SampleData> points = new ArrayList<>();
    for (int i = 0; i < boids.size(); i++) {
      List<Double> attributes = new ArrayList<>();
      attributes.add(boids.get(i).x);
      attributes.add(boids.get(i).y);
      SampleData sd = new SampleData(attributes, i);
      points.add(sd);
    }
    return points;
  }
Example #11
0
 public void add(Velocity velocitz) {
   this.x = x + velocitz.getX();
   this.z = z + velocitz.getZ();
 }
Example #12
0
 public static double getDistance(Velocity l, Velocity l2) {
   return Math.sqrt(
       ((l2.getX() - l.getX()) * (l2.getX() - l.getX()))
           + ((l2.getZ() - l.getZ()) * (l2.getZ() - l.getZ())));
 }
Example #13
0
 public boolean equals(Velocity v) {
   return getVelocity().equals(v.getVelocity());
 }
Example #14
0
 public void tick(Velocity v) {
   int dx = (int) (MathUtilities.cosdeg(v.direction) * v.getSpeed());
   int dy = (int) (MathUtilities.sindeg(360 - v.direction) * v.getSpeed());
   this.x += dx;
   this.y += dy;
 }