我画了一条线,然后画了一个点,然后我想检查该点是否在线上。我在数组中获取了一条线坐标(因为有多条线)。我想检查最后一行的当前点吗?
if (positionX1 == positionX2 && positionY1 == positionY2) {
float m = line.getSlope(
drawLines[currentLines - 1][2], drawLines[currentLines - 1][3],
drawLines[currentLines - 1][0], drawLines[currentLines - 1][1]);
m = Float.parseFloat(df.format(m));
float c = line.getIntercept(
drawLines[currentLines - 1][2], drawLines[currentLines - 1][3],
drawLines[currentLines - 1][0], drawLines[currentLines - 1][1]);
c = Math.round(c);
m1 = line.getSlope(positionX2, positionY2,
drawLines[currentLines - 1][0], drawLines[currentLines - 1][1]);
m1 = Float.parseFloat(df.format(m1));
System.out.println(m + " " + m1);
c1 = line.getIntercept(positionX2, positionY2,
drawLines[currentLines - 1][0], drawLines[currentLines - 1][1]);
c1 = Math.round(c1);
if (m == m1 && ((c == c1) || (c == c1 - 1) || (c == c1 + 1))) {
System.out.println("Point is on Line");
}
}
问题是当一个点靠近直线的起点或当一条直线大约垂直时 m1 和 c1 的值变化很大。所以,检测一个点是否在线上存在一个问题。我该如何检查这种情况?
Line2D.ptSegDist(x1, y1, x2, y2, xP, yP)如果点 (xP, yP) 位于从 (x1, y1) 到 (x2, y2) 的线段上,则返回 0.0。Line2D.ptLineDist
对无限线做同样的事情。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)