comparing point coordination with line

1 view (last 30 days)
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:
twolines.PNG
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. );
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 :)

Accepted Answer

Star Strider
Star Strider on 13 Feb 2019
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 Comments
Rawan Alghamdi
Rawan Alghamdi on 13 Feb 2019
Edited: Rawan Alghamdi on 13 Feb 2019
Thank you for your help. I tried the approach and tested it for four cases
(10,-10), (10,10) are both working well, however, when I tested (-10,-10), (20,10) I'm getting the difference to be greater than y2(x) (aka to the right of the line) when it is clearly to the left of the line (above the line), why am i getting such result?
Here I am assuming (below y2 means to the right of the line, and above the line is the left of line).
I believe what I'm asking here is what does above the purple means, and vice versa, because I think my assumption is not correct?
Also, do you mind explaining to me why we used this approach?
Star Strider
Star Strider on 13 Feb 2019
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.

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!