Search in sources :

Example 46 with PointDoubleXY

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

the class CommonBitsRemover method add.

/**
 * Add a geometry to the set of geometries whose common bits are
 * being computed.  After this method has executed the
 * common coordinate reflects the common bits of all added
 * geometries.
 *
 * @param geometry a Geometry to test for common bits
 */
public void add(final Geometry geometry) {
    for (final Vertex vertex : geometry.vertices()) {
        this.commonBitsX.add(vertex.getX());
        this.commonBitsY.add(vertex.getY());
    }
    this.commonCoord = new PointDoubleXY(this.commonBitsX.getCommon(), this.commonBitsY.getCommon());
}
Also used : Vertex(com.revolsys.geometry.model.vertex.Vertex) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 47 with PointDoubleXY

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

the class Points method pointOffset.

public static Point pointOffset(final Point point1, final Point point2, final double xOffset, double yOffset) {
    final double distance = point1.distancePoint(point2);
    final double projectionFactor = xOffset / distance;
    if (Double.isNaN(projectionFactor) || Double.isInfinite(projectionFactor)) {
        return new PointDoubleXY(point1.getX() + xOffset, point1.getY() + yOffset);
    } else {
        final Point point = LineSegmentUtil.pointAlong(point1, point2, projectionFactor);
        if (yOffset == 0) {
            return new PointDoubleXY(point);
        } else {
            double angle = point1.angle2d(point2);
            if (yOffset > 0) {
                angle += MathUtil.PI_OVER_2;
            } else {
                angle -= MathUtil.PI_OVER_2;
                yOffset = -yOffset;
            }
            final double x = point.getX() + Math.cos(angle) * yOffset;
            final double y = point.getY() + Math.sin(angle) * yOffset;
            return new PointDoubleXY(x, y);
        }
    }
}
Also used : PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Point(com.revolsys.geometry.model.Point)

Example 48 with PointDoubleXY

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

the class Triangles method angleBisector.

/**
 * Computes the point at which the bisector of the angle ABC cuts the segment
 * AC.
 *
 * @param a
 *          a vertex of the triangle
 * @param b
 *          a vertex of the triangle
 * @param c
 *          a vertex of the triangle
 * @return the angle bisector cut point
 */
static Point angleBisector(final Point a, final Point b, final Point c) {
    /**
     * Uses the fact that the lengths of the parts of the split segment are
     * proportional to the lengths of the adjacent triangle sides
     */
    final double len0 = b.distancePoint(a);
    final double len2 = b.distancePoint(c);
    final double frac = len0 / (len0 + len2);
    final double dx = c.getX() - a.getX();
    final double dy = c.getY() - a.getY();
    final Point splitPt = new PointDoubleXY(a.getX() + frac * dx, a.getY() + frac * dy);
    return splitPt;
}
Also used : Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 49 with PointDoubleXY

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

the class CreateRandomShapeFunctions method randomSegments.

public static Geometry randomSegments(final Geometry g, final int nPts) {
    final BoundingBox env = FunctionsUtil.getEnvelopeOrDefault(g);
    final GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
    final double xLen = env.getWidth();
    final double yLen = env.getHeight();
    final List lines = new ArrayList();
    for (int i = 0; i < nPts; i++) {
        final double x0 = env.getMinX() + xLen * Math.random();
        final double y0 = env.getMinY() + yLen * Math.random();
        final double x1 = env.getMinX() + xLen * Math.random();
        final double y1 = env.getMinY() + yLen * Math.random();
        lines.add(geomFact.lineString(new Point[] { new PointDoubleXY(x0, y0), new PointDoubleXY(x1, y1) }));
    }
    return geomFact.buildGeometry(lines);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Point(com.revolsys.geometry.model.Point)

Example 50 with PointDoubleXY

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

the class CreateRandomShapeFunctions method randomRectilinearWalk.

public static Geometry randomRectilinearWalk(final Geometry g, final int nPts) {
    final BoundingBox env = FunctionsUtil.getEnvelopeOrDefault(g);
    final GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
    final double xLen = env.getWidth();
    final double yLen = env.getHeight();
    final Point[] pts = new Point[nPts];
    boolean xory = true;
    for (int i = 0; i < nPts; i++) {
        Point pt = null;
        if (i == 0) {
            pt = randomPtInRectangleAround(env.getCentre(), xLen, yLen);
        } else {
            final double dist = xLen * (Math.random() - 0.5);
            double x = pts[i - 1].getX();
            double y = pts[i - 1].getY();
            if (xory) {
                x += dist;
            } else {
                y += dist;
            }
            // switch orientation
            xory = !xory;
            pt = new PointDoubleXY(x, y);
        }
        pts[i] = pt;
    }
    return geomFact.lineString(pts);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Point(com.revolsys.geometry.model.Point)

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