Search in sources :

Example 1 with PointDoubleXY

use of com.revolsys.geometry.model.impl.PointDoubleXY in project com.revolsys.open by revolsys.

the class ConformingDelaunayTriangulator method findNonGabrielPoint.

/**
 * Given a set of points stored in the kd-tree and a line segment defined by
 * two points in this set, finds a {@link Coordinates} in the circumcircle of
 * the line segment, if one exists. This is called the Gabriel point - if none
 * exists then the segment is said to have the Gabriel condition. Uses the
 * heuristic of finding the non-Gabriel point closest to the midpoint of the
 * segment.
 *
 * @param p
 *          start of the line segment
 * @param q
 *          end of the line segment
 * @return a point which is non-Gabriel
 * or null if no point is non-Gabriel
 */
private Point findNonGabrielPoint(final LineSegmentDoubleData seg) {
    final Point p = seg.getPoint(0);
    final Point q = seg.getPoint(1);
    // Find the mid point on the line and compute the radius of enclosing circle
    final Point midPt = new PointDoubleXY((p.getX() + q.getX()) / 2.0, (p.getY() + q.getY()) / 2.0);
    final double segRadius = p.distancePoint(midPt);
    // compute envelope of circumcircle
    final BoundingBox env = midPt.getBoundingBox().expand(segRadius);
    // Find all points in envelope
    final List result = this.pointIndex.getItems(env);
    // For each point found, test if it falls strictly in the circle
    // find closest point
    Point closestNonGabriel = null;
    double minDist = Double.MAX_VALUE;
    for (final Iterator i = result.iterator(); i.hasNext(); ) {
        final KdNode nextNode = (KdNode) i.next();
        final Point testPt = nextNode;
        // ignore segment endpoints
        if (testPt.equals(2, p) || testPt.equals(2, q)) {
            continue;
        }
        final double testRadius = midPt.distancePoint(testPt);
        if (testRadius < segRadius) {
            // double testDist = seg.distance(testPt);
            final double testDist = testRadius;
            if (closestNonGabriel == null || testDist < minDist) {
                closestNonGabriel = testPt;
                minDist = testDist;
            }
        }
    }
    return closestNonGabriel;
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) KdNode(com.revolsys.geometry.index.kdtree.KdNode) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 2 with PointDoubleXY

use of com.revolsys.geometry.model.impl.PointDoubleXY in project com.revolsys.open by revolsys.

the class CGAlgorithmsDD method intersection.

/**
 * Computes an intersection point between two lines
 * using DD arithmetic.
 * Currently does not handle case of parallel lines.
 *
 * @param p1
 * @param p2
 * @param q1
 * @param q2
 * @return
 */
public static Point intersection(final Point p1, final Point p2, final Point q1, final Point q2) {
    final DD denom1 = DD.valueOf(q2.getY()).selfSubtract(q1.getY()).selfMultiply(DD.valueOf(p2.getX()).selfSubtract(p1.getX()));
    final DD denom2 = DD.valueOf(q2.getX()).selfSubtract(q1.getX()).selfMultiply(DD.valueOf(p2.getY()).selfSubtract(p1.getY()));
    final DD denom = denom1.subtract(denom2);
    /**
     * Cases:
     * - denom is 0 if lines are parallel
     * - intersection point lies within line segment p if fracP is between 0 and 1
     * - intersection point lies within line segment q if fracQ is between 0 and 1
     */
    final DD numx1 = DD.valueOf(q2.getX()).selfSubtract(q1.getX()).selfMultiply(DD.valueOf(p1.getY()).selfSubtract(q1.getY()));
    final DD numx2 = DD.valueOf(q2.getY()).selfSubtract(q1.getY()).selfMultiply(DD.valueOf(p1.getX()).selfSubtract(q1.getX()));
    final DD numx = numx1.subtract(numx2);
    final double fracP = numx.selfDivide(denom).doubleValue();
    final double x = DD.valueOf(p1.getX()).selfAdd(DD.valueOf(p2.getX()).selfSubtract(p1.getX()).selfMultiply(fracP)).doubleValue();
    final DD numy1 = DD.valueOf(p2.getX()).selfSubtract(p1.getX()).selfMultiply(DD.valueOf(p1.getY()).selfSubtract(q1.getY()));
    final DD numy2 = DD.valueOf(p2.getY()).selfSubtract(p1.getY()).selfMultiply(DD.valueOf(p1.getX()).selfSubtract(q1.getX()));
    final DD numy = numy1.subtract(numy2);
    final double fracQ = numy.selfDivide(denom).doubleValue();
    final double y = DD.valueOf(q1.getY()).selfAdd(DD.valueOf(q2.getY()).selfSubtract(q1.getY()).selfMultiply(fracQ)).doubleValue();
    return new PointDoubleXY(x, y);
}
Also used : DD(com.revolsys.geometry.math.DD) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 3 with PointDoubleXY

