Created
February 2, 2014 02:52
-
-
Save b27lu/8762337 to your computer and use it in GitHub Desktop.
This gist shows how to determine if two line segments intersects.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define a class to represent the x and y coordinates of points | |
class Point: | |
def __init__(self,x,y): | |
self.x = x | |
self.y = y | |
#judges if point A,B,C are counter-clockwise | |
def ccw(A,B,C): | |
return (C.y-A.y)*(B.x-A.x) > (B.y-A.y)*(C.x-A.x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#determining if line segments AB and CD intersects | |
def intersect(A,B,C,D): | |
return ccw(A,C,D) != ccw(B,C,D) and ccw(A,B,C) != ccw(A,B,D) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment