求平面内两条直线的交点

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=afrac{d-c}{a-b}+c.

Hence, the point of intersection is

Pleft( frac{d-c}{a-b}, afrac{d-c}{a-b}+c 
ight) = Pleft( frac{d-c}{a-b}, frac{ad - bc}{a-b} 
ight).

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.

原文地址:https://www.cnblogs.com/xpvincent/p/3927553.html