Find intersection of two lines with four points

Find intersection of two lines with four points
Line Intersection Calculator

When two lines are intersected, there exists a point of intersection on which the two lines will touch each other. The point of intersection depends on the coordinate system that is being used to describe the lines and their intersection.

Find the equation of one line

In order to find the point of line intersection calculator, you first need to find the equation of each line. To do this, you need two points that lie on the line. These points can be found by solving a system of linear equations. Once you have the points, plug them into the slope-intercept form equation and solve for y. This will give you the y-intercept, which is one point that lies on the line. The slope can be found by taking the rise (the change in y) over the run (the change in x).

Step 2. Find the equation of a second line (seven sentences): To find a second equation, use a different set of points that also lie on the line. You’ll then find the y-intercept, slope, and y-intercept again using the same steps as before. For example, if you have four points that all lie on a line, you would use three of those points to solve for the first equation’s intercepts. You would then use the other three points to solve for the second equation’s intercepts. Finally, plug these intercepts into both equations and solve them simultaneously.

Find the equation of another line

In order to find the point of line intersection calculator, you’ll need to calculate the equation of each line. To do this, you’ll need two points that lie on each line. Once you have those points, use the slope formula to calculate the slope of each line. With the slope in hand, plug one point’s coordinates into the equation y=mx+b and solve for b. You should now have everything you need to plug into the point-of-intersection formula! 2 points define a line; 2 equations are necessary to calculate a point of intersection. The first is given by (x1,y1) +(x2,y2). The second is given by (x3,y3). Plugging these values into the point-of-intersection formula gives us (-8,-4), which corresponds to (x=0,y=-8) as the point of intersection.

One might also note that when graphed out, the two lines intersect at the following coordinate: x=-4/9=-5/9 y=-4/9=-5/9. It can be seen from this graph that the two lines intersect at (-5/9,-5/9). The final answer is -5/-10

Graphing both equations

The next step is to graph both equations on a coordinate plane. This will help you visualize where the lines intersect and make it easier to find the point of intersection. To graph an equation, you’ll need to plot points that satisfy the equation. For each equation, start by plotting some points that satisfy the equation. Then, draw a line through those points. The line will be your graphed equation. Plot points that are satisfying for each of the equations and then connect them with a line.

The first equation is y = 2x + 1

The second equation is y = -2x – 3

Plotting points for these two equations yields these coordinates: (1, 4), (-3, -5), (0, 0) and (-1,-2). When these two lines are drawn together, they cross at (-3,-5).

Also Check: Parabola Calculator

Finding an angle where lines intersect

You can use a line intersection calculator to find the point of intersection for two lines. To do this, you’ll need the slope and y-intercept for each line. The slope is the number that tells you how steep the line is, and the y-intercept is the point where the line crosses the y-axis. To find the angle where lines intersect, you’ll need to find the inverse tangent of the slopes of both lines. Then, you’ll subtract the smaller from the larger (inverse tangent) by adding them together. Once these values are found, it’s possible to solve for x-coordinates by dividing them by 3.

The new value will be called a point. It’s also possible to make calculations with this equation because it includes a division sign between two variables–x and 3.

Finding point of intersection

The line intersection calculator is the point where the two lines meet. To find it, we need to find the x- and y-coordinates of the point. The x-coordinate is easy to find; it is simply the average of the x-coordinates of the two points on each line. The y-coordinate is a bit more difficult, but we can use a similar method. First, we find the slope of each line. Then, we plug in one set of coordinates (x1, y1) from each line into the equation y = mx + b. This will give us two equations with two unknowns (y and b). We can then solve for b using algebra and plug that value back into either equation to solve for y. For example, if we take the first pair of coordinates from both lines, then their slope would be -3/4. Plugging those numbers into the first equation gives us y= -4x+b. Solving for b, we get b=-2. Now if we plug this value back into the first equation and solve for y, we get y=-2x+5 which simplifies to 2x+5=5 which equals 6! So our point of intersection would be at (6,-2).

