Package org.rascalmpl.library.vis.util.vector

Examples of org.rascalmpl.library.vis.util.vector.Vector2D


    double cy = 0;
    for (SpringGraphNode n : nodes){
      cx += n.getCenterX();
      cy += n.getCenterY();
    }
    return new Vector2D(cx / nodes.size(), cy / nodes.size());
  }
View Full Code Here


  public void init() {
    x = FigureMath.random(width()/2, G.minSize.getX() - width()/2);
    y = FigureMath.random(height()/2, G.minSize.getY() -height()/2);
    temperature = G.MAX_LOCAL_TEMPERATURE;
    skew = 0;
    oldImpulse = new Vector2D(0, 0);
  }
View Full Code Here

  protected double getCenterY() {
    return y;
  }
 
  public Vector2D getCenter() {
    return new Vector2D(x, y);
  }
View Full Code Here

  // Perform one step of the spring simulation algorithm for this node

  public void step() {
    if(debug) print("update, before");
    Vector2D impulse = computeNodeImpulse();
    double angle = oldImpulse.angle(impulse);
    adjustTemperatureAndSkew(angle);
    double dx = G.UPDATE_STEP * impulse.getX() * temperature;
    double dy = G.UPDATE_STEP * impulse.getY() * temperature;

    moveBy(dx, dy); // adjust local position

    if(debug){
      print("relax, after ");
      System.err.printf("             imp (%3.2f, %3.2f), angle %1.2f, dx %3.2f, dy %3.2f\n",
            impulse.getX(), impulse.getY(), Math.toDegrees(angle),
            dx, dy);
    }
    oldImpulse = impulse;
  }
View Full Code Here

   * A = (this - other) * distance^2 / (EDGE_LENGTH_2 * PHI) * ATTRACT
   *
   */
  public Vector2D attractiveForce(SpringGraphNode other) {
    double distance2 = distance2(other);
    Vector2D thisVector = new Vector2D(x, y);
    Vector2D otherVector = new Vector2D(other.x, other.y);
    return thisVector.sub(otherVector).mul(distance2).div(G.EDGE_LENGTH_2 * getMass()) .mul(G.ATTRACT);
  }
View Full Code Here

   */
  public Vector2D repulsiveForce(SpringGraphNode other) {
    double distance2 = distance2(other);

    if (distance2 > 0) {
      Vector2D thisVector = new Vector2D(getCenter());
      Vector2D otherVector = new Vector2D(other.getCenter());
      return thisVector.sub(otherVector).mul(G.EDGE_LENGTH_2).div(distance2).mul(G.REPEL);
    }
    return (new Vector2D(0, 0));
  }
View Full Code Here

    }
    return (new Vector2D(0, 0));
  }
 
  public Vector2D repulsiveForceWall(Vector2D wallVector) {
    Vector2D thisVector = new Vector2D(getCenter());
    double distance2 = thisVector.distance2(wallVector);

    if (distance2 > 0) {
      return thisVector.sub(wallVector).mul(G.EDGE_LENGTH_2).div(distance2).mul(10 * G.REPEL);
    }
    return (new Vector2D(0, 0));
  }
View Full Code Here

   * sum(n in adjacent, attract(n)) Returns norm(F)
   */
  public Vector2D computeNodeImpulse() {

    // Add a random force and the gravitational force
    Vector2D resultForce = gravitionalForce().add(randomForce());

    // Repulsive forces
    for (SpringGraphNode otherNode : G.nodes) {
      if (otherNode != this) {
        resultForce = resultForce.add(repulsiveForce(otherNode));
      }
    }

    // Attractive forces
    for (SpringGraphNode otherNode : in) {
      resultForce = resultForce.sub(this.attractiveForce(otherNode));
    }

    for (SpringGraphNode otherNode : out) {
      resultForce = resultForce.sub(attractiveForce(otherNode));
    }
   
    // Repulsion of left and right wall
   
    resultForce = resultForce.add(repulsiveForceWall(new Vector2D(0, y)));
    resultForce = resultForce.add(repulsiveForceWall(new Vector2D(G.minSize.getX(), y)));
   
    // Repulsion of top and bottom wall
   
    resultForce = resultForce.add(repulsiveForceWall(new Vector2D(x, 0)));
    resultForce = resultForce.add(repulsiveForceWall(new Vector2D(x, G.minSize.getY())));

    // we only need the impulse
    return resultForce.normalize();
  }
View Full Code Here

   * Compute the random force.
   * We need a random impulse [-RAND_CONSTANT, ..., +RAND_CONSTANT]
   * Range should be approx. [-1/4 ... +1/4] of desired edge length.
   */
  public Vector2D randomForce() {
    return new Vector2D(FigureMath.random(-G.RAND_DISTURB, G.RAND_DISTURB),
                      FigureMath.random(-G.RAND_DISTURB, G.RAND_DISTURB));
  }
View Full Code Here

   * This method computes the gravitational force between a node and the
   * barycenter of the drawing.
   * G = (barycenter - thisVector) * Mass * Gravity
   */
  public Vector2D gravitionalForce() {
    Vector2D barycenter = new Vector2D(G.getBaryCenter());
    Vector2D thisVector = new Vector2D(getCenter());
    return barycenter.sub(thisVector).mul(getMass()).mul(G.GRAVITY);
  }
View Full Code Here

TOP

Related Classes of org.rascalmpl.library.vis.util.vector.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.