comparing point coordination with line
5 ビュー (過去 30 日間)
古いコメントを表示
I am trying to find out if a point is below or above a certain line (which I have its slope and y-intecept)
So asuuming I have two lines as in the figure:

and I have a point for example (10, -10), how do I test if it's below the black line (i.e.
), and to the right of purlple line (i.e.
);
), and to the right of purlple line (i.e.
); I am not sure how to compare a point with a line, the way I thought about is the following:
First make a line between the point (10,-10) and the intersection point of the two line (i.e. (8,2)), then check if the line has a slope less than black line slope and greater than purple line slope. This method, however, isn't effective, becuase it can have a slope within that range, but in the area I am targeting.
I would appreciate any guadince or help to solve this :)
0 件のコメント
採用された回答
Star Strider
2019 年 2 月 13 日
One approach:
y1 = @(x) -0.3*x + 4.4;
y2 = @(x) 3*x - 22;
pt = [10, -10];
Difference = [y1(pt(1))-pt(2); y2(pt(1))-pt(2)]
producing:
Difference =
11.4000
18.0000
Since both lines are greater than the y-value of the pointat the x-value of the point, it is below the ‘y1’ line and below the ‘y2’ line.
2 件のコメント
Star Strider
2019 年 2 月 13 日
My pleaure.
First, I get different results:
pt = [-10, -10];
Difference =
17.4000
-42.0000
and:
pt = [20, 10];
Difference =
-11.6000
28.0000
So the first one is less than (below) ‘y1’ and greater than (to the left of) ‘y2’.
And the second one is greater than (above) ‘y1’ and less than (to the right of) ‘y2’.
Perhaps we are interpreting ‘above’, ‘below’, ‘left’ and ‘right’ differently.
‘Also, do you mind explaining to me why we used this approach?’
It seems as good as any to me. Choose whatever works best for you. There is likely no ‘absolute’ convention.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!