Suppose we have two finite line segments defined each by two points (in two space). I would like to find a way to get the intersection point of those two lines. Eventually, I would like to extend this to work on sets of connected line segments.

I have found a good solution here: Python - matplotlib: find intersection of lineplots. However, this relies on scipy, which I believe requires BLAS, which for separate reasons I would like to avoid.

matplotlib has a module called Path, which has an intersects_path() function (http://matplotlib.org/api/path_api.html#matplotlib.path.Path.intersects_path) which returns true or false for the existence of an intersection, but not the specific location, which I require.

Does anyone know of a clean approach to this?

Any solution I am coming up with is lengthy, and if a solution already exists I would really prefer not to re-invent the wheel.

Thanks!

For the sake of completion, I thought I would post the final solution which I used.

Using Shapely (https://pypi.python.org/pypi/Shapely) the code can look as simple as this:

```
from shapely.geometry import LineString
line1 = LineString([(0,0), (1,0), (1,1)])
line2 = LineString([(0,1), (1,1)])
print(line1.intersection(line2))
```

Returns:

```
POINT (1 1)
```

The nice thing about this is that it will handle single point intersection, and intersection of segments seamlessly, and the same technique can be applied to much more complicated objects.

Similar Questions

I have one line of code which seems commented. Basically the thing I want to find is the revision that changed this line in the code. So, is it possible to see changes in code related to a specific k

I can find plenty formulas for finding the distance between two skew lines. I want to calculate the distance between two line segments in one dimension. It's easy to do with a bunch of IF statements.

Possible Duplicate: How do you detect where two line segments intersect? Determining if two line segments intersect? Given are two lines l1=((A0, B0), (A1, B1)) and l2=((A2, B2), (A3, B3)); Ax, Bx a

I am trying to find the intersection point of a straight(dashed red) with the contour-line highlighted in red(see plot). I used .get_paths in the second plot to isolate said contour line form the othe

I had an interview question along these lines: Given two lists of unordered customers, return a list of the intersection of the two lists. That is, return a list of the customers that appear in both

I'm using the DotSpatial C# library and I'm trying to use the following code to try to find the intersection point between two lines (I know they do intersect) var geoproj = DotSpatial.Projections.Kno

Namely, I am interested in finding files that were modified in both commits (or in two diffs if that is easier). Excuse me if it's simple, but I am still pretty new to git.

I have been looking for ages for a suitable method of finding if two line segments (2 sets of x,y co-ords each) intercept. I have seen many (including: How do you detect where two line segments inters

I'm writing a basic 2D shape library in Python (primarily for manipulating SVG drawings), and I'm at a loss for how to efficiently calculate the intersection points of two ellipses. Each ellipse is de

I'm trying to make intersection of 2 lists (i.e. list C contains those and only those elements, that are in A and B), yet as I understand, I get disjunction of 2 lists + any amount of any elements in

How do you find a JavaScript critical error at a line that does not exist? Visual studio has this error message when I am debugging an aspx file with C# with JavaScript: *JavaScript critical error at

Is there a way to find out the distance of intersection between 2 spheres ? I understand when two spheres intersect the circle of intersection is formed . But what i'm trying to figure ouut is by how

As part of a larger algorithm, I am traversing a set of interconnected line segments. On arriving at any vertex via a line segment, I need to find the leftmost line segment leaving from that point. A

When using the usual formulas to calculate intersection between two 2D segments, ie here, if you round the result to an integer, you get non-symmetric results. That is, sometimes, due to rounding erro

I have to write a program in order to find the same numbers between two arrays. The problem is that I have to do it in the most optimized way respecting some constraints: -Having i,j indexes for the a

How do I calculate the intersection points of two circles. I would expect there to be either two, one or no intersection points in all cases. I have the x and y coordinates of the centre-point, and th

I have a ray, I need to find the closest line segment that it hits. I think it's possible to do this in O(log n) time if I sort the line segments first, but I can't remember how to sort them... I thin

I want some examples of how to take intersection of two finite autometa machines(with diagram). I have learned taking union of two finite autometas. I have searched throughout the internet but hasn't

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? Any help will be highl

I've got a line (x1,y1) and (x2,y2). I'd like to use tan inverse to find the angle of that line, how would I do so in java? I'd like to see what angle the line makes in relation to x1,y1

I have two sets of data (Lists of complex objects or SQL data - LINQ to Entities) where im trying to find the intersection of the two sets of data. Specifically an intersection of the Complex property

I have to find the average of double numbers that the user inputs at the command line, so my program should work with any amount of inputs. I understand that I have to find the sum of all of the numbe

Is there any way to do std::set_intersection on two different types of sets? I have two sets: std::set<X1> l_set1; std::set<X2> l_set2; I'm able to define some comparator for them that ch

Is there a not-too-long way to calculate points of intersection for rectangle and ellipse? I need this for my college project - vector editor with few primitives. I'm using Java, but, as I looked thro

I have a UISegmentedControl with 2 segments. I'm loading JSON data into a table view and each segment has different data. I first load the view and the default first segment shows up - data is there a

For some reason I can't figure this out. But basically I want to compare to models and see if they have any matching emails. Here's my attempt, but this doesn't for some reason work at all. >> C

two iframes should be forced to be shown as cols, can it be done with css? Example code: <!-- if I inc width to 800, the iframes should still be as cols, (regardless of window size) !--> <d

I only find the way to set a property by hadoop dfsadmin -D xx=yy , but how do I find the value of a specific property xx in command line?

In the perl debugger, if you repeatedly list segments of code taking you away from the current line, you can return to the current line by entering the command . (dot). I have not been able to find a

I am using the Raphael Javascript library to construct cubic bezier curves. I need to get a straight segment at the very end of my curve that is a consistent length regardless the length or structure

My algorithm produces a list of (usually) several thousand line segments (all 2D) which I need to join up into large polylines. These resulting polylines might be closed or open, but they are never se

What is the best tool out there to find the VERY last line of code executed in a python program? Thanks!

How do I check whether 2 line segments, L1(p1,p2) and L2(p3,p4), intersect with each other? I do not need the intersection point, I just need to know whether they intersect or not. Since my applicatio

Suppose I have n line segments in general position. How can I quickly count, for each of my n segments, how many of the other n-1 it intersects? I can do this naively in O(n2) time. I can find all int

I want a two-line list view in my activity. This code is displaying one column. Here only the Category column displays, but I also want the Distance_from_Centre at right side. My code is: if (c.moveTo

I have to find intersection elements of 3 integer arrays say a, b, c with a condition; if any of the array is null ( [] ), simply ignore the array and find intersection of the remaining arrays, and if

I need to obtain the intersection of two curves. The problem I'm facing can be stated in the following way: Given two curves C1 and C2, defined by N1 and N2 points connected by straight lines, obtain

i want to compute intersection line, given by 2 planes. my main program gives me, plane parameters a,b,-1,d (my equation is ax+by-z+d=0). so, my function for computing equation of intersection line is

In linux i can get list of opened posix shared memory segments by getting /dev/shm directory listing. How do i programmatically get list of all opened posix shared memory segments in FreeBSD? Assumin

I need to count the number of elements corresponding to the intersection of two big arrays of strings and do it very fast. I am using the following code: arr1[i].Intersect(arr2[j]).Count() For CPU Ti

So, I am wondering whats the difference between these two segments of code - other than just syntax differences? BBDataStore* tempDataStore = [[BBDataStore alloc] initWithDataExpiry:DATA_EXPIRY_TIME];

I'm using JAVA. Ellipse2D s1=new Ellipse2D.Float(0,0,100,100); System.out.println(s1.intersects(99, 30, 100, 100)); Should return false but it return true. How to find intersection between 2 ellipse?

This question already has an answer here: How do you detect where two line segments intersect? 21 answers I have two line segments that are represented by two x,y coordinates, like so: [(x1,y1)

Let's say I have x1, y1 and also x2, y2. How can I find the distance between them? It's a simple math function, but is there a snippet of this online?

I'm new to codeigniter 2, and I have a question about URI segments. What should I do when I have a different number of segments? for example (pseudo code) if(number of segments are 3){ do something }e

I'm trying to find a way to calculate the intersection between a b-spline and a straight line. So far Google hasn't been much help.

A line is here defined as a series of 2D node points. Now, I have two such lines A and B. A=[(0, 0), (1, 1), (2.1, 3), (4,7)] B=[(2, 0), (2, 6)] When one draws them on the paper, one can easily see t

Disclaimer: I am not a GIS guy. We are trying to use the DotSpatial library to calculate a line polygon intersection and then display that intersection in the WPF Bing Maps control. For some reason an

I have 2D line segments extracted from a single image data and would like to match with 3D line segments extracted from other source. for that, first I would like to project a 3D line segment to the i

Let's say I have two binary images of the same size. How do I find the intersection between the two binary images? Only pixels of the same coordinate (location) on the two images that are white (gray