Search in sources :

Example 66 with PointDoubleXY

use of com.revolsys.geometry.model.impl.PointDoubleXY 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 67 with PointDoubleXY

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

the class DelaunayPerfTest method randomPointsInGrid.

List<Point> randomPointsInGrid(final int nPts) {
    final List<Point> pts = new ArrayList<>();
    final int nSide = (int) Math.sqrt(nPts) + 1;
    for (int i = 0; i < nSide; i++) {
        for (int j = 0; j < nSide; j++) {
            final double x = i * SIDE_LEN + SIDE_LEN * Math.random();
            final double y = j * SIDE_LEN + SIDE_LEN * Math.random();
            pts.add(new PointDoubleXY(x, y));
        }
    }
    return pts;
}
Also used : ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Point(com.revolsys.geometry.model.Point)

Example 68 with PointDoubleXY

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

the class GeoNamesService method mapToObjects.

private List<Record> mapToObjects(final RecordDefinition recordDefinition, final Map<String, Object> result) {
    final List<Record> results = new ArrayList<>();
    final List<Map<String, Object>> names = (List<Map<String, Object>>) result.get("geonames");
    for (final Map<String, Object> name : names) {
        final Record record = recordDefinition.newRecord();
        for (final String fieldName : recordDefinition.getFieldNames()) {
            final Object value = name.get(fieldName);
            if (value != null) {
                record.setValue(fieldName, value);
            }
        }
        final double lat = ((Number) name.get("lat")).doubleValue();
        final double lon = ((Number) name.get("lng")).doubleValue();
        Point coordinate = new PointDoubleXY(lon, lat);
        final Number elevation = (Number) name.get("elevation");
        if (elevation == null) {
            coordinate = new PointDoubleXY(lon, lat);
        } else {
            coordinate = new PointDoubleXYZ(lon, lat, elevation.doubleValue());
        }
        record.setGeometryValue(GeometryFactory.DEFAULT_3D.point(coordinate));
        results.add(record);
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) PointDoubleXYZ(com.revolsys.geometry.model.impl.PointDoubleXYZ) Record(com.revolsys.record.Record) ArrayList(java.util.ArrayList) List(java.util.List) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) HashMap(java.util.HashMap) Map(java.util.Map)

Example 69 with PointDoubleXY

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

the class SplitSegment method pointAlongReverse.

/**
 * Computes the {@link Coordinates} that lies a given fraction along the line defined by the
 * reverse of the given segment. A fraction of <code>0.0</code> returns the end point of the
 * segment; a fraction of <code>1.0</code> returns the start point of the segment.
 *
 * @param seg the LineSegmentDouble
 * @param segmentLengthFraction the fraction of the segment length along the line
 * @return the point at that distance
 */
private static Point pointAlongReverse(final LineSegment seg, final double segmentLengthFraction) {
    final double x = seg.getP1().getX() - segmentLengthFraction * (seg.getP1().getX() - seg.getP0().getX());
    final double y = seg.getP1().getY() - segmentLengthFraction * (seg.getP1().getY() - seg.getP0().getY());
    final Point coord = new PointDoubleXY(x, y);
    return coord;
}
Also used : Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 70 with PointDoubleXY

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

the class ConvexHull method getUniquePoints.

private static Set<Point> getUniquePoints(final Iterable<? extends Point> points) {
    final Set<Point> set = new HashSet<>();
    for (final Point point : points) {
        final Point point2d = new PointDoubleXY(point);
        set.add(point2d);
    }
    return set;
}
Also used : Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) HashSet(java.util.HashSet)

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