Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a point between two points?

Tags:

java

math

After Googling and looking on Stack for a long time, I've only managed to find methods for determining whether or not a point falls on the line that connects two points. This, unfortunately, isn't what I need.

Please see the image at the end of this question. I apologize in advance for the terrible picture, but it gets the point (get it?) across.

I need to create two perpendicular lines to the one that joins the points x and y. They need to intersect with the perpendicular line at points x and y. I then need to then tell if point z appears between those two lines or not.

Any help is appreciated. Thanks for your time!

Point graph.

like image 557
Stev Avatar asked Sep 12 '26 23:09

Stev


2 Answers

Compute the angle xyz and yxz. If either is > 90 then it is outside.

like image 71
mike.k Avatar answered Sep 15 '26 12:09

mike.k


Since you tagged your question with java, here you go:

import javafx.geometry.Point2D;
....
// is z between parallel lines 
boolean betweenLines(Point2D x, Point2D y, Point2D z) { 
    return  x.angle(y,z) < 90 && y.angle(x,z) < 90;
}
like image 21
Misha Avatar answered Sep 15 '26 12:09

Misha