Itโs not difficult to determine the equations of these perpendicular dashed lines passing through the endpoints of your bold line.
Let the bold line be defined by points (x 1 , y 1 ) and (x 2 , y 2 ) . Then it has a slope
m = (y 2 - y 1 ) / (x 2 - x 1 )
Thus, all perpendicular lines will have the form
y (x) = ( -1 / m ) x + c
We can use this to determine the equations of perpendicular lines passing through (x 1 , y 1 ) and (x 2 , y 2 ) (respectively), which essentially represent the boundary of the area in which all real points should be:
y a (x) = (-1 / m) x + y 1 + x 1 / m
y b (x) = (-1 / m) x + y 2 + x 2 / m
So, for an arbitrary point (x*, y*) , to determine if it is in a valid area, you can check
y a (x *) <= y * <= y b (x *)
(or vice versa if y a (x*) greater)
The following should do the trick:
public static boolean check(double x1, double y1, double x2, double y2, double x, double y) { if (x1 == x2) {
arshajii
source share