{"id":20750584,"url":"https://github.com/micycle1/balaban-intersection","last_synced_at":"2025-07-23T08:37:57.874Z","repository":{"id":51362968,"uuid":"358036394","full_name":"micycle1/balaban-intersection","owner":"micycle1","description":"Implements the Balaban algorithm for finding intersecting segment pairs from a set of line segments.","archived":false,"fork":false,"pushed_at":"2025-01-25T08:58:10.000Z","size":3044,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T03:06:28.184Z","etag":null,"topics":["algorithm","geometry-algorithms","intersection","segment","segment-intersection"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/micycle1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-14T20:39:12.000Z","updated_at":"2025-01-25T08:58:14.000Z","dependencies_parsed_at":"2022-09-24T01:41:03.378Z","dependency_job_id":null,"html_url":"https://github.com/micycle1/balaban-intersection","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micycle1%2Fbalaban-intersection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micycle1%2Fbalaban-intersection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micycle1%2Fbalaban-intersection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micycle1%2Fbalaban-intersection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/micycle1","download_url":"https://codeload.github.com/micycle1/balaban-intersection/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248894939,"owners_count":21179152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","geometry-algorithms","intersection","segment","segment-intersection"],"created_at":"2024-11-17T08:27:57.669Z","updated_at":"2025-04-14T14:09:44.170Z","avatar_url":"https://github.com/micycle1.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![](https://jitpack.io/v/micycle1/balaban-intersection.svg)](https://jitpack.io/#micycle1/balaban-intersection)\n\n\n# Balaban Line Segments Intersection\n\n\u003cp float=\"middle\"\u003e\n  \u003cimg src=\"resources/example1.png\" alt=\"\" width=\"49%\"/\u003e\n  \u003cimg src=\"resources/example2.png\" alt=\"\" width=\"49%\"/\u003e\n\u003c/p\u003e\n\n## Overview\nReporting of segment set intersections is one of the\nfundamental problems of computational geometry. This library implements *Ivan J. Balaban*'s [*Intermediate Algorithm*](https://www2.cs.sfu.ca/~binay/813.2011/Balaban.pdf) for finding intersecting segment pairs from a given set of N segments in the plane.\n\nThis algorithm has complexity *O( n\\*log\u003csup\u003e2\u003c/sup\u003e(n) + k )* (where k is the number of intersecting pairs), which is **much** faster than the more commonly implemented *O( (n+k)\\*log(n) )* *Bentley–Ottmann* algorithm for the same problem. In practice therefore, this library processes sizeable segment sets orders of magnitude more quickly than existing (Java) *Bentley–Ottmann* implementations.\n\nThis repository improves the abandoned original project from *Google Code Archive* whose author was [Taras](https://github.com/taarraas), and is provided as an artifact via [Jitpack](https://jitpack.io/#micycle1/balaban-intersection) for easy use in Maven/Gradle projects.\n\n## Input\n\nThe algorithm processes a single collection of line segments.\n\n\nThe algorithm itself does not check for or handle *degenerate* inputs and will error (generally a stack overflow) on such inputs. The library offers the `findDegenerateSegments()` method to identify degenerate segments before processing.\n\nSegment sets are degenerate when:\n- Contains a vertical segment (whose vertices have the same X coordinate)\n- Contains segments where a vertex from each share an x coordinate.\n\n## Usage\n\nThe algorithm does not natively compute **points** of intersection. Rather, it returns intersecting **segment pairs**.\n\nYou must provide a callback function to the solver: *it* provides intersecting pairs — *you* decide what to do with them.\n\n### Code Example\n```\nRandom r = new Random(0);\n\nCollection\u003cSegment\u003e segments = new ArrayList\u003c\u003e();\nfor (int i = 0; i \u003c 2000; i++) {\n\tsegments.add(new Segment(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble()));\n}\n\nCollection\u003cPoint\u003e points = new ArrayList\u003c\u003e();\n\nBalabanSolver balabanSolver = new BalabanSolver((a, b) -\u003e {\n    \t// will be called by the solver for each intersecting pair\n\tpoints.add(a.getIntersection(b));\n});\n\nbalabanSolver.computeIntersections(segments);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicycle1%2Fbalaban-intersection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicycle1%2Fbalaban-intersection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicycle1%2Fbalaban-intersection/lists"}