Currently, there is no function in MATLAB that allows you to find intersection of any two lines or line segments. If you know that two lines in 2D intersect (are not skew) and you know two points on each of those lines, you can find the intersection using the following formula:
L1_x1 = 1;
L1_y1 = 2;
L1_x2 = 3;
L1_y2 = 4;
L2_x1 = 1;
L2_y1 = 4;
L2_x2 = 3;
L2_y2 = 3;
plot([L1_x1 L1_x2], [L1_y1 L1_y2])
hold on
plot([L2_x1 L2_x2], [L2_y1 L2_y2])
Dx12 = L1_x1-L1_x2;
Dx34 = L2_x1-L2_x2;
Dy12 = L1_y1-L1_y2;
Dy34 = L2_y1-L2_y2;
Dx24 = L1_x2-L2_x2;
Dy24 = L1_y2-L2_y2;
ts = [Dx12 -Dx34; Dy12 -Dy34] \ [-Dx24; -Dy24];
P = ts(1)*[L1_x1; L1_y1] + (1-ts(1))*[L1_x2; L1_y2];
Q = ts(2)*[L2_x1; L2_y1] + (1-ts(2))*[L2_x2; L2_y2];
plot(P(1), P(2), 'ro')
plot(Q(1), Q(2), 'bo')
hold off
P and Q both contain the values of the common intersection point.
Alternately, if you have discrete data and know that some point is in data sets for both lines, you can use the "intersect" function.
Finally, if you own the "Mapping Toolbox" for MATLAB, you can use the "polyxpoly" function to calculate the intersection point.
For more information on these or any other command, type the following at the MATLAB command prompt:
help function_name
doc function_name
Best Answer