Created
April 1, 2013 05:32
-
-
Save Karloid/5283383 to your computer and use it in GitHub Desktop.
segmentsIntersect
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
public boolean segmentsIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { | |
double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4); | |
if (d == 0) return false; | |
double xi = Math.floor(((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d); | |
double yi = Math.floor(((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d); | |
if (xi < Math.min(x1, x2) - 15 || xi > Math.max(x1, x2) + 15) return false; | |
if (xi < Math.min(x3, x4) - 15 || xi > Math.max(x3, x4) + 15) return false; | |
if (yi < Math.min(y1, y2) - 15 || yi > Math.max(y1, y2) + 15) return false; | |
if (yi < Math.min(y3, y4) - 15 || yi > Math.max(y3, y4) + 15) return false; | |
/*Косяки с вычислениями в double*/ | |
/* log("[segmentsIntersect] OBSTACLE FIND!"); | |
log("[segmentsIntersect] x1 y1 x2 y2 x3 x4 : " + x1 + " " + y1 + " " + x2 + " " + y2 + " " + x3 + " " + y3 + " " + x4 + " " + y4); | |
log("[segmentsIntersect]xi, yi : " + xi + " " + yi); - точки пересечения | |
*/ | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment