Intersecting lines from coordinates and fixed lines

2 views (last 30 days)
How can I find the intersecting points between the line that is created from a set of coordinates and a fixed line? I am trying to use the Curve Intersections function.
Specifically, I have a set of coordinates with x: (NAN NAN NAN x1 x2 x3 x4 x5... xN-1 xN NAN NAN NAN) and y:(NAN NAN NAN y1 y2 y3 y4 y5...yN-1 yN NAN NAN NAN). I want to find whether the line created from these connected corrdinates is intersecting a line with specific start and end point.
x1=val(:,2);
y1=val(:,3);
x2=[-226.586 , -238.954];
y2=[112.566 , 49.459];
plot(x1,y1,x2,y2)
P = InterX([x1;y1],[x2;y2]);
plot(x1,y1,x2,y2,P(1,:),P(2,:),'ro'
And the result I get is:
Error using .*
Matrix dimensions must agree.
Error in InterX (line 60)
S1 = dx1.*y1(1:end-1) - dy1.*x1(1:end-1);
while the plot work just fine! Then, I want to a counter to increase by one IF there is an intersection point between these two lines.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 27 Apr 2015
x1=val(:,2);
y1=val(:,3);
x2=[-226.586 , -238.954];
y2=[112.566 , 49.459];
plot(x1,y1,x2,y2)
P = InterX([x1.';y1.'],[x2;y2]);
plot(x1,y1,x2,y2,P(1,:),P(2,:),'ro')

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!