curve_intersect: Calculate the intersection of two curves

Description Usage Arguments Details Value Examples

Description

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.

Usage

1
curve_intersect(curve1, curve2, empirical = TRUE, domain = NULL)

Arguments

curve1

Either a data.frame with columns named x and y or a function.

curve2

Either data.frame with columns named x and y or a function.

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 empirical is false

Details

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.

Value

A list with x and y values.

Examples

 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))

andrewheiss/reconPlots documentation built on May 12, 2019, 5:39 a.m.