intersection

How to calculate the 3D line segment of two rectangles?

I am looking for a fast way to calculate the line segment of two given rectangles in 3D. For instance, each 3D rectangle is defined by its four vertices. A solution in any reasonable programming language will do. ...

How can you easily test hash equality in Ruby when you only care about intersecting keys?

Say I have the following hashes: hash_x = { :a => 1, :b => 2 } hash_y = { :b => 2, :c => 3 } I need a chunk of logic that compares the two for equality only taking into consideration intersecting keys. In this example the 'b' key is the only commonality between the two hashes and it's value is set to '2' in both so by that ...

C#: Range intersection when endpoints are null (infinity)

Ok, I have these intersection methods to work with ranges, and they work well as long as the range endpoints are not null: public static bool Intersects<T>(this Range<T> first, Range<T> second, IComparer<T> comparer) { return comparer.Compare(first.Start, second.End) <= 0 && comparer.Compare(first.End, second.Start) >= 0; }...

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

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? ...

Connecting two WPF canvas elements by a line, without using anchors?

I have a canvas for diagramming, and want to join nodes in the diagram by directed lines (arrow ends). I tried the anchor approach, where lines only attach at specific points on the nodes but that did not work for me, it looked like crap. I simply want a line from the centre of each object to the other, and stop the line at the nodes' e...

Somewhat simple PHP array intersection question

Maybe I'm going insane, but I could have sworn that there was an PHP core function which took two arrays as arguments: $a = array('1', '3'); $b = array('1'=>'apples', '2'=>'oranges', '3'=>'kiwis'); And performs an intersection where the values from array $a are checked for collisions with the keys in array $b. Returning something like...

Python: Fast extraction of intersections among all possible 2-combinations in a large number of lists

I have a dataset of ca. 9K lists of variable length (1 to 100K elements). I need to calculate the length of the intersection of all possible 2-list combinations in this dataset. Note that elements in each list are unique so they can be stored as sets in python. What is the most efficient way to perform this in python? Edit I forgot to ...

How can I turn a ray-plane intersection point into barycentric coordinates?

Hi, My problem: How can I take two 3D points and lock them to a single axis? For instance, so that both their z-axes are 0. What I'm trying to do: I have a set of 3D coordinates in a scene, representing a a box with a pyramid on it. I also have a camera, represented by another 3D coordinate. I subtract the camera coordinate from the ...

Generate new polygons from a cut polygon (2D)

Hi, I'm stuck with this little problem and my algorithm to solve this doesn't hold for all cases. Does anybody has an idea how to solve this? Here's an example polygon: Formal description We have a list of points in CW order defining the polygon. We also can query whether a point is a cutting point with is_cut(p), where p is a giv...

Simultaneous connections, excel

Hi everyone, I have a list of session start and stop times, in format like so: 23/11/09 15:18:32, 23/11/09 15:18:40 23/11/09 15:20:02, 23/11/09 15:20:32 23/11/09 15:20:10, 23/11/09 15:20:40 This is in excel at the moment, start datetime in one column end datetime in the other. Basically what I want to do is some post processing on t...

Intersection Of A Surface An Plane

I'm trying to find out when a quadratic selection algorithm is faster than a linear selection algorithm. Running some experiments I generated two 3D plots that show the algorithm run times as a function of the input array size and the desired order statistic. Using gnuplot to draw the plot I confirmed that there are cases when the quadra...

Calculating point of intersection based on angle and speed

I have a vector consisting of a point, speed and direction. We will call this vector R. And another vector that only consists of a point and a speed. No direction. We will call this one T. Now, what I am trying to do is to find the shortest intersection point of these two vectors. Since T has no direction, this is proving to be difficult...

Checking for intersection points between two rectangles?

If I have two rectangles whose positions are deifned using two 2D vectors (i.e. top left, bottom right) how can I check for the points they are intersecting? ...

Collision Handling Between Circle and Line Segments

Hello, I'm implementing a small game and am having trouble getting the physics working properly. In this game, there is one ball (a circle which moves from frame to frame, and may change radius) and several walls (line segments which also change and move from frame to frame). I can detect collisions properly, and making the ball bounce ...

SELECT from two same table with intersect

The query: SELECT id_user FROM Rating Where id_movie=2 INTERSECT SELECT id_user FROM Rating Where id_movie=3 but I get: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTERSECT SELECT id_user FROM Rating Where id_movie=3 LIMI...

Ruby Array Intersection, Hash.has_value? for intersection with array[i+1] based on hash values

I am trying to populate an array with an intersection of an array and hash based on hash values: array2 = ["hi","world","One"] Vals = {:one => "One", :two => "Two"} array2 = VALS.values & array2 print array2 Works fine for intersection of hash values and array2[ i ], but if I want to instead populate with array2[ i+1 ] element from ar...

How do I do an Intersection of many<-->many DataMapper Collection?

I am trying to return an intersection of datamapper collections relating to tagged topics. Before we go any further I should point out the obvious: @tags = Tag.all(:title => ["shim", "sham"]) @tags.topics This returns a UNION which means I get all topics with either 'shim' or 'sham' as a tag. What I want to do is return all articles...

Comparing Python nested lists

I have two nested lists, each nested list containing two strings e.g.: list 1 [('EFG', '[3,4,5]'), ('DEF', '[2,3,4]')] and list 2 [('DEF', '[2,3,4]'), ('FGH', '[4,5,6]')] I would like to compare the two lists and recover those nested lists which are identical with each other. In this case only ('DEF','[2,3,4]') would be returned. Th...

Determining whether a coordinate exists inside of a polygon

Hi all, I'm working on an open source tracking and geofence software application and am having a bit of difficulty figuring out the math for the geofencing. I need to determine whether or not a coordinate exists inside of a polygon. However, the tricky part is that the polygon has no set number of sides. I need to be able to calculate ...

How do I efficiently do the intersection of joins in SQL?

I have three tables, books, tags, and taggings (books-xref-tags): books id | title | author 1 | Blink | Malcolm Gladwell 2 | 1984 | George Orwell taggings book_id | tag_id 1 | 1 1 | 2 2 | 1 2 | 3 tags id | name 1 | interesting 2 | nonfiction 3 | fiction I'd like to ...