Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def intersect2(a,b,c,d):
- # standard form line eq Line_AB
- a1 = b[1]-a[1]
- b1 = a[0]-b[0]
- c1 = a1*a[0] + b1*a[1]
- # standard form line eq Line_CD
- a2 = d[1]-c[1]
- b2 = c[0]-d[0]
- c2 = a2*c[0] + b2*c[1]
- determinant = a1*b2 - a2*b1
- if (determinant == 0):
- return math.inf, math,inf
- else:
- x = (b2*c1 - b1*c2)/determinant
- y = (a1*c2 - a2*c1)/determinant
- return x,y
- def main():
- #line1 = Line(4,29,27,2)
- #line2 = Line(5,5,51,22)
- line1 = Line(14,21,37,20)
- line2 = Line(15,10,53,23)
- vert1 = line1.get_vert(0)
- vert2 = line1.get_vert(1)
- vert3 = line2.get_vert(0)
- vert4 = line2.get_vert(1)
- x,y = intersect2( vert1, vert2,
- vert3, vert4)
- print("Intersection of 2 lines at: %.03f, %.03f" % (x,y))
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement