How to located a point on top, in between and below two curves.

4 views (last 30 days)
I need help I have two curves ploted which meets at both ends. I want , when a user enters a point, it should tell the user whether the point entered is above the upper curve or on the upper curve or in between the curves or on the lower curve or below the lower curve. Below is my code;
if true
X = 0 : 20 : 100;
y1 = [ 1085 1160 1230 1310 1380 1453 ];
y2 = [ 1085 1198 1280 1350 1405 1453 ];
plot(x, y1,'r'); % plot lower curve
Hold on;
plot(x, y2, 'b'); %plot upper curve
X = input('enter the value of x: ');
Y = input('enter the value of y: ');
plot (X , Y ,'g'); % user ploted points
end
So all i am saying is that; After the user has entered the X and the Y values and it is ploted , there should be some codes to determine whether the point ploted or entered is above the upper curve or on the upper curve or in between the curves or on the lower curve or below the lower curve . I hope am making sense since am not quite matlab friendly. Please help.
  2 Comments
John D'Errico
John D'Errico on 3 Apr 2020
Do you kow how to use interpolation, for example, interp1? If not, then it is time to learn.
Can you interpolate each curve, at the given x value? How would that tell you if the point is above or below each curve? How will that allow you to answer your question?
Paul Kpantey
Paul Kpantey on 3 Apr 2020
Thanks for the comment.
Ihavent used that function before. will try that.
But at the meantime can you help me ith that algorithm?

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 3 Apr 2020
Edited: the cyclist on 3 Apr 2020
You should be able to use the inpolygon function to solve this.
  10 Comments
Image Analyst
Image Analyst on 3 Apr 2020
You were going to look into interp1(), remember? So just reverse y and x and use it. Something like (untested)
x1 = interp1(yBlue, xBlue, yGreen);
x2 = interp1(yRed, xRed, yGreen);
Paul Kpantey
Paul Kpantey on 4 Apr 2020
works perfectly @ Image Analyst
Thanks so so much
i did this according to what you stated up
x1 = interp1(y2, x, Y);
x2 = interp1(y1, x, Y);

Sign in to comment.

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!