r - 在R中找到两条线的交点
问题描述
我有一些代码可以从一组点中绘制两条线。我需要找到两者的交集。
red <- read.table("red.txt", header=TRUE) #Get's table
mag <- red$T #T values
outer <- red$O #outer values
inner <- red$I #inner values
plot(outer, mag) #plot outer points
abline(lm(mag~outer)) #line of best fit
abline(inner, mag) #add inner line
它产生一个类似于我想要的图表。
(我知道这不是最时尚的)。如何找到线交叉的坐标?
(对不起,我只是在学习如何使用它的狡猾可能令人作呕的代码)
解决方案
从斜率/截距 (m/b) 回归输出生成直线方程。所以
reg1 <- lm(y1 ~ x1)
reg2 <- lm(y2 ~ x2)
提供斜率 (m1, m2) 和截距 (b1, b2)
y1 = m1x1 + b1
y2 = m2x2 + b2
由于 x1 = x2 = x 和 y1 = y2 = y 那么
m1x - y = -b1
m2x - y = -b2
您可以求解 x,y 未知数的方程。
推荐阅读
- javascript - Access-Control-Allow-Origin: 同源 & recaptcha & YouTube-视频
- android - 如何防止我的应用程序被系统杀死?
- python - 使用 pyenv 时无法添加任何带有诗歌的包
- visual-studio - 如何在 Visual Studio 中更改 UI 颜色,而不更改文本编辑器中的字体和文本颜色?
- ruby-on-rails - 检查是否调用了内部方法 - rspec
- bootstrap-4 - 如何使用 Bootstrap 进行响应式网页设计?
- r - 如何使用 ggplot 在 R 中绘制特定行?
- node.js - NextJS API 未发布到外部域
- php - 将条形码插入 CSV 文件
- javascript - 如何在一条又一条路径上显示d3中的过渡?