![]() | This ![]() It is of interest to the following WikiProjects: | ||||||||||
|
![]() | This article was nominated for deletion on 9 March 2013 (UTC). The result of the discussion was keep. |
I am being bold in updating, and hopefully not making a total donkeys butt of myself at the same time. --Chase-san (talk) 06:49, 10 January 2008 (UTC)
So what happens when the denominator is zero? Article's still lacking some information. -- Mike Kamermans, Nov. 2010 —Preceding unsigned comment added by 77.167.120.32 (talk) 21:25, 15 November 2010 (UTC)
We really need the match for a case where the end points of the lines are specified in terms of x, y and z coordinates, not just x and y. But I'd keep the 2D case too, as that's no doubt simpler and will be sufficient for most peoples needs. Drkirkby (talk) 12:28, 13 November 2011 (UTC)
This was added to the article and I removed it for discussion here.
Note: The equation above do not return the intersection of two lines. There may be some unknown additional step needed to get the correct intersection point, or the determinant may be written incorrectly. Here is a version that works correctly. This corresponds to the simplified version in the citation. This code is for MatLab.
x = [0 0; 6 6]; %# Starting points in first row, ending points in second rowy = [0 6; 6 0];
The equations from the above source can then be coded up as follows:
dx = diff(x); %# Take the differences down each columndy = diff(y);
den = dx(1)*dy(2)-dy(1)*dx(2); %# Precompute the denominator
ua = (dx(2)*(y(1)-y(3))-dy(2)*(x(1)-x(3)))/den;
ub = (dx(1)*(y(1)-y(3))-dy(1)*(x(1)-x(3)))/den;
And you can now compute the intersection point of the two lines:
xi = x(1)+ua*dx(1);yi = y(1)+ua*dy(1);
For the example in the question, the above code gives xi = 3 and yi = 3, as expected. If you want to check that the intersection point lies between the endpoints of the lines (i.e. they are finite line segments), you just have to check that the values ua and ub both lie between 0 and 1:isInSegment = all(([ua ub] >= 0) & ([ua ub] <= 1));
A couple more points from the tutorial I linked to above:
If the denominator den is 0 then the two lines are parallel.
If the denominator and numerator for the equations for ua and ub are 0 then the two lines are coincident.
-- 06:46, 26 January 2014 69.230.99.150
I am leaving it to others to straighten out any problems. Bill Cherowitzo (talk) 05:34, 27 January 2014 (UTC)
By the way, I had no trouble in calculating (3,3) as the intersection point in your example using the determinental form in the article - what do you think may be wrong with it? Bill Cherowitzo (talk) 23:25, 28 January 2014 (UTC)
The presented formula for computing the line–line intersection is wrong. The comment below also notes this. How is this article still around? Please try the proposed computations yourself and then remove this article. — Preceding unsigned comment added by 94.217.39.180 (talk) 23:18, 9 July 2014 (UTC)
Look at the following example. Line1: x1,y1 = 15,15 to x2,y2 = 15, 100. Line2: x3,y3 = 10,20 to x4,y4 = 20,20.
Obviously our intersection point should habe an x-coordinate of 15. This not the case with the given Formular for Px. — Preceding unsigned comment added by 94.217.46.136 (talk) 13:22, 10 July 2014 (UTC)
Converting one of the point-vector pairs to two planes intersection as the line representation, gives two line-plane intersections to test. — Preceding unsigned comment added by Goofyseeker311 (talk • contribs) 11:36, 11 October 2023 (UTC)