Find if a point lies bellow or above a curve
    9 ビュー (過去 30 日間)
  
       古いコメントを表示
    
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:
- I don't know how to make the line go through the curve
- 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!
Lina
1 件のコメント
  Jonathan
      
 2015 年 6 月 4 日
				
      編集済み: Jonathan
      
 2015 年 6 月 4 日
  
			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).
採用された回答
  Salaheddin Hosseinzadeh
      
 2015 年 6 月 4 日
        
      編集済み: Salaheddin Hosseinzadeh
      
 2015 年 6 月 4 日
  
      Hi TY
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);
            end
            assignin('base','X',newX)
            assignin('base','Y',newY)
        end
        figure
        plot(newX,newY,'*')
        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 件のコメント
  Vithal Bable
 2018 年 8 月 14 日
				this is wrong code as you not provided small letter variable'x' value....
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Interpolation についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



