Intersection of line and curve from thier points
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mohamed Ameen
el 8 de Dic. de 2017
Comentada: Juan Sebastián Gómez Chitiva
el 24 de En. de 2021
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.
0 comentarios
Respuesta aceptada
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
1 comentario
Juan Sebastián Gómez Chitiva
el 24 de En. de 2021
exactly what i need!!! Thanks!!!!
this is the best answer i've seen
Más respuestas (3)
Mohamed Ameen
el 8 de Dic. de 2017
1 comentario
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.
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!
0 comentarios
Ver también
Categorías
Más información sobre Logical 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!