# Polygons Intersection Points

Question asked by ahsan_phy@hotmail.com on Dec 23, 2014
Latest reply on Dec 24, 2014 by ahsan_phy@hotmail.com

I want to calculate the intersection point of two polygon, the polygons are illustrate in picture. The picture clearly show that there are two points

of intersections.

I have write some code, but there is problem init, it's calculate more than two intersection point. Blow is my code...

def linesIntersection(A, B, C, D):

x1 = A

y1 = A

x2 = B

y2 = B

x3 = C

y3 = C

x4 = D

y4 = D

#print x1, y1, x2, y2

#print x3, y3, x4, y4

denomenator = (((x1-x2)*(y3-y4)) - ((y1-y2)*(x3-x4)))

#print denomenator

if denomenator == 0:

return denomenator

else:

P1 = (((x1*y2 - y1*x2)*(x3-x4)) - ((x1-x2)*(x3*y4-y3*x4)))

Px = P1 / denomenator

P2 = (((x1*y2 - y1*x2)*(y3-y4)) - ((y1-y2)*(x3*y4-y3*x4)))

Py = P2 / denomenator

print "The Intersection points are: ", Px, Py

polygon1 = [(1,0),(3,0),(3,2),(1,2),(1,0)]

polygon2 = [(0,1),(2,1),(2,3),(0,3),(0,1)]

poly1 = len(polygon1)

poly2 = len(polygon1)

#print poly1,poly2

for i in range(poly1-1):

A = polygon1[i]

B = polygon1[i+1]

for j in range(poly2-1):

C = polygon2[j]

D = polygon2[j+1]

linesIntersection(A, B, C, D)

I am using determinant for calculating the intersection of point. http://en.wikipedia.org/wiki/Line%E2%80%93line_intersection

There is a condition both lines should be similar planes, this is where problem begin, i don't know how to do it ? Pleas help me... 