我有一个Line2D和一个Area对象,我想要相交的Line2D。结果也可以是GeneralPath。我怎么能这样做?
答案 0 :(得分:1)
您可以在类Area中使用方法instersects。 Line2D可以用Rectangle2D代替。
答案 1 :(得分:1)
第二次机会:
在这里。
答案 2 :(得分:0)
选项1,用三角形近似表示Line2D:
Polygon polygon = new Polygon(new int[]{x1, x2, x2}, new int[]{y1, y2+e, y2-e}, 3);
Area triangle = new Area(polygon);
triangle.intersect(area); // intersection of ray and area
return !triangle.isEmpty(); // returns true if intersects
选项2,改为使用Geometry类
private final GeometryFactory geometryFactory = new GeometryFactory();
private ShapeReader shapeReader = new ShapeReader(geometryFactory);
Path2D.Double thePath = new Path2D.Double(area);
Geometry geometry = shapeReader.read(thePath.getPathIterator(null));
Coordinate[] coordinate = new Coordinate[] {new Coordinate(x1, y1), new Coordinate(x2, y2)};
LineString centerRay = geometryFactory.createLineString(coordinate);
return geometry.intersects(centerRay); // returns true if intersects