intersection

Find common elements in 2D numpy arrays

瘦欲@ 提交于 2019-12-04 16:52:01
If I have two (or more) 2D arrays, how can I get only common elements between the arrays given a row number. For example, I have arrays in the format: time, position, velocity, acceleration I want to get the two arrays to only have the same time elements, so row 0. I can use np.intersect1d(array1[:, 0], array2[:, 0]) which gives all the common times, but I want to either extract all matching rows/columns from array1/2 or remove non common time elements. In the end array1 and array2 will have the exact same dimensions so I could go: pos_difference = array1[:, 1] - array2[:, 2] The arrays could

Determine if two lines intersect

倖福魔咒の 提交于 2019-12-04 16:50:16
I've seen many postings here on stackoverflow, which are discussing this topic. I took a solution from stackoverflow, but I couldn't find the posting. It was to say: If two lines are intersecting, then the crossproduct produces for the left and the right side two different results. One positive and one negative. Otherwise both have the same sign. So far it is okay. The used formula is, where AB is one line and CD another. dotproductleft = (B.x-A.x) (C.y-B.y)-(B.y-A.y) (C.x-B.x) dotproductright = (B.x-A.x) (D.y-B.y)-(B.y-A.y) (D.x-B.x) If I calculate this for the following given GPS coordinates

CGAL - custom 2D point and intersection behavior in constrained delaunay triangulation

淺唱寂寞╮ 提交于 2019-12-04 14:28:53
In short, I have to generate a constrained delaunay triangulation from a set of 2D points that carry additional information. Since there could be intersecting constraints, I need that the triangulation properly interpolates the satellite data whenever it generates the new point of intersection. I tried with CGAL (C++) to define a custom kernel following the example here , but I've failed to compile it succesfully, basically because there is something fundamental of the underlying generic programming machinery of CGAL that I am missing (lot of type mismatches etc.). Can you point me to a

Efficient all-pairs set intersection on GPU

天大地大妈咪最大 提交于 2019-12-04 13:30:06
I have n sets, subsets of a finite universe. I want to calculate the n*n matrix in which the (I, J) entry contains the cardinality of the intersection of set I and set J . n is in the order of 50000 . My idea is to split the matrix into blocks sufficiently small so to have one thread per entry. Every thread should calculate the intersection using bitwise and . Are there more efficient approaches to solve this problem? I'm going to assume you want to compute it as you described: actually computing the intersection of every pair of sets, using bitwise and of bitsets. With the right mathematical

fast calculation of the intersection area of a triangle and the unit square

天大地大妈咪最大 提交于 2019-12-04 13:25:00
In my current project I need to calculate the intersection area of triangles and the unit squares in an infinite grid. For every triangle (given by three pairs of floating point numbers) I need to know the area (in the interval (0,1] ) it has in common with every square it intersects. Right now I convert both (the triangle and the square) to polygons and use Sutherland-Hodgman polygon clipping to calculate the intersection polygon, which I then use to calculate its area . This approach now shows to be a performance bottleneck in my application. I guess a more specialized (analytical) algorithm

Intersection between two lines in coordinates

孤街醉人 提交于 2019-12-04 12:19:57
问题 I can detect the intersection point of two lines, but if my line don't has the length of my screen, it detects the point, where it shouldn't be. Here a preview: So, it shouldn't detect this intersection because the horizontal line isn't that long. Code: - (NSMutableArray *) intersectWithLines:(CGPoint)startPoint andEnd:(CGPoint)endPoint { NSMutableArray *intersects = [[NSMutableArray alloc] init]; for(GameLine *line in [_lineBackground getLines]) { double lineStartX = line.startPos.x; double

Looking for a non “brute force” algorithm to remove intersecting areas of a collection of Rects

北城以北 提交于 2019-12-04 08:05:21
I have an n-sized collection of Rects, most of which intersect each other. I'd like to remove the intersections and reduce the intersecting Rects into smaller non-intersecting rects. I could easily brute force a solution, but I'm looking for an efficient algorithm. Here's a visualization: Original: Processed: Ideally the method signature would look like this: public static List<RectF> resolveIntersection(List<RectF> rects); the output would be greater or equal to the input, where the output resolves the above visual representation. this is a problem I solved in the past. The first thing it to

Set of efficient 3D intersection algorithms

╄→гoц情女王★ 提交于 2019-12-04 07:40:56
问题 Anyone knows a source, website where I can get some good implementations of 3D intersection algorithms, like intersection of sphere and sphere sphere/ellipsoid sphere/cuboid ellipsoid/ellipsoid ellipsoid/cuboid cuboid/cuboid sphere/ray ellipsoid/ray cuboid/ray triangle/ray quad/ray triangle/triangle quad/quad 回答1: http://www.realtimerendering.com/intersections.html. It's a huge matrix of algorithms that calculate intersections between various types of objects. Excellent resource. 回答2: Not

Getting Union, Intersection, or Difference of Sets in C++

房东的猫 提交于 2019-12-04 05:11:47
I have a couple questions about how to use C++ sets (std::set) Is there a way to get the union, intersection, or difference of two C++ sets? (It's pretty easy to write my own functionto do that but I wanted to know if there was a built in function for it) Can C++ sets be used as keys in a map? Use the set_difference() , set_union() , set_intersection() and set_symmetric_difference() functions. Sets and maps support any key type that can compare. By default this means the type has operator<() defined, but you can provide your own comparator. C++ sets don't have operator<() defined and therefore

a faster way to achieve what intersect() is giving me?

☆樱花仙子☆ 提交于 2019-12-04 05:08:51
I am finding that a lot of time spent in my matlab function is in this code: intersect(freq_bins, our_bins); Both can be rather large vectors, and are comprised of only integers. I just need to know which integers are in both. This is truly the primitive purpose of intersect(), so I suspect that the answer is: it doesn't get any better. But maybe someone has some suggestions. intersect calls ismember . In your case, you don't need all the complicated checks that intersect does, so you can save some overhead and call ismember directly (note: I made sure to call both functions before timing them