Python Line Intersection

Mark Tolonen metolone+gmane at gmail.com
Sat Apr 10 02:24:08 EDT 2010


"Chris Rebert" <clp2 at rebertia.com> wrote in message 
news:y2o50697b2c1004091304u627d99bfj44ad56fa76a3cc15 at mail.gmail.com...
> On Fri, Apr 9, 2010 at 11:43 AM, John Nagle <nagle at animats.com> wrote:
>> Chris Rebert wrote:
>>> On Fri, Apr 9, 2010 at 8:04 AM, Peyman Askari 
>>> <peter_peyman_puk at yahoo.ca>
>>> wrote:
>>>>
>>>> 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?
>>>
>>> Just solve the equations ahead of time by using generic ones.
> <snip>
>>> x = (c - b) / (m-n)
>>
>> Actually, you don't want to do it that way, because it fails for vertical
>> lines, when m and n go to infinity.
>
> As the programmer said upon seeing a stripe-less zebra:
> "Oh no, a special case!"
>
> Excellent catch my good sir; although I will point out that strictly
> speaking, you can't put vertical lines into slope-intercept form (but
> I should not have forgotten that precondition).

And parallel lines, where m and n are equal (divide-by-zero)...

-Mark





More information about the Python-list mailing list