# Re: Python Line Intersection

Discussion in 'Python' started by Emile van Sebille, Apr 9, 2010.

1. ### Emile van SebilleGuest

On 4/9/2010 8:04 AM Peyman Askari said...
> Hello
>
> This is partly Python related, although it might end up being more math related.
>
> I am using PyGTK (GUI builder for Python) and I need to find the intersection point for two lines. It is easy to do, even if you only have the four points describing line segments (http://www.maths.abdn.ac.uk/~igc/tch/eg1006/notes/node23.html). However, it requires that you solve for two equations. How can I do this in Python, either solve equations, or calculating intersection points some other way?

I needed this a couple years back and used parts of pycad without much
difficulty.

Emile

Emile van Sebille, Apr 9, 2010

2. ### Josh EnglishGuest

On Apr 9, 8:36 am, Emile van Sebille <> wrote:
> On 4/9/2010 8:04 AM Peyman Askari said...
>
> > Hello

>
> > This is partly Python related, although it might end up being more math related.

>
> > I am using PyGTK (GUI builder for Python) and I need to find the intersection point for two lines. It is easy to do, even if you only have the four points describing line segments (http://www.maths.abdn.ac.uk/~igc/tch/eg1006/notes/node23.html). However, it requires that you solve for two equations. How can I do this in Python, either solve equations, or calculating intersection points some other way?

>
> I needed this a couple years back and used parts of pycad without much
> difficulty.
>
> Emile

You can also do this by creating a Python representation of a line. I
did it by creating a vector class (using named tuple) and a line class
that stored a point and a direction vector. From there, you can find
the intersection of two lines (or a line with a circle, triangle, etc.
through some mathematical jiggery pokery using dot products.

If anyone want to see it I can post the code when I get home

Josh English, Apr 9, 2010