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();
}
}
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);
}
}
}
Aggregations