use of com.revolsys.geometry.model.impl.PointDoubleXY in project com.revolsys.open by revolsys.

the class Graph method getNode.

/**
 * Get the node by point coordinates, creating one if it did not exist.
 *
 * @param point The point coordinates to get the node for.
 * @return The node.
 */
public Node<T> getNode(final double x, final double y) {
    final PointDoubleXY point = new PointDoubleXY(x, y);
    Node<T> node = findNode(point);
    if (node == null) {
        final int nodeId = ++this.nextNodeId;
        node = new Node<>(nodeId, this, x, y);
        this.nodesIdsByPoint.put(point, nodeId);
        this.nodesById.put(nodeId, node);
        if (this.nodeIndex != null) {
            this.nodeIndex.add(node);
        }
        this.nodeListeners.nodeEvent(node, null, null, NodeEvent.NODE_ADDED, null);
    }
    return node;
}
Also used : PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Point(com.revolsys.geometry.model.Point)

Example 4 with PointDoubleXY

use of com.revolsys.geometry.model.impl.PointDoubleXY in project com.revolsys.open by revolsys.

the class AffineTransformationFactory method newFromBaseLines.

/**
 * Creates an AffineTransformation defined by a maping between two baselines.
 * The computed transformation consists of:
 * <ul>
 * <li>a translation
 * from the start point of the source baseline to the start point of the destination baseline,
 * <li>a rotation through the angle between the baselines about the destination start point,
 * <li>and a scaling equal to the ratio of the baseline lengths.
 * </ul>
 * If the source baseline has zero length, an identity transformation is returned.
 *
 * @param src0 the start point of the source baseline
 * @param src1 the end point of the source baseline
 * @param dest0 the start point of the destination baseline
 * @param dest1 the end point of the destination baseline
 * @return the computed transformation
 */
public static AffineTransformation newFromBaseLines(final Point src0, final Point src1, final Point dest0, final Point dest1) {
    final Point rotPt = new PointDoubleXY(src0.getX() + dest1.getX() - dest0.getX(), src0.getY() + dest1.getY() - dest0.getY());
    final double ang = Angle.angleBetweenOriented(src1, src0, rotPt);
    final double srcDist = src1.distancePoint(src0);
    final double destDist = dest1.distancePoint(dest0);
    // return identity if transformation would be degenerate
    if (srcDist == 0.0) {
        return new AffineTransformation();
    }
    final double scale = destDist / srcDist;
    final AffineTransformation trans = AffineTransformation.translationInstance(-src0.getX(), -src0.getY());
    trans.rotate(ang);
    trans.scale(scale, scale);
    trans.translate(dest0.getX(), dest0.getY());
    return trans;
}
Also used : Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 5 with PointDoubleXY

use of com.revolsys.geometry.model.impl.PointDoubleXY in project com.revolsys.open by revolsys.

the class DistanceWithPoints method computeContainmentDistance.

private boolean computeContainmentDistance(final Polygon poly, final double x, final double y) {
    // if point is not in exterior, distance to geom is 0
    if (Location.EXTERIOR != poly.locate(x, y)) {
        this.minDistance = 0.0;
        this.minDistancePoint1 = new PointDoubleXY(x, y);
        this.minDistancePoint2 = new PointDoubleXY(x, y);
        return true;
    } else {
        return false;
    }
}
Also used : PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Aggregations

PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)138 Point (com.revolsys.geometry.model.Point)91 Geometry (com.revolsys.geometry.model.Geometry)36 ArrayList (java.util.ArrayList)19 BoundingBox (com.revolsys.geometry.model.BoundingBox)10 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)10 List (java.util.List)9 LineString (com.revolsys.geometry.model.LineString)8 Polygon (com.revolsys.geometry.model.Polygon)6 RobustLineIntersector (com.revolsys.geometry.algorithm.RobustLineIntersector)5 LengthIndexedLine (com.revolsys.geometry.linearref.LengthIndexedLine)5 LinearLocation (com.revolsys.geometry.linearref.LinearLocation)5 LocationIndexedLine (com.revolsys.geometry.linearref.LocationIndexedLine)5 LineSegmentDouble (com.revolsys.geometry.model.segment.LineSegmentDouble)5 PointDoubleXYZ (com.revolsys.geometry.model.impl.PointDoubleXYZ)4 LineSegment (com.revolsys.geometry.model.segment.LineSegment)4 AffineTransformation (com.revolsys.geometry.model.util.AffineTransformation)4 GeometricShapeFactory (com.revolsys.geometry.util.GeometricShapeFactory)4 Vertex (com.revolsys.geometry.model.vertex.Vertex)3 KdNode (com.revolsys.geometry.index.kdtree.KdNode)2