use of java.awt.geom.Point2D in project JMRI by JMRI.
the class PositionablePoint method getBounds.
/**
* @return the bounds of this positional point
*/
public Rectangle2D getBounds() {
Rectangle2D result;
Point2D pointA = getCoords();
result = new Rectangle2D.Double(pointA.getX(), pointA.getY(), 0, 0);
return result;
}
use of java.awt.geom.Point2D in project opennms by OpenNMS.
the class D3TopoLayout method stepOld.
public void stepOld() {
double currentForce;
// guass-seidel relaxation for links
for (E e : getGraph().getEdges()) {
Pair<V> endPoints = getGraph().getEndpoints(e);
VertexData srcVertexData = getVertexData(endPoints.getFirst());
VertexData targetVertexData = getVertexData(endPoints.getSecond());
double xDelta = targetVertexData.getX() - srcVertexData.getX();
double yDelta = targetVertexData.getY() - srcVertexData.getY();
double l = xDelta * xDelta + yDelta * yDelta;
if (l != 0) {
EdgeData edgeData = getEdgeData(e);
double lSqrt = Math.sqrt(l);
double distance = m_alpha * edgeData.getStrength() * (lSqrt - edgeData.getDistance()) / lSqrt;
xDelta *= distance;
yDelta *= distance;
currentForce = (double) srcVertexData.getWeight() / (double) (targetVertexData.getWeight() + srcVertexData.getWeight());
targetVertexData.offset(-(xDelta * currentForce), -(yDelta * currentForce));
currentForce = 1 - currentForce;
srcVertexData.offset(xDelta * currentForce, yDelta * currentForce);
}
}
// Apply gravity forces
currentForce = m_alpha * getGravity();
if (currentForce != 0) {
double centerX = getSize().getWidth() / 2;
double centerY = getSize().getHeight() / 2;
for (V v : getGraph().getVertices()) {
VertexData vData = getVertexData(v);
vData.offset((centerX - vData.getX()) * currentForce, (centerY - vData.getY()) * currentForce);
}
}
// Compute quad tree center of mass and apply charge force
if (getDefaultCharge() != 0) {
DblBoundingBox bounds = new DblBoundingBox(0, 0, getSize().getWidth(), getSize().getHeight());
QuadTree<VertexData> quadTree = new QuadTree<VertexData>(bounds);
for (V v : getGraph().getVertices()) {
VertexData vData = getVertexData(v);
quadTree.insert(vData, vData.getCharge(), vData);
}
for (V v : getGraph().getVertices()) {
final VertexData vData = getVertexData(v);
quadTree.visit(new Visitor<VertexData>() {
@Override
public boolean visitNode(Node<VertexData> n) {
if (n.isLeaf() && vData == n.getValue())
return true;
double dx = n.getX() - vData.getX();
double dy = n.getY() - vData.getY();
double dw = n.getWidth();
double dSquared = dx * dx + dy * dy;
if (dw * dw / m_thetaSquared < dSquared) {
double force = n.getCharge() / dSquared;
vData.offset(-(dx * force), -(dy * force));
return true;
}
if (n.isLeaf()) {
if (dSquared == 0) {
vData.offset(1, 1);
} else {
double force = n.getCharge() / dSquared;
vData.offset(-(dx * force), -(dy * force));
}
return true;
}
return false;
}
});
}
}
for (V v : getGraph().getVertices()) {
VertexData vData = getVertexData(v);
Point2D location = transform(v);
location.setLocation(vData.getX(), vData.getY());
}
m_alpha *= 0.998235;
}
use of java.awt.geom.Point2D in project opennms by OpenNMS.
the class D3TopoLayout method initialize.
@Override
public void initialize() {
// initialize the weights
for (V v : getGraph().getVertices()) {
VertexData vData = getVertexData(v);
vData.setWeight(1);
Point2D location = transform(v);
vData.setLocation(location);
vData.setPrevious(location);
}
// initialize the vertices that have edges with weight
for (E e : getGraph().getEdges()) {
Pair<V> endPoints = getGraph().getEndpoints(e);
V v1 = endPoints.getFirst();
V v2 = endPoints.getSecond();
VertexData vData1 = getVertexData(v1);
vData1.setWeight(vData1.getWeight() + 1);
VertexData vData2 = getVertexData(v2);
vData2.setWeight(vData2.getWeight() + 1);
}
// Do we need to do an initial layout, we can rely on the initialized position
}
use of java.awt.geom.Point2D in project opennms by OpenNMS.
the class D3TopoLayout method step.
@Override
public void step() {
double currentForce;
// guass-seidel relaxation for links
for (E e : getGraph().getEdges()) {
Pair<V> endPoints = getGraph().getEndpoints(e);
VertexData srcVertexData = getVertexData(endPoints.getFirst());
VertexData targetVertexData = getVertexData(endPoints.getSecond());
double xDelta = targetVertexData.getX() - srcVertexData.getX();
double yDelta = targetVertexData.getY() - srcVertexData.getY();
double l = xDelta * xDelta + yDelta * yDelta;
if (l != 0) {
EdgeData edgeData = getEdgeData(e);
double lSqrt = Math.sqrt(l);
double distance = m_alpha * edgeData.getStrength() * (lSqrt - edgeData.getDistance()) / lSqrt;
// double distance = edgeData.getStrength() * (lSqrt - edgeData.getDistance()) / lSqrt;
xDelta *= distance;
yDelta *= distance;
currentForce = (double) srcVertexData.getWeight() / (double) (targetVertexData.getWeight() + srcVertexData.getWeight());
// currentForce = 0.5;
targetVertexData.offset(-(xDelta * currentForce), -(yDelta * currentForce));
currentForce = 1 - currentForce;
srcVertexData.offset(xDelta * currentForce, yDelta * currentForce);
}
}
// Apply gravity forces
currentForce = m_alpha * getGravity();
if (currentForce != 0) {
double centerX = getSize().getWidth() / 2;
double centerY = getSize().getHeight() / 2;
for (V v : getGraph().getVertices()) {
VertexData vData = getVertexData(v);
vData.offset((centerX - vData.getX()) * currentForce, (centerY - vData.getY()) * currentForce);
}
}
// Compute quad tree center of mass and apply charge force
if (getDefaultCharge() != 0) {
for (V v1 : getGraph().getVertices()) {
VertexData vData1 = getVertexData(v1);
for (V v2 : getGraph().getVertices()) {
VertexData vData2 = getVertexData(v2);
double dx = vData2.getX() - vData1.getX();
double dy = vData2.getY() - vData1.getY();
double d = dx * dx + dy * dy;
if (d > 0) {
double k = m_alpha * vData2.getCharge() / d;
double px = dx * k;
double py = dy * k;
// vData1.offsetPrevious(px, py);
vData1.offset(px, py);
} else {
// vData1.offsetPrevious(0.5-Math.random(), 0.5-Math.random());
vData1.offset(0.5 - Math.random(), 0.5 - Math.random());
}
}
}
}
// position verlet integration
for (V v : getGraph().getVertices()) {
VertexData vData = getVertexData(v);
double tempX = vData.getX();
double tempY = vData.getY();
double x = vData.getX() + (vData.getPrevious().getX() - vData.getX()) * getFriction();
double y = vData.getY() + (vData.getPrevious().getY() - vData.getY()) * getFriction();
vData.setLocation(x, y);
vData.setPrevious(tempX, tempY);
Point2D location = transform(v);
location.setLocation(vData.getX(), vData.getY());
}
m_alpha *= 0.99;
}
use of java.awt.geom.Point2D in project dhis2-core by dhis2.
the class GeoUtils method getBoxShape.
/**
* Returns boundaries of a box shape which centre is the point defined by the
* given longitude and latitude. The distance between the center point and the
* edges of the box is defined in meters by the given distance. Based on standard
* EPSG:4326 long/lat projection. The result is an array of length 4 where
* the values at each index are:
*
* <ul>
* <li>Index 0: Maximum latitude (north edge of box shape).</li>
* <li>Index 1: Maxium longitude (east edge of box shape).</li>
* <li>Index 2: Minimum latitude (south edge of box shape).</li>
* <li>Index 3: Minumum longitude (west edge of box shape).</li>
* </ul>
*
* @param longitude the longitude.
* @param latitude the latitude.
* @param distance the distance in meters to each box edge.
* @return an array of length 4.
*/
public static double[] getBoxShape(double longitude, double latitude, double distance) {
double[] box = new double[4];
GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(longitude, latitude);
calc.setDirection(0, distance);
Point2D north = calc.getDestinationGeographicPoint();
calc.setDirection(90, distance);
Point2D east = calc.getDestinationGeographicPoint();
calc.setDirection(180, distance);
Point2D south = calc.getDestinationGeographicPoint();
calc.setDirection(-90, distance);
Point2D west = calc.getDestinationGeographicPoint();
box[0] = north.getY();
box[1] = east.getX();
box[2] = south.getY();
box[3] = west.getX();
return box;
}
Aggregations