Search in sources :

Example 11 with LineSegmentDouble

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

the class GeometricShapeBuilder method getSquareBaseLine.

public LineSegment getSquareBaseLine() {
    final double radius = getRadius();
    final Point centre = getCentre();
    final double x1 = centre.getX() - radius;
    final double y1 = centre.getY() - radius;
    final double x2 = centre.getX() + radius;
    return new LineSegmentDouble(2, x1, y1, x2, y1);
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) Point(com.revolsys.geometry.model.Point)

Example 12 with LineSegmentDouble

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

the class TaggedLineStringSimplifier method flatten.

/**
 * Flattens a section of the taggedLine between
 * indexes <code>start</code> and <code>end</code>,
 * replacing them with a taggedLine between the endpoints.
 * The input and output indexes are updated
 * to reflect this.
 *
 * @param start the start index of the flattened section
 * @param end the end index of the flattened section
 * @return the new segment created
 */
private LineSegment flatten(final int start, final int end) {
    // make a new segment for the simplified geometry
    final Point p0 = this.line.getVertex(start);
    final Point p1 = this.line.getVertex(end);
    final LineSegment newSeg = new LineSegmentDouble(p0, p1);
    // update the indexes
    remove(this.taggedLine, start, end);
    this.outputIndex.add(newSeg);
    return newSeg;
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 13 with LineSegmentDouble

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

the class LineSegmentTest method testDistancePointLinePerpendicular.

public void testDistancePointLinePerpendicular() {
    final LineSegmentDouble segment = new LineSegmentDouble(2, 0.0, 0, 1.0, 0);
    Assert.assertEquals(0.5, segment.distancePerpendicular(new PointDoubleXY(0.5, 0.5)), 0.000001);
    Assert.assertEquals(0.5, segment.distancePerpendicular(new PointDoubleXY(3.5, 0.5)), 0.000001);
    Assert.assertEquals(0.707106, segment.distancePerpendicular(new PointDoubleXY(1.0, 0)), 0.000001);
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 14 with LineSegmentDouble

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

the class Polygon method getPointWithin.

@Override
default Point getPointWithin() {
    if (isEmpty()) {
        final GeometryFactory geometryFactory = getGeometryFactory();
        return geometryFactory.point();
    } else {
        Point centroid = null;
        try {
            centroid = getCentroid();
            if (centroid.within(this)) {
                return centroid;
            }
        } catch (final TopologyException e) {
        }
        if (centroid != null) {
            final BoundingBox boundingBox = getBoundingBox();
            final double x1 = centroid.getX();
            final double y1 = centroid.getY();
            for (final double x2 : new double[] { boundingBox.getMinX(), boundingBox.getMaxX() }) {
                for (final double y2 : new double[] { boundingBox.getMinY(), boundingBox.getMaxY() }) {
                    final LineSegment line = new LineSegmentDouble(2, x1, y1, x2, y2);
                    try {
                        final Geometry intersection = intersection(line);
                        if (!intersection.isEmpty()) {
                            return intersection.getPointWithin();
                        }
                    } catch (final TopologyException e) {
                    }
                }
            }
        }
        return getPoint();
    }
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 15 with LineSegmentDouble

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

the class SegmentPointComparatorFullTest method checkSegment.

private void checkSegment(final double x, final double y) {
    final Point seg0 = new PointDoubleXY(0, 0);
    final Point seg1 = new PointDoubleXY(x, y);
    final LineSegment seg = new LineSegmentDouble(seg0, seg1);
    for (int i = 0; i < 4; i++) {
        final double dist = i;
        final double gridSize = 1;
        checkPointsAtDistance(seg, dist, dist + 1.0 * gridSize);
        checkPointsAtDistance(seg, dist, dist + 2.0 * gridSize);
        checkPointsAtDistance(seg, dist, dist + 3.0 * gridSize);
        checkPointsAtDistance(seg, dist, dist + 4.0 * gridSize);
    }
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

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