Skip to main content

Implementation of Bentley-Ottman algorithm for finding line segment intersections.

Project description

# line-segment-intersections

An implementation of the Bentley-Ottman algorithm.

## Requirements

numpy >= 1.19.0

## Usage

To use the algorithm, you can import it using

from linesegmentintersections import bentley_ottman

segments = [[[0, 0], [4, 4]], [[1, 3], [3, 1]]] intersections = bentley_ottman(segments)

This algorithm takes a list of pairs of (x, y) coordinates. It will output a list of Intersection objects, from which you can get the coordinates using

x_coordinate = intersections[0].x y_coordinate = intersections[0].y

### Important Assumptions

*No endpoints lie on another segment.* This implementation will work on most cases with colinear endpoints, but there are a few edge cases which will not work, such as 2 or more endpoints lying on a vertical segment. It will simply be missing intersections in the final output.

*No 3 line segments intersect at the same location.* This may cause the algorithm to report a fewer quantity of intersections than are truly there, but will still report the correct locations of intersections.

*No segments share endpoints.* This will cause the algorithm to throw an error.

## Algorithm Details

We implemented the Bentley-Ottman algorithm, which uses a sweepline to add and remove line segments from a balanced tree data structure. Segments only check for intersections with other segments immediately above or below the given segment in the balanced tree. Upon reaching an intersection point, segments are switched in the tree. We keep track of the segment beginnings, ends, and intersections using a priority queue, which simulates our sweepline. For our balanced tree we implemented an AVL Tree.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

line-segment-intersections-0.1.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

line_segment_intersections-0.1.0-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file line-segment-intersections-0.1.0.tar.gz.

File metadata

  • Download URL: line-segment-intersections-0.1.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for line-segment-intersections-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8aebb206e29d00aba9a36a4b4cf65f1fceda33d495012d6a354d602ae44f15d4
MD5 de3bb0a2afb9f6005e1d05251d3003c0
BLAKE2b-256 4db4fff93745b295afb7552666be940f3495c6bd231e0cf9552b3a1b6d971979

See more details on using hashes here.

File details

Details for the file line_segment_intersections-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: line_segment_intersections-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for line_segment_intersections-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b40cf2a2893caa529ac612d87dad4934c327143c9f13f1962b6a9863de28d56f
MD5 e321ccf9caeb6bceb3e6bb4449518c2b
BLAKE2b-256 ed04330f7a5e4b68120a73bd5aad45418472645ac4a0cb3c4d3359f70cb8791b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page