Example 1 (2 Points)

The line segment joining points A(1,2) and B(3,4) intersects the line segment joining points C(5,6) and D(7,8) at the point P(x,y). To find x and y, we use the following formula:

First, we calculate the slope of each line. The slope of line segment AB is m1 = (4-2)/(3-1) = 2/2 = 1. The slope of line segment CD is m2 = (8-6)/(7-5) = 2/2 = 1. The slope of line segment AD is m3 = (4-6)/(7-5) = -2/2=-1. Next, we need to determine which one has a positive or negative slope by looking at the signs next to their values on the top row in brackets. line intersection calculator AB has a positive slope while lines CD and AD have negative slopes. Thus, if our answer is positive then P must be at position A; if our answer is negative then P must be at position B.

$\begingroup$

Line A goes through the points (4,5) and (-2,-1) and line B goes through the points (3,3) and (6,1). At what point do they intersect?

I found the equations of the 2 lines, for A I got: $y = 9-x$, and for B I got $y = -\frac{2}{3}x + 5$ and set them equal to each other but it didn't work out.

$\endgroup$

6

In Euclidean geometry, the intersection of a line and a line can be the empty set, a point, or another line. Distinguishing these cases and finding the intersection have uses, for example, in computer graphics, motion planning, and collision detection.

Find intersection of two lines with four points

Two intersecting lines

In three-dimensional Euclidean geometry, if two lines are not in the same plane, they have no point of intersection and are called skew lines. If they are in the same plane, however, there are three possibilities: if they coincide (are not distinct lines), they have an infinitude of points in common (namely all of the points on either of them); if they are distinct but have the same slope, they are said to be parallel and have no points in common; otherwise, they have a single point of intersection.

The distinguishing features of non-Euclidean geometry are the number and locations of possible intersections between two lines and the number of possible lines with no intersections (parallel lines) with a given line.[further explanation needed]

A necessary condition for two lines to intersect is that they are in the same plane—that is, are not skew lines. Satisfaction of this condition is equivalent to the tetrahedron with vertices at two of the points on one line and two of the points on the other line being degenerate in the sense of having zero volume. For the algebraic form of this condition, see Skew lines § Testing for skewness.

Given two points on each line

First we consider the intersection of two lines L1 and L2 in two-dimensional space, with line L1 being defined by two distinct points (x1, y1) and (x2, y2), and line L2 being defined by two distinct points (x3, y3) and (x4, y4).[1]

The intersection P of line L1 and L2 can be defined using determinants.

P x = | | x 1 y 1 x 2 y 2 | | x 1 1 x 2 1 | | x 3 y 3 x 4 y 4 | | x 3 1 x 4 1 | | | | x 1 1 x 2 1 | | y 1 1 y 2 1 | | x 3 1 x 4 1 | | y 3 1 y 4 1 | | P y = | | x 1 y 1 x 2 y 2 | | y 1 1 y 2 1 | | x 3 y 3 x 4 y 4 | | y 3 1 y 4 1 | | | | x 1 1 x 2 1 | | y 1 1 y 2 1 | | x 3 1 x 4 1 | | y 3 1 y 4 1 | | {\displaystyle P_{x}={\frac {\begin{vmatrix}{\begin{vmatrix}x_{1}&y_{1}\\x_{2}&y_{2}\end{vmatrix}}&{\begin{vmatrix}x_{1}&1\\x_{2}&1\end{vmatrix}}\\\\{\begin{vmatrix}x_{3}&y_{3}\\x_{4}&y_{4}\end{vmatrix}}&{\begin{vmatrix}x_{3}&1\\x_{4}&1\end{vmatrix}}\end{vmatrix}}{\begin{vmatrix}{\begin{vmatrix}x_{1}&1\\x_{2}&1\end{vmatrix}}&{\begin{vmatrix}y_{1}&1\\y_{2}&1\end{vmatrix}}\\\\{\begin{vmatrix}x_{3}&1\\x_{4}&1\end{vmatrix}}&{\begin{vmatrix}y_{3}&1\\y_{4}&1\end{vmatrix}}\end{vmatrix}}}\,\!\qquad P_{y}={\frac {\begin{vmatrix}{\begin{vmatrix}x_{1}&y_{1}\\x_{2}&y_{2}\end{vmatrix}}&{\begin{vmatrix}y_{1}&1\\y_{2}&1\end{vmatrix}}\\\\{\begin{vmatrix}x_{3}&y_{3}\\x_{4}&y_{4}\end{vmatrix}}&{\begin{vmatrix}y_{3}&1\\y_{4}&1\end{vmatrix}}\end{vmatrix}}{\begin{vmatrix}{\begin{vmatrix}x_{1}&1\\x_{2}&1\end{vmatrix}}&{\begin{vmatrix}y_{1}&1\\y_{2}&1\end{vmatrix}}\\\\{\begin{vmatrix}x_{3}&1\\x_{4}&1\end{vmatrix}}&{\begin{vmatrix}y_{3}&1\\y_{4}&1\end{vmatrix}}\end{vmatrix}}}\,\!}  

