Search in sources :

Example 76 with Point2D

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;
}
Also used : Point2D(java.awt.geom.Point2D) Rectangle2D(java.awt.geom.Rectangle2D)

Example 77 with Point2D

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;
}
Also used : DblBoundingBox(org.opennms.features.topology.api.DblBoundingBox) Point2D(java.awt.geom.Point2D)

Example 78 with Point2D

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
}
Also used : Point2D(java.awt.geom.Point2D)

Example 79 with Point2D

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;
}
Also used : Point2D(java.awt.geom.Point2D)

Example 80 with Point2D

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;
}
Also used : Point2D(java.awt.geom.Point2D) GeodeticCalculator(org.geotools.referencing.GeodeticCalculator)

Aggregations

Point2D (java.awt.geom.Point2D)193 Color (java.awt.Color)22 Rectangle2D (java.awt.geom.Rectangle2D)20 RadialGradientPaint (java.awt.RadialGradientPaint)19 Graphics2D (java.awt.Graphics2D)18 Point (java.awt.Point)18 Paint (java.awt.Paint)17 Line2D (java.awt.geom.Line2D)12 AffineTransform (java.awt.geom.AffineTransform)11 Rectangle (java.awt.Rectangle)9 BasicStroke (java.awt.BasicStroke)8 Stroke (java.awt.Stroke)8 Ellipse2D (java.awt.geom.Ellipse2D)8 BufferedImage (java.awt.image.BufferedImage)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 Element (org.jdom2.Element)6 GradientPaint (java.awt.GradientPaint)5 Arc2D (java.awt.geom.Arc2D)5 GeneralPath (java.awt.geom.GeneralPath)5