Finding the intersect between 2 lines
古いコメントを表示
Hello, very simple question, however, I have tried using multiple methods, such as polyxpoly() from the Mapping Toolbox to find the intersection between these 2 lines, but I cannot see what the issue is. I have just used a simulatneous equation (as shown in the code) to solve for the equation just to get an output as polyxpoly() wasn't returning anything. The y value seems correct, but the x value is widely incorrect.

Here is my code:
xrt = linspace((1/297.7), (1/446.1), 20000)
m11 = -197.7506;
x11 = 0.0031;
b11 = 20.8898;
line1=m11*(xrt-x11)+b11;
plot(xrt, line1, '-')
hold on;
m22 = -897.4321;
x22 = 0.0029'
b22 = 20.9819;
line2=m22*(xrt-x22)+b22;
plot(xrt, line2, '-')
x_intersect = (b22-b11)/(m11-m22) %find the x point
y_intersect = m11*x0+b11
plot(x_intersect,y_intersect,'r*')
The output values for x_intersect and y_intersect:

Any help would be greatly appreciated.
Thanks.
2 件のコメント
Actually your math is incorrect, as the y-value is not correct either:
xrt = linspace((1/297.7), (1/446.1), 20000);
m11 = -197.7506;
x11 = 0.0031;
b11 = 20.8898;
line1=@(xrt) m11*(xrt-x11)+b11;
m22 = -897.4321;
x22 = 0.0029';
b22 = 20.9819;
line2=@(xrt) m22*(xrt-x22)+b22;
x_intersect = (b22-b11)/(m11-m22) %find the x point
y_intersect = line2(x_intersect)
plot(xrt, line1(xrt), '-')
hold on;
plot(xrt, line2(xrt), '-')
plot(x_intersect,y_intersect,'r*')
Tb
2021 年 2 月 11 日
採用された回答
その他の回答 (1 件)
David Hill
2021 年 2 月 11 日
xrt = linspace((1/297.7), (1/446.1), 20000);
m11 = -197.7506;
x11 = 0.0031;
b11 = 20.8898;
line1=@(x)m11*(x-x11)+b11;
plot(xrt, line1(xrt), '-');
hold on;
m22 = -897.4321;
x22 = 0.0029;
b22 = 20.9819;
line2=@(x)m22*(x-x22)+b22;
plot(xrt, line2(xrt), '-');
A=[1,-m11;1,-m22];
b=[b11-m11*x11;b22-m22*x22];
c=A\b;
plot(c(2),c(1),'g*');
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
