find intersection of two lines in hesse form in matlab

To find the intersection point of two lines in Hesse form in MATLAB, we can first convert the equations to the general form of a line, and then solve the resulting system of equations.

Assuming we have two lines in Hesse form:

main.m
L1: rx*cos(a) + ry*sin(a) = d1
L2: rx*cos(b) + ry*sin(b) = d2
62 chars
3 lines

We can convert these to the general form of a line:

main.m
L1: -sin(a)*x + cos(a)*y = -d1
L2: -sin(b)*x + cos(b)*y = -d2
62 chars
3 lines

We can then represent this system of equations as a matrix equation:

main.m
A*x = b
8 chars
2 lines

Where:

main.m
A = [-sin(a) cos(a); -sin(b) cos(b)]
x = [x; y]
b = [-d1; -d2]
63 chars
4 lines

To find the solution for x, we can use MATLAB's backslash operator \:

main.m
A = [-sin(a) cos(a); -sin(b) cos(b)];
b = [-d1; -d2];
x = A \ b;
65 chars
4 lines

The resulting x will contain the intersection point of the two lines.

gistlibby LogSnag