import java.awt.geom.Line2D; import org.javagl.geom.LineIntersection; public class LineIntersectionExample { public static void main(String[] args) { Line2D line1 = new Line2D.Double(0, 0, 1, 1); Line2D line2 = new Line2D.Double(0, 1, 1, 0); double[] intersection = LineIntersection.intersect( line1.getX1(), line1.getY1(), line1.getX2(), line1.getY2(), line2.getX1(), line2.getY1(), line2.getX2(), line2.getY2() ); if (intersection != null) { System.out.println("Lines intersect at: (" + intersection[0] + ", " + intersection[1] + ")"); } else { System.out.println("Lines do not intersect."); } } } <dependencies> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-geometry-core</artifactId> <version>1.1</version> </dependency> </dependencies>


上一篇:
下一篇:
切换中文