Description Usage Arguments Details Value Examples
Calculate where two lines or curves intersect. Curves are defined as data frames with x and y columns providing cartesian coordinates for the lines. This function works on both linear and nonlinear curves.
1 | curve_intersect(curve1, curve2, empirical = TRUE, domain = NULL)
|
curve1 |
Either a |
curve2 |
Either |
empirical |
If true (default) indicates that the curves are data frames of empirical data. If false, indicates that the curves are actual functions. |
domain |
Two-value numeric vector indicating the bounds along the
x-axis where the intersection should be found when |
For now, curve_intersect
will only find one intersection.
If you define curves with empirical data frames (i.e. provide actual values
for x and y), ensure that empirical = TRUE
.
If you define curves with functions (i.e. curve1 <- x^2
), ensure that
empirical = FALSE
and provide a range of x-axis values to search for
an intersection using domain
.
A list with x
and y
values.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | library(reconPlots)
# Straight lines (empirical)
line1 <- data.frame(x = c(1, 9), y = c(1, 9))
line2 <- data.frame(x = c(9, 1), y = c(1, 9))
curve_intersect(line1, line2)
# Curved lines (empirical)
curve1 <- data.frame(Hmisc::bezier(c(1, 8, 9), c(1, 5, 9)))
curve2 <- data.frame(Hmisc::bezier(c(1, 3, 9), c(9, 3, 1)))
curve_intersect(curve1, curve2)
# Curved lines (functional)
curve1 <- function(q) (q - 10)^2
curve2 <- function(q) q^2 + 2*q + 8
curve_intersect(curve1, curve2, empirical = FALSE, domain = c(0, 5))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.