So I have a problem. I write a programm to figure out how many triangles are in a given set of lines and I want to calculate that with the line intersections.
I have a problem with line intersections. My problems are to figure out if the intersection is in the line segments. Here is my code:
def Schnittkorrekt (xs,ys,x1,x2,y1,y2):
global y
global x
global z
global w
global c
global x3
global y3
global z2
global w2
global x21
global x22
global y21
global y22
print (Schnittpunkt(x1,x2,y1,y2,x21,x22,y21,y22))
if (x1 <= xs) and (y1 <= ys) and (xs <= x2) and (ys <= y2):
return ('cool')
elif (x1 <= xs) and (y2 <= ys) and (xs <= x2) and (ys <= y1):
return ('cool')
elif (x2 <= xs) and (y1 <= ys) and (xs <= x1) and (ys <= y2):
return ('cool')
elif (x2 <= xs) and (y2 <= ys) and (xs <= x1) and (ys <= y1):
return ('cool')
else:
return ('uncool')
x1,x2,y1,y2 are the are the beginning/ endpoints of the first line segment
x21,x22,y21,y22 are the are the beginning/ endpoints of the second line segment
xs,ys are the coordinates of the intersection
it always gives out 'uncool' shouldn't be right
For testing purposes i chose
x1=4
x2=5
y1=4
y2=6
x21 = 8
x22 = 1
y21 = 1
y22 = 8
with these coordinates xs and ys are 4,33 and 4,66
thanks in advance