我正在努力寻找一种方法来获得坐标x和坐标Y的最近点,如果它们不存在的话。
public class CheckForIntersection {
double x1, x2, x3, x4, y1, y2, y3, y4, a, b, c, d, e, f, checkLinear, x, y;
CheckForIntersection(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.x3 = x3;
this.y3 = y3;
this.x4 = x4;
this.y4 = y4;
checkintersection();
}
public double getx() {
return x;
}
public double gety() {
return y;
}
public void checkintersection() {
a = y1 - y2;
b = -(x1 - x2);
c = y3 - y4;
d = -(x3 - x4);
e = (y1 - y2) * x1 - (x1 - x2) * y1;
f = (y3 - y4) * x3 - (x3 - x4) * y3;
checkLinear = (a * d) - (b * c);
x = ((e * d) - (b * f)) / checkLinear;
y = ((a * f) - (e * c)) / checkLinear;
System.out.println(a + " " + b + " " + c + " " + d + " " + e + " " + f);
checknearestNeighbour(x, y);
if (checkLinear == 0) {
System.out.println("the intersection is parallel");
} else {
System.out.println("X coordinate:" + x + " X coordinate:" + y);
}
}
}
以下参数的结果应为2.88889,1.1111。