Determine the intersection Point of the two Diagonals in a quadrilateral

1 view (last 30 days)
John on 17 May 2013
Commented: Ryan Cho on 20 Dec 2017
Hey people,
is there an easy way of dermining the intersection points of two diagonals in a quadriliteral??
Doing it by hand is quite hard since there are many special cases to consider. maybe there is already a function that helps solving the problem?
With best regards, John
Ryan Cho on 20 Dec 2017
If you are doing this on a graph get the x values of the coordinates and average them, then get the y values of the coordiantes and averagae them and then there you go (I've only tried this with parralellograms so far bu good luck)

Image Analyst on 17 May 2013
Calculate the equation of the two lines and set them equal, and solve for x, and then plug in x into either equation and get y. Just basic math
m1*x+b1 = m2*x+b2
and so on to solve for x. m is just the slope deltaY/deltaX you get from using your two diagonal points. You can use
coeffs = polyfit(x,y,1); % coeffs(1) = m, coeffs(2) = b
if you want.
John on 17 May 2013
Hi Image Analyst, i dont know in advance what pointconnections build the diagonals, so i have to try all 3 kombinations..
i have to add the examnination if the resulting points actually lie in the konvex hull of the four points...i dont know how to implement that right now...
function [ Steinerpunkt4 ] = Steineropt4( Vektor1, Vektor2, Vektor3, Vektor4 )
B=zeros(2,3);
%Testing, if line from point 1 to 3 and line from 2 to 4 is a %Steinerpoint
%Derminition of the line-equations
m1=(Vektor1(2)-Vektor3(2))/(Vektor1(1)-Vektor3(1));
b1=Vektor3(2)-m1*Vektor3(1);
m2=(Vektor2(2)-Vektor4(2))/(Vektor2(1)-Vektor4(1));
b2=Vektor4(2)-m2*Vektor4(1);
if isequal(m1,m2) % in case of parallel lines
a=1;
else a=0;
end
%to avoid zu high slope so that there is no zero-division
if (( m1 < -(10^(10)) || m1 > 10^(10)) && a==0 )
Steinerpunkty=m2*Vektor1(1)+b2;
Steinerpunkt4=[Vektor1(1), Steinerpunkty];
B(:,1)=Steinerpunkt4;
elseif (( m2 < -(10^(10)) || m2 > 10^(10)) && a==0 )
Steinerpunkty=m1*Vektor2(1)+b1;
Steinerpunkt4=[Vektor2(1), Steinerpunkty];
B(:,1)=Steinerpunkt4;
elseif a==0
A=[-m1 ,1; -m2, 1 ];
b=[b1;b2];
Steinerpunkt4 = A\b;
B(:,1)=Steinerpunkt4;
else B(:,1)=[0,0];
end
%Now testing if 1 and 4 and line 2 to 3 form a Steinerpoint
m1=(Vektor1(2)-Vektor4(2))/(Vektor1(1)-Vektor4(1));
b1=Vektor4(2)-m1*Vektor4(1);
m2=(Vektor2(2)-Vektor3(2))/(Vektor2(1)-Vektor3(1));
b2=Vektor3(2)-m2*Vektor3(1);
if isequal(m1,m2)
a=1;
else a=0;
end
if (( m1 < -(10^(10)) || m1 > 10^(10)) && a==0 )
Steinerpunkty=m2*Vektor1(1)+b2;
Steinerpunkt4=[Vektor1(1), Steinerpunkty];
B(:,2)=Steinerpunkt4;
elseif (( m2 < -(10^(10)) || m2 > 10^(10)) && a==0 )
Steinerpunkty=m1*Vektor2(1)+b1;
Steinerpunkt4=[Vektor2(1), Steinerpunkty];
B(:,2)=Steinerpunkt4;
elseif a==0
A=[-m1 ,1; -m2, 1 ];
b=[b1;b2];
Steinerpunkt4 = A\b;
B(:,2)=Steinerpunkt4;
else B(:,2)=[0,0];
end
%No testing if 1 and 2 with line 3 to 4 intersect at a Steinerpoint
m1=(Vektor1(2)-Vektor2(2))/(Vektor1(1)-Vektor2(1));
b1=Vektor2(2)-m1*Vektor2(1);
m2=(Vektor3(2)-Vektor4(2))/(Vektor3(1)-Vektor4(1));
b2=Vektor4(2)-m2*Vektor4(1);
if isequal(m1,m2)
a=1;
else a=0;
end
if (( m1 < -(10^(10)) || m1 > 10^(10)) && a==0 )
Steinerpunkty=m2*Vektor1(1)+b2;
Steinerpunkt4=[Vektor1(1), Steinerpunkty];
B(:,3)=Steinerpunkt4;
elseif (( m2 < -(10^(10)) || m2 > 10^(10)) && a==0 )
Steinerpunkty=m1*Vektor2(1)+b1;
Steinerpunkt4=[Vektor2(1), Steinerpunkty];
B(:,3)=Steinerpunkt4;
elseif a==0
A=[-m1 ,1; -m2, 1 ];
b=[b1;b2];
Steinerpunkt4 = A\b;
B(:,3)=Steinerpunkt4;
else B(:,3)=[0,0];
end
B(:,~any(B))=[];
length(B)
%Making sure that input Vektors/points are not returned
for i=1:length(B)-1
if B(1,i)==Vektor1(1) & B(2,i)==Vektor1(2)
B(:,i)=[]
end
if B(1,i)==Vektor2(1) & B(2,i)==Vektor2(2)
B(:,i)=[]
end
if B(1,i)==Vektor3(1) & B(2,i)==Vektor3(2)
B(:,i)=[]
end
if B(1,i)==Vektor4(1) & B(2,i)==Vektor4(2)
B(:,i)=[]
end
i=i+1;
end
end
Image Analyst on 17 May 2013
You HAVE to know the order of the points going around the quadrilateral. If you don't know the order, then there are multiple possible quadrilaterals you could build from the same set of points. So, because you must know the order, your diagonals are always points 1 and 3, and points 2 and 4. Always.

Sean de Wolski on 17 May 2013
Don't try and reinvent the wheel: