【发布时间】:2014-12-12 00:09:21
【问题描述】:
我有一条由两点 a 和 b 确定的线段。我还有一个由 x0
我的想法是使用这张图片
function(a, b, x0, x1, y0, y1) {
if (a or b is inside square)
return true;
else {
switch (which quadrant is a in) {
case 1: return (ab intersects top of square);
case 2: return (ab intersects left of square);
case 3: return (ab intersects bottom of square);
case 4: return (ab intersects right of square);
}
}
}
我想知道是否有更好的方法来解决这个问题。
【问题讨论】:
-
这是一个绝妙而正确的想法。
-
对不起,如果我误解了,但是为什么正方形内的a或b表示相交?如果 a 和 b 都在正方形内怎么办?
-
@shole 我正在检查与正方形的整个域的交集,而不仅仅是边界。所以里面的 a 和 b 都算作一个交集。
-
那么除了检查正方形内的 a 和 b 是否都返回 true 之外,它还能使用我的答案吗?
标签: javascript algorithm geometry