touchBoundary: Verify line segment intersection with a simple boundary

Description Usage Arguments Value Author(s) Examples

View source: R/touchBoundary.R

Description

Does the line segments touch the boundary? Verify line segment intersection with a simple boundary.

Usage

1
touchBoundary(w0, w1, lims = 0:1)

Arguments

w0, w1

Numeric vector. w stands for either x or y coordinate (of both ends) of the line segments.

lims

Numeric 2 dimensional vector.

Value

List with vectors wm and wM with values where the input touches the boundary.

Author(s)

Daniella Ayala (daniellaayala@ciencias.unam.mx) and Francisco Mendoza-Torres (mentofran@gmail.com)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
n <- 10; xl <- -0.3; xr <- 1.2
set.seed(123) #9
endpts <- data.frame(x0 = runif(n, xl, xr),
y0 = runif(n, xl, xr),
x1 = runif(n, xl, xr),
y1 = runif(n, xl, xr))
plotSegments(segment = endpts)
lims <- c(0,1)
abline(h=lims, v= lims, col = 'lightgray')
# Check for intersection with vertical lines
te <- touchBoundary(w0=endpts$x0, w1 = endpts$x1, lims = lims)
# Intersection with the leftmost vertical boundary (x=constant)
segments(endpts$x0[te$wm], endpts$y0[te$wm],
endpts$x1[te$wm], endpts$y1[te$wm],
col = 'blue', lwd = 3)
# Intersection with the rightmost vertical boundary (x=constant)
segments(endpts$x0[te$wM], endpts$y0[te$wM],
endpts$x1[te$wM], endpts$y1[te$wM],
col = 'green', lwd = 3)

# Intersection with horizontal lines
tey <- touchBoundary(w0=endpts$y0, w1 = endpts$y1, lims = lims)
# Intersection with the bottom-most horizontal boundary (y=constant)
segments(endpts$x0[tey$wm], endpts$y0[tey$wm],
endpts$x1[tey$wm], endpts$y1[tey$wm],
col = 'pink', lwd = 3)
# Intersection with the uppermost horizontal boundary (y=constant)
segments(endpts$x0[tey$wM], endpts$y0[tey$wM],
endpts$x1[tey$wM], endpts$y1[tey$wM],
col = 'red', lwd = 3)

mathphysmx/percolation documentation built on Aug. 14, 2019, 2:03 a.m.