@Override protected boolean isAllowed(final Position p) { return (p.getCoordinate(0) < maxX && p.getCoordinate(0) > minX && p.getCoordinate(1) < maxY && p.getCoordinate(1) > minY); }
/** * Initialize a gradient layer which grows in concentration proportionaly in space. * * @param direction the {@link Position} representing the direction in which the gradient grows (here the positions is considered as a vector) * @param unitVariation unit variation of the gradient * @param offset minimum value of concentration reached by this spatial distribution */ public BiomolGradientLayer(final Position direction, final double unitVariation, final double offset) { this(direction.getCoordinate(0), direction.getCoordinate(1), unitVariation, offset); }
@Override public boolean intersectsObstacle(final Position p1, final Position p2) { return intersectsObstacle(p1.getCoordinate(0), p1.getCoordinate(1), p2.getCoordinate(0), p2.getCoordinate(1)); }
private PointAdapter(final Position pos) { assert pos.getDimensions() == 2; this.pos = pos; x = pos.getCoordinate(0); y = pos.getCoordinate(1); }
private boolean selectNodes(final CellWithCircularArea node, final CellWithCircularArea nodeToMove, final Position origin, final Position requestedPos, final double xVer, final double yVer) { // testing if node is between requested position and original position final Position nodePos = getPosition(node); final Position nodeOrientationFromOrigin = new Continuous2DEuclidean(nodePos.getCoordinate(0) - origin.getCoordinate(0), nodePos.getCoordinate(1) - origin.getCoordinate(1)); final double scalarProductResult1 = xVer * nodeOrientationFromOrigin.getCoordinate(0) + yVer * nodeOrientationFromOrigin.getCoordinate(1); // testing if node is near enough to requested position to be an obstacle final Position oppositeVersor = new Continuous2DEuclidean(-xVer, -yVer); final Position nodeOrientationFromReq = new Continuous2DEuclidean(nodePos.getCoordinate(0) - requestedPos.getCoordinate(0), nodePos.getCoordinate(1) - requestedPos.getCoordinate(1)); final double scalarProductResult2 = oppositeVersor.getCoordinate(0) * nodeOrientationFromReq.getCoordinate(0) + oppositeVersor.getCoordinate(1) * nodeOrientationFromReq.getCoordinate(1); if (scalarProductResult2 <= 0) { return (nodePos.getDistanceTo(requestedPos) < node.getRadius() + nodeToMove.getRadius()) && scalarProductResult1 >= 0; } return scalarProductResult1 >= 0; }
/** * Updates the environment size to include the provided position. * * @param pos * the position to include */ protected final void includeObject(final Position pos) { assert pos.getDimensions() == 2; final double x = pos.getCoordinate(0); final double y = pos.getCoordinate(1); includeObject(x, x, y, y); }
private Position weightedAverageVectors(final List<Node<Double>> list, final CellNode thisNode) { Position res = new Continuous2DEuclidean(0, 0); final Position thisNodePos = env.getPosition(thisNode); for (final Node<Double> n : list) { final Position nPos = env.getPosition(n); Position vecTemp = new Continuous2DEuclidean( nPos.getCoordinate(0) - thisNodePos.getCoordinate(0), nPos.getCoordinate(1) - thisNodePos.getCoordinate(1)); final double vecTempModule = FastMath.sqrt(FastMath.pow(vecTemp.getCoordinate(0), 2) + FastMath.pow(vecTemp.getCoordinate(1), 2)); vecTemp = new Continuous2DEuclidean( n.getConcentration(biomol) * (vecTemp.getCoordinate(0) / vecTempModule), n.getConcentration(biomol) * (vecTemp.getCoordinate(1) / vecTempModule)); res = new Continuous2DEuclidean( res.getCoordinate(0) + vecTemp.getCoordinate(0), res.getCoordinate(1) + vecTemp.getCoordinate(1)); } return res; }
@Override public void setEnvPosition(final Position ep) { LatLong center; try { center = new LatLong(ep.getCoordinate(1), ep.getCoordinate(0)); } catch (IllegalArgumentException e) { center = new LatLong(0, 0); } mapModel.setCenter(center); }
@Override protected boolean isAllowed(final Position p) { return rtree.search(Geometries.point(p.getCoordinate(0), p.getCoordinate(1))).isEmpty().toBlocking().single(); }
@Override public Position getNextPosition() { final CellNode thisNode = getNode(); return new Continuous2DEuclidean( delta * thisNode.getPolarizationVersor().getCoordinate(0), delta * thisNode.getPolarizationVersor().getCoordinate(1) ); }
final double sfx = shortest.getCoordinate(0); final double sfy = shortest.getCoordinate(1); if (sfx != fx || fy != sfy) {
Position newPolVer = weightedAverageVectors(l, thisNode); final double newPolVerModule = FastMath.sqrt(FastMath.pow( newPolVer.getCoordinate(0), 2) + FastMath.pow(newPolVer.getCoordinate(1), 2) ); if (newPolVerModule == 0) { thisNode.addPolarization(newPolVer); } else { newPolVer = new Continuous2DEuclidean(newPolVer.getCoordinate(0) / newPolVerModule, newPolVer.getCoordinate(1) / newPolVerModule); if (ascend) { thisNode.addPolarization(newPolVer); } else { thisNode.addPolarization(new Continuous2DEuclidean( -newPolVer.getCoordinate(0), -newPolVer.getCoordinate(1)) );
final double halfDistance = (distanceToScan / 2); final double rx = requestedPos.getCoordinate(0); final double ox = originalPos.getCoordinate(0); final double xVec = rx - ox; final double ry = requestedPos.getCoordinate(1); final double oy = originalPos.getCoordinate(1); final double yVec = ry - oy; final double module = FastMath.sqrt(FastMath.pow(xVec, 2) + FastMath.pow(yVec, 2));
final double yn = possibleObstaclePosition.getCoordinate(1); final double xn = possibleObstaclePosition.getCoordinate(0); final Position versor = new Continuous2DEuclidean((xIntersect - xo) / module, (yIntersect - yo) / module); final Position vectorToSum = new Continuous2DEuclidean(distToSum * (versor.getCoordinate(0)), distToSum * (versor.getCoordinate(1)));
for (final Position p : pushForces) { for (int i = 0; i < p.getDimensions(); i++) { resVersor[i] = resVersor[i] + p.getCoordinate(i);