Created
August 23, 2020 22:56
-
-
Save musou1500/2376c70028e4b9cee241c73c8de610fa to your computer and use it in GitHub Desktop.
線分の交差判定
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
bool ntersects(double ax, double ay, double bx, double by, double cx, | |
double cy, double dx, double dy) { | |
double ta = (cx - dx) * (ay - cy) + (cy - dy) * (cx - ax); | |
double tb = (cx - dx) * (by - cy) + (cy - dy) * (cx - bx); | |
double tc = (ax - bx) * (cy - ay) + (ay - by) * (ax - cx); | |
double td = (ax - bx) * (dy - ay) + (ay - by) * (ax - dx); | |
return tc * td < 0 && ta * tb < 0; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment