本文介绍了在二维空间中重叠线段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我需要找出两条线是否相互重叠。如果两行平行,我有交叉码返回0。但是后来我需要知道这两条平行线是否重叠。 编辑: ACBD ---------------------------------- ------------- 第1行:AB 第2行:CD 我需要查找第1行是否与第2行重叠,但两行都可以有大于0的斜率。解决方案你可以比较一下,找出是否没有重叠。你将以这种方式比较少,因此非常有效。做以下比较 D B 如果两种情况都是真的,则这些线不重叠。否则必须有重叠。 您将进行最少数量的比较以确定它们是否不重叠。否则会有更多的比较。 I need to find whether two lines overlap each other. I have the intersection code which returns 0, if two lines are parallel. But then I need to know if these two parallel lines overlap.Edit:A C B D-----------------------------------------------Line 1: A-BLine 2: C-DI need to find if Line 1 overlaps Line 2, but both lines can have a slope > 0. 解决方案 You can compare to find if there is no over lap. you will have less comparisons in this way thus very efficient. Do following comparisonsD < AB < CIf either case is true the lines are not overlapping. otherwise there must an overlap.You will make least number of comparisons to determine if they are not overlapping. Otherwise there will be more comparisons to make. 这篇关于在二维空间中重叠线段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-23 17:41