intersection

Line intersection with AABB Rectangle?

假如想象 提交于 2019-11-26 07:29:36
问题 Preferably without using any kind of loop, as this\'ll be used in a game. I wish to intersect a line with a rectangle, of arbitrary size. But I also wish for the intersection point[s] to be returned. It\'s possible, I\'ve done a little googling, but still have not worked it out. The line is defined using (x1,y1,x2,y2). The rectangle has these two points too. 回答1: I would recommend simply doing a line-segment-line-segment intersection check on each line segment (edge) that makes up the

How to find the intersection point between a line and a rectangle?

无人久伴 提交于 2019-11-26 04:33:28
I have a line that goes from points A to B; I have (x,y) of both points. I also have a rectangle that's centered at B and the width and height of the rectangle. I need to find the point in the line that intersects the rectangle. Is there a formula that gives me the (x,y) of that point? The point A is always outside of the rectangle and the point B is always at the center of the rectangle Assuming the rectangle is axis-aligned, this makes things pretty simple: The slope of the line is s = (Ay - By)/(Ax - Bx). If -h/2 <= s * w/2 <= h/2 then the line intersects: The right edge if Ax > Bx The left

Python -Intersection of multiple lists?

为君一笑 提交于 2019-11-26 04:30:47
I am playing with python and am able to get the intersection of two lists: result = set(a).intersection(b) Now if d is a list containing a and b and a third element c , is there an built-in function for finding the intersection of all the three lists inside d ? So for instance, d = [[1,2,3,4], [2,3,4], [3,4,5,6,7]] then the result should be [3,4] for 2.4, you can just define an intersection function. def intersect(*d): sets = iter(map(set, d)) result = sets.next() for s in sets: result = result.intersection(s) return result for newer versions of python: the intersection method takes an

Test if lists share any items in python

这一生的挚爱 提交于 2019-11-26 03:48:05
问题 I want to check if any of the items in one list are present in another list. I can do it simply with the code below, but I suspect there might be a library function to do this. If not, is there a more pythonic method of achieving the same result. In [78]: a = [1, 2, 3, 4, 5] In [79]: b = [8, 7, 6] In [80]: c = [8, 7, 6, 5] In [81]: def lists_overlap(a, b): ....: for i in a: ....: if i in b: ....: return True ....: return False ....: In [82]: lists_overlap(a, b) Out[82]: False In [83]: lists

How to find the intersection point between a line and a rectangle?

独自空忆成欢 提交于 2019-11-26 03:25:27
问题 I have a line that goes from points A to B; I have (x,y) of both points. I also have a rectangle that\'s centered at B and the width and height of the rectangle. I need to find the point in the line that intersects the rectangle. Is there a formula that gives me the (x,y) of that point? 回答1: The point A is always outside of the rectangle and the point B is always at the center of the rectangle Assuming the rectangle is axis-aligned, this makes things pretty simple: The slope of the line is s

Python -Intersection of multiple lists?

[亡魂溺海] 提交于 2019-11-26 01:53:51
问题 I am playing with python and am able to get the intersection of two lists: result = set(a).intersection(b) Now if d is a list containing a and b and a third element c , is there an built-in function for finding the intersection of all the three lists inside d ? So for instance, d = [[1,2,3,4], [2,3,4], [3,4,5,6,7]] then the result should be [3,4] 回答1: for 2.4, you can just define an intersection function. def intersect(*d): sets = iter(map(set, d)) result = sets.next() for s in sets: result =

Python -Intersection of multiple lists?

余生颓废 提交于 2019-11-26 01:17:08
问题 I am playing with python and am able to get the intersection of two lists: result = set(a).intersection(b) Now if d is a list containing a and b and a third element c , is there an built-in function for finding the intersection of all the three lists inside d ? So for instance, d = [[1,2,3,4], [2,3,4], [3,4,5,6,7]] then the result should be [3,4] 回答1: for 2.4, you can just define an intersection function. def intersect(*d): sets = iter(map(set, d)) result = sets.next() for s in sets: result =

How to find list intersection?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 00:15:44
问题 a = [1,2,3,4,5] b = [1,3,5,6] c = a and b print c actual output: [1,3,5,6] expected output: [1,3,5] How can we achieve a boolean AND operation (list intersection) on two lists? 回答1: If order is not important and you don't need to worry about duplicates then you can use set intersection: >>> a = [1,2,3,4,5] >>> b = [1,3,5,6] >>> list(set(a) & set(b)) [1, 3, 5] 回答2: If you convert the larger of the two lists into a set, you can get the intersection of that set with any iterable using

Intersection and union of ArrayLists in Java

一个人想着一个人 提交于 2019-11-25 23:16:30
问题 Are there any methods to do so? I was looking but couldn\'t find any. Another question: I need these methods so I can filter files. Some are AND filters and some are OR filters (like in set theory), so I need to filter according to all files and the unite/intersects ArrayLists that holds those files. Should I use a different data structure to hold the files? Is there anything else that would offer a better runtime? 回答1: Here's a plain implementation without using any third-party library. Main

Find intersection of two nested lists?

别来无恙 提交于 2019-11-25 22:37:12
问题 I know how to get an intersection of two flat lists: b1 = [1,2,3,4,5,9,11,15] b2 = [4,5,6,7,8] b3 = [val for val in b1 if val in b2] or def intersect(a, b): return list(set(a) & set(b)) print intersect(b1, b2) But when I have to find intersection for nested lists then my problems starts: c1 = [1, 6, 7, 10, 13, 28, 32, 41, 58, 63] c2 = [[13, 17, 18, 21, 32], [7, 11, 13, 14, 28], [1, 5, 6, 8, 15, 16]] In the end I would like to receive: c3 = [[13,32],[7,13,28],[1,6]] Can you guys give me a hand