Skip to content
Advertisement

Numpy and line intersections

How would I use numpy to calculate the intersection between two line segments?

In the code I have segment1 = ((x1,y1),(x2,y2)) and segment2 = ((x1,y1),(x2,y2)). Note segment1 does not equal segment2. So in my code I’ve also been calculating the slope and y-intercept, it would be nice if that could be avoided but I don’t know of a way how.

I’ve been using Cramer’s rule with a function I wrote up in Python but I’d like to find a faster way of doing this.

Advertisement

Answer

Stolen directly from https://web.archive.org/web/20111108065352/https://www.cs.mun.ca/~rod/2500/notes/numpy-arrays/numpy-arrays.html

JavaScript
Advertisement