use of com.revolsys.geometry.model.segment.Segment in project com.revolsys.open by revolsys.
the class Densifier method densifyPoints.
/**
* Densifies a coordinate sequence.
*
* @param pts
* @param distanceTolerance
* @return the densified coordinate sequence
*/
private static List<Point> densifyPoints(final LineString line, final double distanceTolerance) {
final List<Point> points = new ArrayList<>();
for (final Segment segment : line.segments()) {
if (points.isEmpty()) {
points.add(segment.getPoint(0));
}
final double length = segment.getLength();
if (length > 0) {
final int densifiedSegCount = (int) (length / distanceTolerance) + 1;
if (densifiedSegCount > 1) {
final double densifiedSegLen = length / densifiedSegCount;
for (int j = 1; j < densifiedSegCount; j++) {
final double segFract = j * densifiedSegLen / length;
final Point point = segment.pointAlong(segFract);
if (!segment.isEndPoint(point)) {
points.add(point);
}
}
}
points.add(segment.getPoint(1));
}
}
return points;
}
use of com.revolsys.geometry.model.segment.Segment in project com.revolsys.open by revolsys.
the class DistanceWithPoints method computeLinePoint.
private boolean computeLinePoint(final LineString line, final Point point) {
if (this.minDistance == Double.MAX_VALUE || line.getBoundingBox().distance(point) <= this.minDistance) {
for (final Segment segment : line.segments()) {
final double distance = segment.distancePoint(point);
if (distance < this.minDistance) {
this.minDistance = distance;
final Point closestPoint = segment.closestPoint(point);
this.minDistancePoint1 = closestPoint;
this.minDistancePoint2 = point;
if (this.minDistance <= this.terminateDistance) {
return true;
}
}
}
}
return false;
}
use of com.revolsys.geometry.model.segment.Segment in project com.revolsys.open by revolsys.
the class Distance3DOp method computeMinDistanceLineLine.
private void computeMinDistanceLineLine(final LineString line0, final LineString line1, final boolean flip) {
// brute force approach!
int i = 0;
for (final Segment segment1 : line0.segments()) {
int j = 0;
for (final Segment segment2 : line1.segments()) {
final Point line1point1 = segment1.getPoint(0);
final Point line1Point2 = segment1.getPoint(1);
final Point line2Point1 = segment2.getPoint(0);
final Point line2Point2 = segment2.getPoint(1);
final double distance = CGAlgorithms3D.distanceSegmentSegment(line1point1, line1Point2, line2Point1, line2Point2);
if (distance < this.minDistance) {
this.minDistance = distance;
// TODO: compute closest pts in 3D
final Point[] closestPt = segment1.closestPoints(segment2);
updateDistance(distance, new GeometryLocation(line0, i, closestPt[0].newPoint2D()), new GeometryLocation(line1, j, closestPt[1].newPoint2D()), flip);
}
if (this.isDone) {
return;
}
j++;
}
i++;
}
}
use of com.revolsys.geometry.model.segment.Segment in project com.revolsys.open by revolsys.
the class DistanceToPointFinder method computeDistance.
public static void computeDistance(final LineString line, final Point pt, final PointPairDistance ptDist) {
for (final Segment segment : line.segments()) {
// this is somewhat inefficient - could do better
final Point closestPt = segment.closestPoint(pt);
ptDist.setMinimum(closestPt, pt);
}
}
use of com.revolsys.geometry.model.segment.Segment in project com.revolsys.open by revolsys.
the class DistanceWithLocation method computePointLine.
private boolean computePointLine(final Point point, final LineString line) {
final BoundingBox boundingBox = line.getBoundingBox();
if (this.minDistance == Double.MAX_VALUE || boundingBox.distance(point) <= this.minDistance) {
for (final Segment segment : line.segments()) {
final double distance = segment.distancePoint(point);
if (distance < this.minDistance) {
this.minDistance = distance;
final Point closestPoint = segment.closestPoint(point);
final int segmentIndex = segment.getSegmentIndex();
this.minDistanceLocation1 = new GeometryLocation(point, 0, point);
this.minDistanceLocation2 = new GeometryLocation(line, segmentIndex, closestPoint);
if (this.minDistance <= this.terminateDistance) {
return true;
}
}
}
}
return false;
}
Aggregations