View Single Post
  #2 (permalink)  
Old 06-10-2007, 05:37 PM
poorcocoboiboi
Posts: n/a
You would do it just like you would algebraically.

First, look at the two slopes provided. If they're different, we're fine. (If they're the same, then there is no unique solution.)

To find the intersection, we need to find the point where
(m1)x+b1 = (m2)x+b2
so
(m1-m2)x = b2-b1
x = (b2-b1) / (m1-m2)

Plugging the found x value into either equation will yield the y coordinate of the intersection point.

Here's Python code (Indents indicated by __):
class NoUniqueSolutionError: pass


class Intersection:
__ def __init__(self, m1, b1, m2, b2):
____ if m1 == m2:
______ raise NoUniqueSolutionError()
____ self.inputs = [m1,b1,m2,b2]
____ self.x = x = (b2-b1)/(1.0*m1-m2)
____ self.y = m1*x+b1

i=Intersection(1,0,-1,5)
print i.x, i.y

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!