image thumbnail

Intersection of Two Lines (line_intersection)

version 5.0.2 (162 KB) by Tamas Kis
Finds the intersection of two lines.

61 Downloads

Updated 05 Sep 2021

From GitHub

View license on GitHub

line_intersection View Intersection of Two Lines (line_intersection) on File Exchange

Finds the intersection of two lines.

Syntax

[x_int,y_int] = line_intersection(line1,line2)

Description

[x_int,y_int] = line_intersection(line1,line2) returns the intersection [x_int,y_int] of two lines. Each line can be defined in four different ways:

  1. line = x0: vertical line form (vertical line defined as )
  2. line = [m,b]: slope-intercept form ()
  3. line = [x0,y0,m]: point-slope form ()
  4. line = [x1,y1,x2,y2]: two point form (line that contains the points and )

Edge Cases:

  • Vertical lines can be defined using the vertical line form or the two point form.
  • If the two lines are parallel (but not collinear), the function returns positive or negative infinity for the coordinates of the intersection, and a warning is displayed.
  • If the two lines are collinear (but not vertical), the function returns [NaN,NaN] and displays a warning.
  • If the two lines are vertical and collinear, the function returns the x-coordinate of the line for the x-coordinate of the intersection, and NaN for the y-coordinate of the intersection.

Examples and Additional Documentation

  • See "EXAMPLES.mlx" or the "Examples" tab on the File Exchange page for examples.
  • See "Intersection_of_Two_Lines.pdf" (also included with download) for the technical documentation.

Cite As

Tamas Kis (2021). Intersection of Two Lines (line_intersection) (https://github.com/tamaskis/line_intersection-MATLAB/releases/tag/v5.0.2), GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2021a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.