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