Segment extends GM_LineSegment { public Set<IDirectPosition> intersectionWithCircle(IDirectPosition centre, double radius) { Set<IDirectPosition> intersections = new HashSet<IDirectPosition>(); double xc = centre.getX(); double yc = centre.getY(); double a = -coefA / coefB; double b = -coefC / coefB; double A = 1 + a * a; double B = 2.0 * (a * (b - yc) - xc); double C = (xc * xc + (b - yc) * (b - yc) - radius * radius); double delta = B * B - 4.0 * A * C; if (delta > 0.0) { double x1 = -(B + Math.sqrt(delta)) / (2.0 * A); double x2 = -(B - Math.sqrt(delta)) / (2.0 * A); double y1 = a * x1 + b; double y2 = a * x2 + b; intersections.add(new DirectPosition(x1, y1)); intersections.add(new DirectPosition(x2, y2)); } else if (delta == 0.0) { double x = -B / (2.0 * A); double y = a * x + b; intersections.add(new DirectPosition(x, y)); } return intersections; } Segment(IDirectPosition point1, IDirectPosition point2); double getCoefA(); double getCoefB(); double getCoefC(); Segment getPerpendicularSegment(boolean start); Segment getBisectionSegment(); IDirectPosition straightLineIntersection(Segment other); Set<IDirectPosition> intersectionWithCircle(IDirectPosition centre,
      double radius); double distanceToPoint(IDirectPosition point); double orientation(); void print(); static List<Segment> getSegmentList(ILineString line); static List<Segment> getSegmentList(IPolygon polygon,
      IDirectPosition origin); static List<Segment> getSegmentList(IRing ring, IDirectPosition origin); static List<Segment> getReverseSegmentList(IPolygon polygon,
      IDirectPosition origin); static List<Segment> getReverseSegmentList(IRing ring,
      IDirectPosition origin); boolean containsPoint(IDirectPosition point, double tolerance); boolean containsPoint(IDirectPosition point); boolean lineContainsPoint(IDirectPosition point); boolean lineContainsPoint(IDirectPosition point, double tolerance); IDirectPosition getMiddlePoint(); IDirectPosition getWeightedMiddlePoint(double ratio); Segment extendAtExtremities(double length);  }
@Test public void testIntersectionWithCircle() { IDirectPosition p1 = new DirectPosition(0.0, 0.0); IDirectPosition p2 = new DirectPosition(10.0, 0.0); IDirectPosition p3 = new DirectPosition(5.0, 0.0); IDirectPosition p4 = new DirectPosition(15.0, 0.0); Segment segment = new Segment(p1, p2); System.out.println(segment.getCoefA()); System.out.println(segment.getCoefB()); System.out.println(segment.getCoefC()); Set<IDirectPosition> inter = segment.intersectionWithCircle(p2, 5.0); Iterator<IDirectPosition> iter = inter.iterator(); IDirectPosition inter1 = iter.next(); IDirectPosition inter2 = iter.next(); Assert.assertTrue(inter1.equals(p3) || inter2.equals(p3)); Assert.assertTrue(inter1.equals(p4) || inter2.equals(p4)); }