The determinants can be written out as:

P x = ( x 1 y 2 − y 1 x 2 ) ( x 3 − x 4 ) − ( x 1 − x 2 ) ( x 3 y 4 − y 3 x 4 ) ( x 1 − x 2 ) ( y 3 − y 4 ) − ( y 1 − y 2 ) ( x 3 − x 4 ) P y = ( x 1 y 2 − y 1 x 2 ) ( y 3 − y 4 ) − ( y 1 − y 2 ) ( x 3 y 4 − y 3 x 4 ) ( x 1 − x 2 ) ( y 3 − y 4 ) − ( y 1 − y 2 ) ( x 3 − x 4 ) {\displaystyle {\begin{aligned}P_{x}&={\frac {(x_{1}y_{2}-y_{1}x_{2})(x_{3}-x_{4})-(x_{1}-x_{2})(x_{3}y_{4}-y_{3}x_{4})}{(x_{1}-x_{2})(y_{3}-y_{4})-(y_{1}-y_{2})(x_{3}-x_{4})}}\\[4px]P_{y}&={\frac {(x_{1}y_{2}-y_{1}x_{2})(y_{3}-y_{4})-(y_{1}-y_{2})(x_{3}y_{4}-y_{3}x_{4})}{(x_{1}-x_{2})(y_{3}-y_{4})-(y_{1}-y_{2})(x_{3}-x_{4})}}\end{aligned}}}  

When the two lines are parallel or coincident, the denominator is zero. If the lines are almost parallel, then a computer solution might encounter numeric problems implementing the solution described above: the recognition of this condition might require an approximate test in a practical application. An alternate approach might be to rotate the line segments so that one of them is horizontal, whence the solution of the rotated parametric form of the second line is easily obtained. Careful discussion of the special cases is required (parallel or coincident lines, overlapping or non-overlapping intervals).

Given two points on each line segment

Note that the intersection point above is for the infinitely long lines defined by the points, rather than the line segments between the points, and can produce an intersection point not contained in either of the two line segments. In order to find the position of the intersection in respect to the line segments, we can define lines L1 and L2 in terms of first degree Bézier parameters:

L 1 = [ x 1 y 1 ] + t [ x 2 − x 1 y 2 − y 1 ] , L 2 = [ x 3 y 3 ] + u [ x 4 − x 3 y 4 − y 3 ] {\displaystyle L_{1}={\begin{bmatrix}x_{1}\\y_{1}\end{bmatrix}}+t{\begin{bmatrix}x_{2}-x_{1}\\y_{2}-y_{1}\end{bmatrix}},\qquad L_{2}={\begin{bmatrix}x_{3}\\y_{3}\end{bmatrix}}+u{\begin{bmatrix}x_{4}-x_{3}\\y_{4}-y_{3}\end{bmatrix}}}  

