Search in sources :

Example 1 with Vector2D

use of org.vcell.util.geometry2d.Vector2D in project vcell by virtualcell.

the class NailShapeEnergyFunction method getForce.

public Vector2D getForce(List<Point2D> ps, int index) {
    if (ps.size() < 2) {
        throw EnergySum.Default.getWrongNUmberOfParametersException(getNumberOfParameters(), ps.size());
    }
    Point2D p0 = ps.get(0);
    Point2D p1 = ps.get(1);
    double dx = 0.0, dy = 0.0;
    switch(index) {
        case 0:
            {
                dx = p1.x - p0.x;
                dy = p1.y - p0.y;
                double r = Math.sqrt(dx * dx + dy * dy);
                double r3 = r * r * r;
                return new Vector2D(k * dx / r3, k * dy / r3);
            }
        case 1:
            {
                dx = p0.x - p1.x;
                dy = p0.y - p1.y;
            }
    }
    double rSquared = dx * dx + dy * dy;
    if (rSquared < rMaxSquared) {
        double factor = 2 * k * rMaxSquared / (rSquared * rSquared);
        return new Vector2D(factor * dx, factor * dy);
    } else {
        return new Vector2D();
    }
}
Also used : Vector2D(org.vcell.util.geometry2d.Vector2D) Point2D(org.vcell.util.geometry2d.Point2D)

Example 2 with Vector2D

use of org.vcell.util.geometry2d.Vector2D in project vcell by virtualcell.

the class WerewolfMinimizer method minimize.

public void minimize(EnergySum energySum) {
    ContainedGraph graph = energySum.getGraph();
    NodesShift.Default nodesShift = new NodesShift.Default(graph);
    for (int iIteration = 0; iIteration < nIterations; ++iIteration) {
        double absShiftMax = 0;
        for (Node node : graph.getNodes()) {
            double shiftX = ContainedGraphUtil.getRandomShiftX(node, random);
            double shiftY = ContainedGraphUtil.getRandomShiftY(node, random);
            nodesShift.getShifts().put(node, new Vector2D(shiftX, shiftY));
            double absShiftX = Math.abs(shiftX);
            if (absShiftX > absShiftMax) {
                absShiftMax = absShiftX;
            }
            double absShiftY = Math.abs(shiftY);
            if (absShiftY > absShiftMax) {
                absShiftMax = absShiftY;
            }
        }
        while (absShiftMax > 0.3) {
            for (Map.Entry<Node, Vector2D> entry : nodesShift.getShifts().entrySet()) {
                Vector2D vShift = entry.getValue();
                vShift.x *= (1 - cut);
                vShift.y *= (1 - cut);
            }
            if (energySum.getDifference(nodesShift) < 0) {
                nodesShift.apply();
                break;
            }
            absShiftMax *= (1 - cut);
        }
    }
}
Also used : Vector2D(org.vcell.util.geometry2d.Vector2D) NodesShift(org.vcell.util.graphlayout.NodesShift) Node(org.vcell.util.graphlayout.ContainedGraph.Node) ContainedGraph(org.vcell.util.graphlayout.ContainedGraph) Map(java.util.Map)

Aggregations

Vector2D (org.vcell.util.geometry2d.Vector2D)2 Map (java.util.Map)1 Point2D (org.vcell.util.geometry2d.Point2D)1 ContainedGraph (org.vcell.util.graphlayout.ContainedGraph)1 Node (org.vcell.util.graphlayout.ContainedGraph.Node)1 NodesShift (org.vcell.util.graphlayout.NodesShift)1