/** * This helper calculates all the attractive forces onto a node. Attractive forces from from the * edges pulling nodes towards each other, this will love through the edges of this node. * * @param current Node to calculate forces for. */ private void calculateNodeAttractiveForce(Node current) { // get all the edges of the current node ArrayList<Edge> nodeEdgeList = current.getEdgeList(); // of each of this node's edge do attactive forces Iterator<Edge> nodeEdges = nodeEdgeList.iterator(); /// int numOfEdgesWeight = 10 * (int) Math.round(nodeEdgeList.size() + SPACING); // Loop through edges and find edges containing current node while (nodeEdges.hasNext()) { Edge e = nodeEdges.next(); double edgeStrength = e.getStrength(); Node n; int dx, dy; double sign = 1.0; if (current == e.getNode1()) { n = e.getNode2(); dx = current.getX() - n.getX(); dy = current.getY() - n.getY(); } else { n = e.getNode1(); dx = current.getX() - n.getX(); dy = current.getY() - n.getY(); sign = -1.0; } double distance = Math.sqrt(dx * dx + dy * dy) + .1; // multiply by the strength of edge // current.setVX(current.getVX() - dx / numOfEdgesWeight * edgeStrength); // current.setVY(current.getVY() - dy / numOfEdgesWeight * edgeStrength); current.accelx += sign * (dx * STIFFNESS * (SPRING_LENGTH - distance)) / current.weight; current.accely += sign * (dy * STIFFNESS * (SPRING_LENGTH - distance)) / current.weight; // current.accelx += sign * (dx * (e.getStrength() + 1) * (SPRING_LENGTH - distance) * 0.5) / // current.weight; // current.accely += sign * (dy * (e.getStrength() + 1) * (SPRING_LENGTH - distance) * 0.5) / // current.weight; // n.accelx += sign * (dx * (e.getStrength() + 1) * (SPRING_LENGTH - distance) * 0.5) / // n.weight; // n.accely += sign * (dy * (e.getStrength() + 1) * (SPRING_LENGTH - distance) * 0.5) / // n.weight; } }