Search in sources :

Example 16 with LineSegmentDouble

use of com.revolsys.geometry.model.segment.LineSegmentDouble in project com.revolsys.open by revolsys.

the class TaggedLineStringSimplifier method simplifySection.

private void simplifySection(final int i, final int j, int depth) {
    depth += 1;
    final int[] sectionIndex = new int[2];
    if (i + 1 == j) {
        final LineSegment newSeg = this.taggedLine.getSegment(i);
        this.taggedLine.addToResult(newSeg);
        // leave this segment in the input index, for efficiency
        return;
    }
    boolean isValidToSimplify = true;
    /**
     * Following logic ensures that there is enough points in the output taggedLine.
     * If there is already more points than the minimum, there's nothing to check.
     * Otherwise, if in the worst case there wouldn't be enough points,
     * don't flatten this segment (which avoids the worst case scenario)
     */
    if (this.taggedLine.getResultSize() < this.taggedLine.getMinimumSize()) {
        final int worstCaseSize = depth + 1;
        if (worstCaseSize < this.taggedLine.getMinimumSize()) {
            isValidToSimplify = false;
        }
    }
    final double[] distance = new double[1];
    final int furthestPtIndex = findFurthestPoint(i, j, distance);
    // flattening must be less than distanceTolerance
    if (distance[0] > this.distanceTolerance) {
        isValidToSimplify = false;
    }
    // test if flattened section would cause intersection
    // final LineSegment candidateSeg = new LineSegmentDouble();
    final Point p0 = this.line.getVertex(i);
    final Point p1 = this.line.getVertex(j);
    final LineSegment candidateSeg = new LineSegmentDouble(p0, p1);
    sectionIndex[0] = i;
    sectionIndex[1] = j;
    if (hasBadIntersection(this.taggedLine, sectionIndex, candidateSeg)) {
        isValidToSimplify = false;
    }
    if (isValidToSimplify) {
        final LineSegment newSeg = flatten(i, j);
        this.taggedLine.addToResult(newSeg);
        return;
    }
    simplifySection(i, furthestPtIndex, depth);
    simplifySection(furthestPtIndex, j, depth);
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 17 with LineSegmentDouble

use of com.revolsys.geometry.model.segment.LineSegmentDouble in project com.revolsys.open by revolsys.

the class OffsetSegmentGenerator method newOffsetSegment.

/**
 * Compute an offset segment for an input segment on a given side and at a given distance.
 * The offset points are computed in full double precision, for accuracy.
 *
 * @param side the side of the segment ({@link Position}) the offset lies on
 * @param distance the offset distance
 * @param offset the points computed for the offset segment
 */
public LineSegment newOffsetSegment(final double x1, final double y1, final double x2, final double y2, final int side, final double distance) {
    final int sideSign;
    if (side == Position.LEFT) {
        sideSign = 1;
    } else {
        sideSign = -1;
    }
    final double dx = x2 - x1;
    final double dy = y2 - y1;
    final double len = Math.sqrt(dx * dx + dy * dy);
    // u is the vector that is the length of the offset, in the direction of the
    // segment
    final double ux = sideSign * distance * dx / len;
    final double uy = sideSign * distance * dy / len;
    final double newX1 = this.geometryFactory.makePrecise(0, x1 - uy);
    final double newY1 = this.geometryFactory.makePrecise(1, y1 + ux);
    final double newX2 = this.geometryFactory.makePrecise(0, x2 - uy);
    final double newY2 = this.geometryFactory.makePrecise(1, y2 + ux);
    return new LineSegmentDouble(2, newX1, newY1, newX2, newY2);
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) Point(com.revolsys.geometry.model.Point)

Example 18 with LineSegmentDouble

use of com.revolsys.geometry.model.segment.LineSegmentDouble in project com.revolsys.open by revolsys.

the class RandomOffsetLineStringGenerator method computeRandomOffset.

private Point computeRandomOffset(final Point p0, final Point p1, final double segFrac) {
    final double len = p0.distancePoint(p1);
    final double len2 = len / 2;
    final double offsetLen = len * Math.random() - len2;
    final LineSegment seg = new LineSegmentDouble(p0, p1);
    return seg.pointAlongOffset(segFrac, offsetLen);
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 19 with LineSegmentDouble

use of com.revolsys.geometry.model.segment.LineSegmentDouble in project com.revolsys.open by revolsys.

the class LineSegmentTest method testOrientationIndexCoordinate.

public void testOrientationIndexCoordinate() {
    final LineSegment seg = new LineSegmentDouble(2, 0, 0, 10, 10);
    checkOrientationIndex(seg, 10, 11, 1);
    checkOrientationIndex(seg, 10, 9, -1);
    checkOrientationIndex(seg, 11, 11, 0);
    checkOrientationIndex(seg, 11, 11.0000001, 1);
    checkOrientationIndex(seg, 11, 10.9999999, -1);
    checkOrientationIndex(seg, -2, -1.9999999, 1);
    checkOrientationIndex(seg, -2, -2.0000001, -1);
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 20 with LineSegmentDouble

use of com.revolsys.geometry.model.segment.LineSegmentDouble in project com.revolsys.open by revolsys.

the class TriangleFunctions method perpendicularBisectors.

public static Geometry perpendicularBisectors(final Geometry g) {
    final Point[] pts = trianglePts(g);
    final Point cc = Triangles.circumcentre(pts[0], pts[1], pts[2]);
    final GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
    final LineString[] line = new LineString[3];
    final Point p0 = new LineSegmentDouble(pts[1], pts[2]).closestPoint(cc);
    line[0] = geomFact.lineString(p0, cc);
    final Point p1 = new LineSegmentDouble(pts[0], pts[2]).closestPoint(cc);
    line[1] = geomFact.lineString(p1, cc);
    final Point p2 = new LineSegmentDouble(pts[0], pts[1]).closestPoint(cc);
    line[2] = geomFact.lineString(p2, cc);
    return geomFact.lineal(line);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point)

Aggregations

LineSegmentDouble (com.revolsys.geometry.model.segment.LineSegmentDouble)20 LineSegment (com.revolsys.geometry.model.segment.LineSegment)14 Point (com.revolsys.geometry.model.Point)10 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)5 LineString (com.revolsys.geometry.model.LineString)2 DirectedEdge (com.revolsys.geometry.geomgraph.DirectedEdge)1 Edge (com.revolsys.geometry.geomgraph.Edge)1 LinearLocation (com.revolsys.geometry.linearref.LinearLocation)1 LocationIndexedLine (com.revolsys.geometry.linearref.LocationIndexedLine)1 Geometry (com.revolsys.geometry.model.Geometry)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1