确定一组线是否位于点的一侧而另一组线是否位于点的另一侧
给定两组线 A 和 B,总共 n 条线和一个点 p。如何确定A线是否位于p的一侧而B线是否位于另一侧?
Given two set A and B of lines with n lines in total and a point p. How do u determine if A lines lie in one side of p and B lines lie in the other side?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非所有线都相互平行,否则它们将总是穿过
p
的两侧,因为它们永远持续下去。否则,画一条与穿过p
的其他线平行的线,这条线将划分这两个集合。Unless all of the lines are mutually parallel, they'll always cross both sides of
p
, since they go on forever. Otherwise, draw a line parallel to one of the other lines that passes throughp
, and this line will divide the two sets.假设如下:
1.这不是家庭作业。
2.“交叉 P”意味着,对于给定的 x,y 范围,它们不交叉。如果我们谈论整个轴,那么 A 和 B 中的线必须相对于它们的集合平行,这个问题就变得微不足道了。
然后,简单(尽管很幼稚)的方法 (O(n)) 就是简单地将线的每个 x 值与点的 x 值(对于给定的 p y 值)进行比较。如果对于给定的 y,集合 A(或 B)的所有 x 坐标都位于给定点的左侧,并且对于给定的 x,所有 y 值都不在该点上方,则该集合位于一侧。对另一组运行相同的测试,看看所有线是否都在另一侧。等中提琴。 :)
希望这有帮助。
Assuming the following:
1. This is not homework.
2. "Cross P" means that, for a given x,y range they don't cross. If we're talking about the entire axis, then the lines in A and B must be parallel with respect to their set and this question becomes trivial.
Then the simple (albeit naive) approach (O(n)) is to simply compare each x value of the lines to the x value of the point (for your given y-value of p). If, for the given y, all the x-coordinates of the set A (or B) are to the left of the given point and for the given x all the y values are NOT above this point, then that set is on one side. Run the same test for the other set and if all the lines are on the other side. Et viola. :)
Hope this helps.