Skip to content

Instantly share code, notes, and snippets.

@musou1500
Created August 23, 2020 22:56
Show Gist options
  • Save musou1500/2376c70028e4b9cee241c73c8de610fa to your computer and use it in GitHub Desktop.
Save musou1500/2376c70028e4b9cee241c73c8de610fa to your computer and use it in GitHub Desktop.
線分の交差判定
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