comparing point coordination with line
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Rawan Alghamdi
el 13 de Feb. de 2019
Comentada: Star Strider
el 13 de Feb. de 2019
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 comentarios
Respuesta aceptada
Star Strider
el 13 de Feb. de 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 comentarios
Star Strider
el 13 de Feb. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!