(where t and u are real numbers). The intersection point of the lines is found with one of the following values of t or u, where

t = | x 1 − x 3 x 3 − x 4 y 1 − y 3 y 3 − y 4 | | x 1 − x 2 x 3 − x 4 y 1 − y 2 y 3 − y 4 | = ( x 1 − x 3 ) ( y 3 − y 4 ) − ( y 1 − y 3 ) ( x 3 − x 4 ) ( x 1 − x 2 ) ( y 3 − y 4 ) − ( y 1 − y 2 ) ( x 3 − x 4 ) {\displaystyle t={\frac {\begin{vmatrix}x_{1}-x_{3}&x_{3}-x_{4}\\y_{1}-y_{3}&y_{3}-y_{4}\end{vmatrix}}{\begin{vmatrix}x_{1}-x_{2}&x_{3}-x_{4}\\y_{1}-y_{2}&y_{3}-y_{4}\end{vmatrix}}}={\frac {(x_{1}-x_{3})(y_{3}-y_{4})-(y_{1}-y_{3})(x_{3}-x_{4})}{(x_{1}-x_{2})(y_{3}-y_{4})-(y_{1}-y_{2})(x_{3}-x_{4})}}}  

and

u = | x 1 − x 3 x 1 − x 2 y 1 − y 3 y 1 − y 2 | | x 1 − x 2 x 3 − x 4 y 1 − y 2 y 3 − y 4 | = ( x 1 − x 2 ) ( y 1 − y 3 ) − ( y 1 − y 2 ) ( x 1 − x 3 ) ( x 1 − x 2 ) ( y 3 − y 4 ) − ( y 1 − y 2 ) ( x 3 − x 4 ) , {\displaystyle u={\frac {\begin{vmatrix}x_{1}-x_{3}&x_{1}-x_{2}\\y_{1}-y_{3}&y_{1}-y_{2}\end{vmatrix}}{\begin{vmatrix}x_{1}-x_{2}&x_{3}-x_{4}\\y_{1}-y_{2}&y_{3}-y_{4}\end{vmatrix}}}={\frac {(x_{1}-x_{2})(y_{1}-y_{3})-(y_{1}-y_{2})(x_{1}-x_{3})}{(x_{1}-x_{2})(y_{3}-y_{4})-(y_{1}-y_{2})(x_{3}-x_{4})}},}  

with

( P x , P y ) = ( x 1 + t ( x 2 − x 1 ) , y 1 + t ( y 2 − y 1 ) ) or ( P x , P y ) = ( x 3 + u ( x 4 − x 3 ) , y 3 + u ( y 4 − y 3 ) ) {\displaystyle (P_{x},P_{y})={\bigl (}x_{1}+t(x_{2}-x_{1}),\;y_{1}+t(y_{2}-y_{1}){\bigr )}\quad {\text{or}}\quad (P_{x},P_{y})={\bigl (}x_{3}+u(x_{4}-x_{3}),\;y_{3}+u(y_{4}-y_{3}){\bigr )}}  

There will be an intersection if 0 ≤ t ≤ 1 and 0 ≤ u ≤ 1. The intersection point falls within the first line segment if 0 ≤ t ≤ 1, and it falls within the second line segment if 0 ≤ u ≤ 1. These inequalities can be tested without the need for division, allowing rapid determination of the existence of any line segment intersection before calculating its exact point.[2]

Given two line equations

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:

a x + c = b x + d . {\displaystyle ax+c=bx+d.}  

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

a x − b x = d − c , {\displaystyle ax-bx=d-c,}  

and so,

