Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有两行:
line1 = [1 2; ... 5 4]; line2 = [1 7; ... 4 2];
我怎样才能像前面的一样得到任何两条线的交点?
这更像是一个数学问题,而不是编程问题:
一条线的方程是y = ax+b
y = ax+b
找到a,你做
a
a = (y2-y1)/(x2-x1)...
或者在你的情况下:
a = (line1(1,2)-line1(2,2))/((line1(1,1)-line1(2,1)); a = 0.5
然后你b在你的行中找到一个点,即:
b
y = 0.5x+b --> 2 = 0.5(1)+b --> b = 1.5; y1 = 0.5x+1.5
对另一条线做同样的事情。
然后做y1 = y2解决。
y1 = y2