To check whether two shapes interact with each other we use the
ILcd2DBinaryTopology
interface,
as illustrated in the example below:
import com.luciad.geodesy.TLcdEllipsoid;
import com.luciad.geometry.ILcd2DBinaryTopology;
import com.luciad.geometry.ellipsoidal.TLcdEllipsoidalBasicBinaryTopology;
import com.luciad.shape.shape2D.ILcd2DEditablePoint;
import com.luciad.shape.shape2D.TLcd2DEditablePointList;
import com.luciad.shape.shape2D.TLcdLonLatPoint;
import com.luciad.shape.shape2D.TLcdLonLatPolygon;
public class BasicBinaryTopologyTutorial {
public static void main(String[] args) {
// Create the ellipsoid.
// For this sample, it is hardcoded here.
// In practice, the ellipsoid used by all shapes in the program should be used.
// In a cartesian topology, no ellipsoid is needed.
TLcdEllipsoid ellipsoid = new TLcdEllipsoid();
// Create two shapes.
// For this sample two simple triangles are created.
// In practice, these ILcdShape instances could originate from any source.
TLcdLonLatPolygon polygon1 = new TLcdLonLatPolygon(new TLcd2DEditablePointList(
new ILcd2DEditablePoint[]{
new TLcdLonLatPoint(0.0, 0.0),
new TLcdLonLatPoint(10.0, 20.0),
new TLcdLonLatPoint(20.0, 10.0)
}, false), ellipsoid);
TLcdLonLatPolygon polygon2 = new TLcdLonLatPolygon(new TLcd2DEditablePointList(
new ILcd2DEditablePoint[]{
new TLcdLonLatPoint(11.0, 12.0),
new TLcdLonLatPoint(5.0, 4.0),
new TLcdLonLatPoint(12.0, 0.0)
}, false), ellipsoid);
// Create the basic binary topology.
ILcd2DBinaryTopology topology = new TLcdEllipsoidalBasicBinaryTopology(ellipsoid);
// Test if the shapes interact.
boolean result = topology.checkTopology(polygon1, polygon2, ILcd2DBinaryTopology.INTERACT);
System.out.println("The shapes intersect: " + result);
}
}
The ILcd2DBinaryTopology
interface only provides basic operations. See the
How to check perform advanced (binary) topology checks tutorial
for more advanced checks.