I have 2 vectors:
set.seed(1)
x1 = rnorm(100,0,1)
x2 = rnorm(100,1,1)
I want to plot these as lines and then find the intersection points of the lines, also if there are multiple points of intersection then I want to locate each of them.
I have come across a similar question,and tried to solve this problem using spatstat
, but I was not able to convert my combined data frame containing both vector values to psp object
.
If you literally just have two random vectors of numbers, you can use a pretty simple technique to get the intersection of both. Just find all points where
x1
is abovex2
, and then below it on the next point, or vice-versa. These are the intersection points. Then just use the respective slopes to find the intercept for that segment.