I am trying to find the intersect point of two lines using "InterX".
More concretely, I want to find the intersect point of the line L1 which two coordinates are x1=1,y1=1 and x2=3 y2=6
and the line L2 which two coordinates are x1=-2 y1=8 and x2=2 y2=-1
I don´t know if I understanded well the "InterX" function, but here is the code I have executed:
hold on
x=linspace(-30,30)
L1=[1 3;
1 6]
L2=[-2 2;
8 -1]
P=InterX(L1,L2);
plot(L1)
plot(L2)
plot(P,'ro')
And the result Matlab gives to me is completly absurd, in the following image:
What am I doing wrong? How can I properly use the "InterX" function? I have searched in the community but I didn´t understand it very well as you can see

 채택된 답변

KSSV
KSSV 2020년 10월 21일
편집: KSSV 2020년 10월 21일

1 개 추천

You should read the documentation/ help given in the InterX function. Your curves/ data points should be such that :
L1 = [x11 x12 ; y11 y12] ;
L2 = [x21 x22 ; y21 y22] ;
L1=[1 3;
1 6]
L2=[-2 2;
8 -1]
P=InterX(L1,L2);
figure
hold on
plot(L1(1,:),L1(2,:),'r')
plot(L2(1,:),L2(2,:),'b')
plot(P(1),P(2),'ro')

댓글 수: 3

And how it would be if I would like to know all intersect points between two elements?. For instance, let's say I would like to know the two intersec points between a line and a circle as shown below.
I don`t know why matlab only shows me one point of intersec. I have read the "help" text of "InterX" function but I think I didn´t get it. Here is the code I have introduced:
How can I find both points of intersec?
axis equal
hold on
caca=2*pi();
ang=linspace(0,caca);
xp=5*cos(ang);
yp=5*sin(ang);
circ=[xp;yp];
plot(xp,yp,'r');
L1=[-7 7; 2 2];
plot(L1(1,:),L1(2,:),'b')
P=InterX(circ,L1);
plot(P(1),P(2),'go');
KSSV
KSSV 2020년 10월 23일
편집: KSSV 2020년 10월 23일
You are getting two points. You are plotting it wrong.
plot(P(1,:),P(2,:),'go');
thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

제품

릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by