Clear Filters
Clear Filters

Find if a point lies bellow or above a curve

51 views (last 30 days)
Is it possible to find if a point lies under a curve C if the curve is not defined by an equation but by points? Say we have point Po(Xo,Yo) and I want to find if this Po is located below, under or on the curve.
Any ideas of how to do that?
I can only think of the following method:
  • Drawing a line 'l' connecting (0,0),Po, the curve
  • Finding the coordinates of the point P1 at which 'l' crosses the curve.
  • Measuring the distance from (0,0) to Po = d1 and comparing it with the distance from (0,0) to P1 =d2
  • If the d1>d2, Po is above, else, it is below
The problems:
  1. I don't know how to make the line go through the curve
  2. I don't know how to find the coordinates of the point at which the line crosses the curve
I know this might be a simple question for most of you but mathematically I can only think of formulas related to polygons, circles, triangles...etc. not for assymptotic curve.
Thank you!
  1 Comment
Jonathan on 4 Jun 2015
Edited: Jonathan on 4 Jun 2015
If your curve C is convex (or concave), then you can find this easily by solving a linear system to find the linear combination of curve-points that give your query-point (regularised in the least-squared sense). Otherwise, if your curve doesn't have too many points, you can simply check whether your query-point is under/over each line-segment that makes up your curve (consecutive pairs of curve-points).

Sign in to comment.

Accepted Answer

Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh on 4 Jun 2015
Edited: Salaheddin Hosseinzadeh on 4 Jun 2015
Yes, you can easily do this. I actually done it before, I had series of points and I draw a line with mouse (2 points) turned those 2 points into line and I guess I removed all the points under that line. The code I wrote is as follows.y and x are the position of the points, Y and X are the position acquired by mouse (threshold line data) which is equated as m*(x(i)-X(1))+Y(1))
%%Added on May 18 2015 to cut a certain point
[X,Y] = ginput(2); % taking 2 points by mouse
m = (Y(2) - Y(1)) ./ (X(2)-X(1)) % defining the line slope
C = 0
newX = 0;
newY = 0;
xSize = numel(x)
for i =1: numel(x)
if (y(i)> (m*(x(i)-X(1))+Y(1))) % checking if its above the defined line
C = C+1;
newX(C) = x(i);
newY(C) = y(i);
axis equal
Here is a picture of the result
What you want is no different than this, I had to create the points for the lines which I draw by means of 2 points, but you have your threshold line points apparently. One step closer to what you want!
Good luck!
  1 Comment
Vithal Bable
Vithal Bable on 14 Aug 2018
this is wrong code as you not provided small letter variable'x' value....

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!