AlmastB Line2D javafx.geometry.Point2D.
public class Line2D {
double x1;
double y1;
double x2;
double y2;
public Line2D(double x1, double y1, double x2, double y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public Line2D(Point2D point1, Point2D point2) {
this(point1.getX(), point1.getY(), point2.getX(), point2.getY());
}
public double length()
{
return new Point2D(x1, y1).distance(x2, y2);
}
public double distance(double x, double y) {
double d1 = x * (y2 - y1) - y * (x2 - x1) + x2 * y1 - y2 * x1;
return Math.abs(d1) / length();
}
public double distance(Point2D toPoint) {
return distance(toPoint.getX(), toPoint.getY());
}
}
, , distance. intersects , double. . : , , , . , .
distance . , 2 , (.. ).
intersects :
public boolean intersects(Point2D toPoint, double precision, boolean checkBounds) {
if (checkBounds &&
((toPoint.getX() < Math.min(x1, x2) - precision) ||
(toPoint.getX() > Math.max(x1, x2) + precision) ||
(toPoint.getY() < Math.min(y1, y2) - precision) ||
(toPoint.getY() > Math.max(y1, y2) + precision))) return false;
return distance(toPoint.getX(), toPoint.getY()) < precision;
}
2 (.. ).