Borrar filtros
Borrar filtros

Intersection of line and curve from thier points

19 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Star Strider
Star Strider el 8 de Dic. de 2017
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

Más respuestas (3)

Mohamed Ameen
Mohamed Ameen el 8 de Dic. de 2017
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 comentario
Star Strider
Star Strider el 8 de Dic. de 2017
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.

Iniciar sesión para comentar.


Mohamed Ameen
Mohamed Ameen el 8 de Dic. de 2017
Thanks a lot Mr. Strider, that's really helpful

Jamie Hetherington
Jamie Hetherington el 24 de Dic. de 2019
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!

Categorías

Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by