Java
- 2 ответа
- 0 вопросов
0
Вклад в тег
public static boolean isLinesIntercepts(Pair<Float, Float> start1, Pair<Float, Float> end1, Pair<Float, Float> start2, Pair<Float, Float> end2) {
double vector1 = (end2.first - start2.first) * (start1.second - start2.second) - (end2.second - start2.second) * (start1.first - start2.first);
double vector2 = (end2.first - start2.first) * (end1.second - start2.second) - (end2.second - start2.second) * (end1.first - start2.first);
double vector3 = (end1.first - start1.first) * (start2.second - start1.second) - (end1.second - start1.second) * (start2.first - start1.first);
double vector4 = (end1.first - start1.first) * (end2.second - start1.second) - (end1.second - start1.second) * (end2.first - start1.first);
return ((vector1 * vector2 <= 0) && (vector3 * vector4 <= 0));
}