public void calcRepulsion(Graph g, NodeItem n1) { Params np = getParams(n1); np.disp[0] = 0.0; np.disp[1] = 0.0; for (Iterator iter2 = g.nodes(); iter2.hasNext();) { NodeItem n2 = (NodeItem) iter2.next(); Params n2p = getParams(n2); if (n2.isFixed()) continue; if (n1 != n2) { double xDelta = np.loc[0] - n2p.loc[0]; double yDelta = np.loc[1] - n2p.loc[1]; double deltaLength = Math.max(EPSILON, Math.sqrt(xDelta*xDelta + yDelta*yDelta)); double force = (forceConstant*forceConstant) / deltaLength; if (Double.isNaN(force)) { System.err.println("Mathematical error..."); } np.disp[0] += (xDelta/deltaLength)*force; np.disp[1] += (yDelta/deltaLength)*force; } } }
public void calcRepulsion(Graph g, NodeItem n1) { Params np = getParams(n1); np.disp[0] = 0.0; np.disp[1] = 0.0; for (Iterator iter2 = g.nodes(); iter2.hasNext();) { NodeItem n2 = (NodeItem) iter2.next(); Params n2p = getParams(n2); if (n2.isFixed()) continue; if (n1 != n2) { double xDelta = np.loc[0] - n2p.loc[0]; double yDelta = np.loc[1] - n2p.loc[1]; double deltaLength = Math.max(EPSILON, Math.sqrt(xDelta*xDelta + yDelta*yDelta)); double force = (forceConstant*forceConstant) / deltaLength; if (Double.isNaN(force)) { System.err.println("Mathematical error..."); } np.disp[0] += (xDelta/deltaLength)*force; np.disp[1] += (yDelta/deltaLength)*force; } } }
/** * @see prefuse.action.Action#run(double) */ public void run(double frac) { Graph g = (Graph)m_vis.getGroup(m_group); Rectangle2D bounds = super.getLayoutBounds(); init(g, bounds); for (int curIter=0; curIter < maxIter; curIter++ ) { // Calculate repulsion for (Iterator iter = g.nodes(); iter.hasNext();) { NodeItem n = (NodeItem)iter.next(); if (n.isFixed()) continue; calcRepulsion(g, n); } // Calculate attraction for (Iterator iter = g.edges(); iter.hasNext();) { EdgeItem e = (EdgeItem) iter.next(); calcAttraction(e); } for (Iterator iter = g.nodes(); iter.hasNext();) { NodeItem n = (NodeItem)iter.next(); if (n.isFixed()) continue; calcPositions(n,bounds); } cool(curIter); } finish(g); }