I'm trying to implement a Billouin-ZoneBrillouin Zone algorithm within mathematicaMathematica, including the generation of Brillouin zones of higher order in 2D and 3D. There is a nice implementation of generating these zones in the Mathematica GuideBook for GraphicsMathematica Guidebook for Graphics. However, this implementation uses the brute force approach in calculating line segment intersections of order O(n²)$\mathcal O(n^2)$ with n$n$ number of lines:
intersectionPoint[{{p1x_, p1y_}, {r1x_, r1y_}}, {{p2x_, p2y_}, {r2x_, r2y_}}, maxDist_] := Module[{aux}, If[PossibleZeroQ[r1y r2x - r2y r1x], Sequence @@ {}, aux = {p1x + (r1x (p1y r2x - p2y r2x - p1x r2y + p2x r2y))/(r1x r2y - r1y r2x), p1y + (r1y (p1y r2x - p2y r2x - p1x r2y + p2x r2y))/(r1x r2y - r1y r2x)} // N; If[Simplify[aux.aux] <= maxDist && IntervalMemberQ[ IntervalIntersection[Interval[{p1x, p1x + r1x}], Interval[{p2x, p2x + r2x}]], aux[[1]]] && IntervalMemberQ[ IntervalIntersection[Interval[{p1y, p1y + r1y}], Interval[{p2y, p2y + r2y}]], aux[[2]]], aux, Sequence @@ {}]]] I'm sure there are a lot of improvements to above code, but the fact persists that the order will be of O(n²)$\mathcal O(n^2)$. Since the line intersection for the Brillouin zone algorithm for high order zones in 3D is the by far the most costly step, I'm looking into smarter approaches to find intersecting line segments. The very smart algorithm by Balaban entitled An optimal algorithm for finding segments intersections is achievingAn optimal algorithm for finding segments intersections achieves an order of at least O(n log(n))$\mathcal O(n\log\,n)$. However, the algorithm involves a rather complex binary search tree implementation. Since mathematicaMathematica has very efficient search implementations within lists already natively supported, I wonder if someone has implemented the Balaban or equivalent sweep line and sweep plane algorithms within mathematica takingMathematica that takes advantage of the built in mathematica-in Mathematica search functions? I'm especially interested in a 2D AND anand a 3D implementation of a line segment intersection within mathematicaMathematica.
Many thanks in advance for any help!