首页 > 技术文章 > 求平面内两条直线的交点

xpvincent 2014-08-21 16:46 原文

The x and y coordinates of the point of intersection of two non-vertical lines can easily be found using the following substitutions and rearrangements.

Suppose that two lines have the equations y=ax+c and y=bx+d where a and b are the slopes (gradients) of the lines and where c and d are the y-intercepts of the lines. At the point where the two lines intersect (if they do), both y coordinates will be the same, hence the following equality:

ax+c=bx+d.

We can rearrange this expression in order to extract the value of x,

ax-bx=d-c,

and so,

x=\frac{d-c}{a-b}.

To find the y coordinate, all we need to do is substitute the value of x into either one of the two line equations, for example, into the first:

y=a\frac{d-c}{a-b}+c.

Hence, the point of intersection is

P\left( \frac{d-c}{a-b}, a\frac{d-c}{a-b}+c \right) = P\left( \frac{d-c}{a-b}, \frac{ad - bc}{a-b} \right).

Note if a = b then the two lines are parallel. If c ≠ d as well, the lines are different and there is no intersection, otherwise the two lines are identical.

推荐阅读