Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created December 6, 2014 13:26
Show Gist options
  • Save cocodrips/204a9c4245b5b9bc0802 to your computer and use it in GitHub Desktop.
Save cocodrips/204a9c4245b5b9bc0802 to your computer and use it in GitHub Desktop.
線分交差判定 2つの線分が交差しているか
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
class Line:
def __init__(self, start, end):
self.start = start
self.end = end
def is_cross(self, other):
if (((self.start.x - self.end.x) * (other.start.y - self.start.y)
+ (self.start.y - self.end.y) * (self.start.x - other.start.x))
* ((self.start.x - self.end.x) * (other.end.y - self.start.y)
+ (self.start.y - self.end.y) * (self.start.x - other.end.x)) < 0):
if (((other.start.x - other.end.x) * (self.start.y - other.start.y)
+ (other.start.y - other.end.y) * (other.start.x - self.start.x))
* ((other.start.x - other.end.x) * (self.end.y - other.start.y)
+ (other.start.y - other.end.y) * (other.start.x - self.end.x)) < 0):
return True
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment