Description Usage Arguments Value Author(s) Examples
View source: R/touchBoundary.R
Does the line segments touch the boundary? Verify line segment intersection with a simple boundary.
1 | touchBoundary(w0, w1, lims = 0:1)
|
w0, w1 |
Numeric vector. w stands for either x or y coordinate (of both ends) of the line segments. |
lims |
Numeric 2 dimensional vector. |
List with vectors wm
and wM
with values where the input touches the boundary.
Daniella Ayala (daniellaayala@ciencias.unam.mx) and Francisco Mendoza-Torres (mentofran@gmail.com)
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.