Created
December 6, 2014 13:26
-
-
Save cocodrips/204a9c4245b5b9bc0802 to your computer and use it in GitHub Desktop.
線分交差判定 2つの線分が交差しているか
This file contains hidden or 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
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