## Intersection of Two Lines (line_intersection)

version 5.0.4 (162 KB) by
Finds the intersection of two lines.

Updated 23 Dec 2021

From GitHub

# `line_intersection`

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.

• See "EXAMPLES.mlx" or the "Examples" tab on the File Exchange page for examples.

### Cite As

Tamas Kis (2022). Intersection of Two Lines (line_intersection) (https://github.com/tamaskis/line_intersection-MATLAB/releases/tag/v5.0.4), 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.