Learn R Programming

retistruct (version 0.5.9)

line.line.intersection: Determine intersection between two lines

Description

Determine the intersection of two lines L1 and L2 in two dimensions, using the formula described by Weisstein.

Usage

line.line.intersection(P1, P2, P3, P4, interior.only = FALSE)

Arguments

P1
vector containing x,y coordinates of one end of L1
P2
vector containing x,y coordinates of other end of L1
P3
vector containing x,y coordinates of one end of L2
P4
vector containing x,y coordinates of other end of L2
interior.only
boolean flag indicating whether only intersections inside L1 and L2 should be returned.

Value

  • Vector containing x,y coordinates of intersection of L1 and L2. If L1 and L2 are parallel, this is infinite-valued. If interior.only is TRUE, then when the intersection does not occur between P1 and P2 and P3 and P4, a vector containing NAs is returned.

source

Weisstein, Eric W. "Line-Line Intersection." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Line-LineIntersection.html

Examples

Run this code
## Intersection of two intersecting lines
line.line.intersection(c(0, 0), c(1, 1), c(0, 1), c(1, 0))

## Two lines that don't intersect
line.line.intersection(c(0, 0), c(0, 1), c(1, 0), c(1, 1))

Run the code above in your browser using DataLab