import com.vividsolutions.jts.util.* GeometricShapeFactory gsf = new GeometricShapeFactory(); gsf.setSize(100); gsf.setNumPoints(100); gsf.setBase(new Coordinate(100, 100)); //configure the circle as appropriate Polygon circleA = gsf.createCircle(); //configure again and create a separate circle Polygon circleB = gsf.createCircle(); //configure a rectangle this time Polygon rectangle = gsf.createRectangle(); Geometry circleIntersection = circleA.intersection(circleB); return rectangle.intersects(circleIntersection);
// method to create your rectangles like before (Polygon objects) public static Polygon createPolygon(Coordinate center, double width, double height){ GeometricShapeFactory shapeFactory = new GeometricShapeFactory(); shapeFactory.setNumPoints(4); shapeFactory.setCentre(center); shapeFactory.setWidth(width); shapeFactory.setHeight(height); return shapeFactory.createRectangle(); } // create your rectagles Polygon rectangleA = createPolygon(new Coordinate(0, 0), 5, 10); Polygon rectangleB = createPolygon(new Coordinate(2, 0), 5, 10); // ### check your constraints // 1. rectangle is within the reference rectangle boolean bWithinA = rectangleB.within(rectangleA); // 2. rectangle is overlapping the reference rectangle boolean bOverlappingA = rectangleB.overlaps(rectangleA); // 3. rectangle is only sharing a border with the reference rectangle boolean bSharesBorderA = rectangleB.touches(rectangleA); // 2. rectangle and reference rectangle are distinct boolean bDistinctsA = rectangleB.disjoint(rectangleA);