seg_seg v0.1.1 SegSeg

Calculates the type of relationship between two line segments AB and CD and the location of intersection (if applicable).

Classification of segment-segment intersection

Link to this section Summary

Functions

Returns a tuple representing the segment-segment intersectoin with three elements

Link to this section Types

Link to this type intersection_result()
intersection_result() :: {boolean, intersection_type, point | nil}
Link to this type intersection_type()
intersection_type() :: :interior | :disjoint | :edge | :vertex
Link to this type point()
point() :: {number, number}

Link to this section Functions

Link to this function intersection(a, b, c, d)
intersection(point, point, point, point) :: intersection_result

Returns a tuple representing the segment-segment intersectoin with three elements:

  1. Boolean true if the two segments intersect at all, false if they are disjoint
  2. An atom representing the classification of the intersection:

    • :interior - the segments intersect at a point that is interior to both
    • :vertex - the segments intersect at an endpoint of one or both segments
    • :edge - the segments are parallel, collinear, and overlap for some non-zero length
    • :disjoint - no intersection exists between the two segments
  3. A tuple {x, y} representing the point of intersection if the intersection is classified as :interior or :vertex, otherwise nil.

Examples

iex> SegSeg.intersection({2, -3}, {4, -1}, {2, -1}, {4, -3})
{true, :interior, {3.0, -2.0}}
iex> SegSeg.intersection({-1, 3}, {2, 4}, {-1, 4}, {-1, 5})
{false, :disjoint, nil}
iex> SegSeg.intersection({-1, 0}, {0, 2}, {0, 2}, {1, -1})
{true, :vertex, {0, 2}}
iex> SegSeg.intersection({-1, 0}, {0, 2}, {1, 4}, {-1, 0})
{true, :edge, nil}