필터 지우기
필터 지우기

Intersection of line and curve from thier points

조회 수: 18 (최근 30일)
Mohamed Ameen
Mohamed Ameen 2017년 12월 8일
I have a line with 2 points on it and a curve with 4 points on it
For the line we have :
x_line = [7020 0]
y_line = [0 250000]
For the curve we have :
x_curve = [5620 4850 4290 3600]
y_curve = [0 100000 200000 300000]
I need to know the intersection point of the line and the curve
Any help will be appreciated.

채택된 답변

Star Strider
Star Strider 2017년 12월 8일
Try this:
x_line = [7020 0];
y_line = [0 250000];
x_curve = [5620 4850 4290 3600];
y_curve = [0 100000 200000 300000];
b_line = polyfit(x_line, y_line,1); % Fit ‘line’
y_line2 = polyval(b_line, x_curve); % Evaluate ‘line’ At ‘x_curve’
x_int = interp1((y_line2-y_curve), x_curve, 0); % X-Value At Intercept
y_int = polyval(b_line,x_int); % Y-Value At Intercept
figure(1)
plot(x_line, y_line)
hold on
plot(x_curve, y_curve)
plot(x_int, y_int, '+r') % Plot Intercept Point
hold off
  댓글 수: 1
Juan Sebastián Gómez Chitiva
Juan Sebastián Gómez Chitiva 2021년 1월 24일
exactly what i need!!! Thanks!!!!
this is the best answer i've seen

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

추가 답변 (3개)

Mohamed Ameen
Mohamed Ameen 2017년 12월 8일
Thank you very much, it worked... But if you could explain the steps a little more, that will be great.
Thanks again for your help.
  댓글 수: 1
Star Strider
Star Strider 2017년 12월 8일
As always, my pleasure.
First, ‘line’ is a linear function, so creating an equation for it (using polyfit) is straightforward. I cannot compare the y-values for ‘y_line’ and ‘y_curve’ directly, so I evaluate ‘line’ at the ‘x_curve’ points to create y-values at those points as ‘y_line2’. I then subtract ‘y_curve’ from them, and use interp1 to find the x-value (as ‘x_int’) where they are 0. I then use polyval with ‘x_int’ to get the y-value at the interception, ‘y_int’.
The plots are then straightforward.

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


Mohamed Ameen
Mohamed Ameen 2017년 12월 8일
Thanks a lot Mr. Strider, that's really helpful

Jamie Hetherington
Jamie Hetherington 2019년 12월 24일
Starstrider this solution was excellent. I needed a method to identify the point of intersection between a straight line and a plotted curve of residuals. I was thinking it could be done solving simulatenous equations but would've taken more time to create and implement.
Great stuff!

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by