Intersection of line and curve from thier points

9 次查看(过去 30 天)
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

更多回答(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