View Source Scurry.Geo (Scurry v2.0.1)
Functions related to lines relevant for 2D map pathfinding.
Summary
Functions
Get the distance from a point to a line/segment, aka the square root of
distance_squared/2.
Get the distance squared from a point to a line/segment.
Check if two lines intersect
Determine if, where and how two lines intersect.
Functions
Get the distance from a point to a line/segment, aka the square root of
distance_squared/2.
Params
linea tuple of points ({{ax, ay}, {bx, by}}) describing a line.pointa tuple{x, y}describing a point
This returns the distance beween the given point and segment as a float.
Examples
iex> Geo.distance_to_segment({{2, 0}, {2, 2}}, {0, 1})
2.0
Get the distance squared from a point to a line/segment.
Params
linea tuple of points ({{ax, ay}, {bx, by}}) describing a line.pointa tuple{x, y}describing a point
This returns the square of the distance beween the given point and segment as a float.
Examples
iex> Geo.distance_to_segment_squared({{2, 0}, {2, 2}}, {0, 1})
4.0
Check if two lines intersect
This is a simpler version of line_segment_intersection/2, which is typically
a better choice since it handles endpoints and segment overlap too.
Params
line1a{{x1, y1}, {x2, y2}}line segmentline2a{{x3, y13, {x4, y4}}line segment
Returns true if they intersect, false otherwise.
Note that this doesn't handle segment overlap or points touching. Use
line_segment_intersection/2 instead for that level of detail.
Determine if, where and how two lines intersect.
Params
line1a{{x1, y1}, {x2, y2}}line segmentline2a{{x3, y13, {x4, y4}}line segment
Returns
:on_segmentone line is on the other.:parallelthe lines are parallel and do not intersect.{:point_intersection, {x, y}}either line has an endpoint ({x, y}) on the other line.{:intersection, {x, y}}the lines intersect at{x, y}.:noneno intersection.
Examples
iex> Geo.line_segment_intersection({{1, 2}, {4, 2}}, {{2, 0}, {3, 0}})
:parallel
iex> Geo.line_segment_intersection({{1, 2}, {4, 2}}, {{2, 2}, {3, 2}})
:on_segment
iex> Geo.line_segment_intersection({{1, 2}, {4, 2}}, {{2, 0}, {2, 1}})
:none
iex> Geo.line_segment_intersection({{1, 2}, {4, 2}}, {{2, 0}, {2, 2}})
{:point_intersection, {2.0, 2.0}}
iex> Geo.line_segment_intersection({{1, 2}, {4, 2}}, {{2, 0}, {2, 3}})
{:intersection, {2.0, 2.0}}