x = d − c a − b . {\displaystyle 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 d − c a − b + c . {\displaystyle y=a{\frac {d-c}{a-b}}+c.}  

Hence, the point of intersection is

P = ( d − c a − b , a d − c a − b + c ) . {\displaystyle P=\left({\frac {d-c}{a-b}},a{\frac {d-c}{a-b}}+c\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 and intersect at every point.

Using homogeneous coordinates

By using homogeneous coordinates, the intersection point of two implicitly defined lines can be determined quite easily. In 2D, every point can be defined as a projection of a 3D point, given as the ordered triple (x, y, w). The mapping from 3D to 2D coordinates is (x′, y′) = (x/w, y/w). We can convert 2D points to homogeneous coordinates by defining them as (x, y, 1).

Assume that we want to find intersection of two infinite lines in 2-dimensional space, defined as a1x + b1y + c1 = 0 and a2x + b2y + c2 = 0. We can represent these two lines in line coordinates as U1 = (a1, b1, c1) and U2 = (a2, b2, c2). The intersection P′ of two lines is then simply given by[3]

P ′ = ( a p , b p , c p ) = U 1 × U 2 = ( b 1 c 2 − b 2 c 1 , a 2 c 1 − a 1 c 2 , a 1 b 2 − a 2 b 1 ) {\displaystyle P'=(a_{p},b_{p},c_{p})=U_{1}\times U_{2}=(b_{1}c_{2}-b_{2}c_{1},a_{2}c_{1}-a_{1}c_{2},a_{1}b_{2}-a_{2}b_{1})}  

If cp = 0, the lines do not intersect.

The intersection of two lines can be generalized to involve additional lines. The existence of and expression for the n-line intersection problem are as follows.

In two dimensions

In two dimensions, more than two lines almost certainly do not intersect at a single point. To determine if they do and, if so, to find the intersection point, write the ith equation (i = 1, …, n) as

[ a i 1 a i 2 ] [ x y ] = b i , {\displaystyle {\begin{bmatrix}a_{i1}&a_{i2}\end{bmatrix}}{\begin{bmatrix}x\\y\end{bmatrix}}=b_{i},}  

and stack these equations into matrix form as

A w = b , {\displaystyle \mathbf {A} \mathbf {w} =\mathbf {b} ,}  

where the ith row of the n × 2 matrix A is [ai1, ai2], w is the 2 × 1 vector [x
y
]
, and the ith element of the column vector b is bi. If A has independent columns, its rank is 2. Then if and only if the rank of the augmented matrix [A | b] is also 2, there exists a solution of the matrix equation and thus an intersection point of the n lines. The intersection point, if it exists, is given by

w = A g b = ( A T A ) − 1 A T b , {\displaystyle \mathbf {w} =\mathbf {A} ^{\mathrm {g} }\mathbf {b} =\left(\mathbf {A} ^{\mathsf {T}}\mathbf {A} \right)^{-1}\mathbf {A} ^{\mathsf {T}}\mathbf {b} ,}  

where Ag is the Moore–Penrose generalized inverse of A (which has the form shown because A has full column rank). Alternatively, the solution can be found by jointly solving any two independent equations. But if the rank of A is only 1, then if the rank of the augmented matrix is 2 there is no solution but if its rank is 1 then all of the lines coincide with each other.

In three dimensions

The above approach can be readily extended to three dimensions. In three or more dimensions, even two lines almost certainly do not intersect; pairs of non-parallel lines that do not intersect are called skew lines. But if an intersection does exist it can be found, as follows.

In three dimensions a line is represented by the intersection of two planes, each of which has an equation of the form

[ a i 1 a i 2 a i 3 ] [ x y z ] = b i . {\displaystyle {\begin{bmatrix}a_{i1}&a_{i2}&a_{i3}\end{bmatrix}}{\begin{bmatrix}x\\y\\z\end{bmatrix}}=b_{i}.}  

Thus a set of n lines can be represented by 2n equations in the 3-dimensional coordinate vector w:

A w = b {\displaystyle \mathbf {A} \mathbf {w} =\mathbf {b} }  

where now A is 2n × 3 and b is 2n × 1. As before there is a unique intersection point if and only if A has full column rank and the augmented matrix [A | b] does not, and the unique intersection if it exists is given by

w = ( A T A ) − 1 A T b . {\displaystyle \mathbf {w} =\left(\mathbf {A} ^{\mathsf {T}}\mathbf {A} \right)^{-1}\mathbf {A} ^{\mathsf {T}}\mathbf {b} .}  

In two or more dimensions, we can usually find a point that is mutually closest to two or more lines in a least-squares sense.

In two dimensions

In the two-dimensional case, first, represent line i as a point pi on the line and a unit normal vector i, perpendicular to that line. That is, if x1 and x2 are points on line 1, then let p1 = x1 and let

n ^ 1 := [ 0 − 1 1 0 ] x 2 − x 1 ‖ x 2 − x 1 ‖ {\displaystyle \mathbf {\hat {n}} _{1}:={\begin{bmatrix}0&-1\\1&0\end{bmatrix}}{\frac {\mathbf {x} _{2}-\mathbf {x} _{1}}{\|\mathbf {x} _{2}-\mathbf {x} _{1}\|}}}  

which is the unit vector along the line, rotated by a right angle.

Note that the distance from a point x to the line (p, ) is given by

d ( x , ( p , n ^ ) ) = | ( x − p ) ⋅ n ^ | = | ( x − p ) T n ^ | = | n ^ T ( x − p ) | = ( x − p ) T n ^ n ^ T ( x − p ) . {\displaystyle d{\bigl (}\mathbf {x} ,(\mathbf {p} ,\mathbf {\hat {n}} ){\bigr )}={\bigl |}(\mathbf {x} -\mathbf {p} )\cdot \mathbf {\hat {n}} {\bigr |}=\left|(\mathbf {x} -\mathbf {p} )^{\mathsf {T}}\mathbf {\hat {n}} \right|=\left|\mathbf {\hat {n}} ^{\mathsf {T}}(\mathbf {x} -\mathbf {p} )\right|={\sqrt {(\mathbf {x} -\mathbf {p} )^{\mathsf {T}}\mathbf {\hat {n}} \mathbf {\hat {n}} ^{\mathsf {T}}(\mathbf {x} -\mathbf {p} )}}.}  

And so the squared distance from a point x to a line is

d ( x , ( p , n ^ ) ) 2 = ( x − p ) T ( n ^ n ^ T ) ( x − p ) . {\displaystyle d{\bigl (}\mathbf {x} ,(\mathbf {p} ,\mathbf {\hat {n}} ){\bigr )}^{2}=(\mathbf {x} -\mathbf {p} )^{\mathsf {T}}\left(\mathbf {\hat {n}} \mathbf {\hat {n}} ^{\mathsf {T}}\right)(\mathbf {x} -\mathbf {p} ).}  

The sum of squared distances to many lines is the cost function:

E ( x ) = ∑ i ( x − p i ) T ( n ^ i n ^ i T ) ( x − p i ) . {\displaystyle E(\mathbf {x} )=\sum _{i}(\mathbf {x} -\mathbf {p} _{i})^{\mathsf {T}}\left(\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\right)(\mathbf {x} -\mathbf {p} _{i}).}  

This can be rearranged:

E ( x ) = ∑ i x T n ^ i n ^ i T x − x T n ^ i n ^ i T p i − p i T n ^ i n ^ i T x + p i T n ^ i n ^ i T p i = x T ( ∑ i n ^ i n ^ i T ) x − 2 x T ( ∑ i n ^ i n ^ i T p i ) + ∑ i p i T n ^ i n ^ i T p i . {\displaystyle {\begin{aligned}E(\mathbf {x} )&=\sum _{i}\mathbf {x} ^{\mathsf {T}}\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\mathbf {x} -\mathbf {x} ^{\mathsf {T}}\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\mathbf {p} _{i}-\mathbf {p} _{i}^{\mathsf {T}}\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\mathbf {x} +\mathbf {p} _{i}^{\mathsf {T}}\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\mathbf {p} _{i}\\&=\mathbf {x} ^{\mathsf {T}}\left(\sum _{i}\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\right)\mathbf {x} -2\mathbf {x} ^{\mathsf {T}}\left(\sum _{i}\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\mathbf {p} _{i}\right)+\sum _{i}\mathbf {p} _{i}^{\mathsf {T}}\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\mathbf {p} _{i}.\end{aligned}}}  

To find the minimum, we differentiate with respect to x and set the result equal to the zero vector:

∂ E ( x ) ∂ x = 0 = 2 ( ∑ i n ^ i n ^ i T ) x − 2 ( ∑ i n ^ i n ^ i T p i ) {\displaystyle {\frac {\partial E(\mathbf {x} )}{\partial \mathbf {x} }}={\boldsymbol {0}}=2\left(\sum _{i}\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\right)\mathbf {x} -2\left(\sum _{i}\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\mathbf {p} _{i}\right)}  

so

( ∑ i n ^ i n ^ i T ) x = ∑ i n ^ i n ^ i T p i {\displaystyle \left(\sum _{i}\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\right)\mathbf {x} =\sum _{i}\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\mathbf {p} _{i}}  

and so

x = ( ∑ i n ^ i n ^ i T ) − 1 ( ∑ i n ^ i n ^ i T p i ) . {\displaystyle \mathbf {x} =\left(\sum _{i}\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\right)^{-1}\left(\sum _{i}\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\mathbf {p} _{i}\right).}  

In more than two dimensions

While i is not well-defined in more than two dimensions, this can be generalized to any number of dimensions by noting that i iT is simply the symmetric matrix with all eigenvalues unity except for a zero eigenvalue in the direction along the line providing a seminorm on the distance between pi and another point giving the distance to the line. In any number of dimensions, if i is a unit vector along the ith line, then

n ^ i n ^ i T {\displaystyle \mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}}   becomes I − v ^ i v ^ i T {\displaystyle \mathbf {I} -\mathbf {\hat {v}} _{i}\mathbf {\hat {v}} _{i}^{\mathsf {T}}}  

where I is the identity matrix, and so[4]

x = ( ∑ i I − v ^ i v ^ i T ) − 1 ( ∑ i ( I − v ^ i v ^ i T ) p i ) . {\displaystyle x=\left(\sum _{i}\mathbf {I} -\mathbf {\hat {v}} _{i}\mathbf {\hat {v}} _{i}^{\mathsf {T}}\right)^{-1}\left(\sum _{i}\left(\mathbf {I} -\mathbf {\hat {v}} _{i}\mathbf {\hat {v}} _{i}^{\mathsf {T}}\right)\mathbf {p} _{i}\right).}  

General derivation

In order to find the intersection point of a set of lines, we calculate the point with minimum distance to them. Each line is defined by an origin ai and a unit direction vector i. The square of the distance from a point p to one of the lines is given from Pythagoras:

d i 2 = ‖ p − a i ‖ 2 − ( ( p − a i ) T n ^ i ) 2 = ( p − a i ) T ( p − a i ) − ( ( p − a i ) T n ^ i ) 2 {\displaystyle d_{i}^{2}=\left\|\mathbf {p} -\mathbf {a} _{i}\right\|^{2}-\left(\left(\mathbf {p} -\mathbf {a} _{i}\right)^{\mathsf {T}}\mathbf {\hat {n}} _{i}\right)^{2}=\left(\mathbf {p} -\mathbf {a} _{i}\right)^{\mathsf {T}}\left(\mathbf {p} -\mathbf {a} _{i}\right)-\left(\left(\mathbf {p} -\mathbf {a} _{i}\right)^{\mathsf {T}}\mathbf {\hat {n}} _{i}\right)^{2}}  

where (pai)T i is the projection of pai on line i. The sum of distances to the square to all lines is

∑ i d i 2 = ∑ i ( ( p − a i ) T ( p − a i ) − ( ( p − a i ) T n ^ i ) 2 ) {\displaystyle \sum _{i}d_{i}^{2}=\sum _{i}\left({\left(\mathbf {p} -\mathbf {a} _{i}\right)^{\mathsf {T}}}\left(\mathbf {p} -\mathbf {a} _{i}\right)-{\left(\left(\mathbf {p} -\mathbf {a} _{i}\right)^{\mathsf {T}}\mathbf {\hat {n}} _{i}\right)^{2}}\right)}  

To minimize this expression, we differentiate it with respect to p.

∑ i ( 2 ( p − a i ) − 2 ( ( p − a i ) T n ^ i ) n ^ i ) = 0 {\displaystyle \sum _{i}\left(2\left(\mathbf {p} -\mathbf {a} _{i}\right)-2\left(\left(\mathbf {p} -\mathbf {a} _{i}\right)^{\mathsf {T}}\mathbf {\hat {n}} _{i}\right)\mathbf {\hat {n}} _{i}\right)={\boldsymbol {0}}}   ∑ i ( p − a i ) = ∑ i ( n ^ i n ^ i T ) ( p − a i ) {\displaystyle \sum _{i}\left(\mathbf {p} -\mathbf {a} _{i}\right)=\sum _{i}\left(\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\right)\left(\mathbf {p} -\mathbf {a} _{i}\right)}  

which results in

( ∑ i ( I − n ^ i n ^ i T ) ) p = ∑ i ( I − n ^ i n ^ i T ) a i {\displaystyle \left(\sum _{i}\left(\mathbf {I} -\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\right)\right)\mathbf {p} =\sum _{i}\left(\mathbf {I} -\mathbf {\hat {n}} _{i}\mathbf {\hat {n}} _{i}^{\mathsf {T}}\right)\mathbf {a} _{i}}  

where I is the identity matrix. This is a matrix Sp = C, with solution p = S+C, where S+ is the pseudo-inverse of S.

 

From left to right: Euclidean geometry, spherical geometry, and hyperbolic geometry

In spherical geometry, any two lines intersect.[5]

In hyperbolic geometry, given any line and any point, there are infinitely many lines through that point that do not intersect the given line.[5]

  • Line segment intersection
  • Line intersection in projective space
  • Distance between two parallel lines
  • Distance from a point to a line
  • Line–plane intersection
  • Parallel postulate
  • Triangulation (computer vision)
  • Intersection (Euclidean geometry) § Two line segments

  1. ^ Weisstein, Eric W. "Line-Line Intersection". MathWorld. Retrieved 2008-01-10.
  2. ^ Antonio, Franklin (1992). "Chapter IV.6: Faster Line Segment Intersection". In Kirk, David (ed.). Graphics Gems III. Academic Press, Inc. pp. 199–202. ISBN 0-12-059756-X.
  3. ^ Birchfield, Stanley (1998-04-23). "Homogeneous coordinates". robotics.stanford.edu. Archived from the original on 2000-09-29. Retrieved 2015-08-18.
  4. ^ Traa, Johannes (2013). "Least-Squares Intersection of Lines" (PDF). cal.cs.illinois.edu. Archived from the original (PDF) on 2017-09-12. Retrieved 2018-08-30.
  5. ^ a b "Exploring Hyperbolic Space" (PDF). math.berkeley.edu. Retrieved 2022-06-03.{{cite web}}: CS1 maint: url-status (link)

  • Distance between Lines and Segments with their Closest Point of Approach, applicable to two, three, or more dimensions.

Retrieved from "https://en.wikipedia.org/w/index.php?title=Line–line_intersection&oldid=1108082813"