I am having difficulty rewriting my function. want to write a function that determines whether or not 2 lines intersect. I know I have to use the backslash to solve for the intersection of 2 equations, but I don't really know where to go from there so I tried my best.
The equations of the lines are :
ax + by = c
px + qy = r
- The inputs, a, b, c, p, q, and r correspond to the coefficients of the equations above. The outputs, xc, yc, flag will be determined as follows:
- If an intersection point exists, the value of flag is 1 and LineIntersect returns the intersection points: xc and yc.
*
- If many intersection points exist, the value of flag is 2, and LineIntersect returns xc and yc as an empty vector.
*
- If no intersection point exists, the value of flag is 3, and LineIntersect returns xc and yc as an empty vector.
This is the code I tried to write. Sorry for the many errors, I tried my best.
function [xc yc flag] = LineIntersect(a,b,c,p,q,r)
a.*x + b.*y = c
p.*x + q.*y = r
if x*c/y*c
flag=1
disp ('xc' 'yc')
elseif x*c/y*c
flag=2
('xc' 'yc')
elseif x*c/y*c
flag=3
disp('xc' 'yc')
flag= yc ./xc
end
Here test cases if it makes understanding the problem easier:
thanks.