| 1 |
function lines_intersect(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) |
| 2 |
{ |
| 3 |
var _x1 = arg0; |
| 4 |
var _y1 = arg1; |
| 5 |
var _x2 = arg2; |
| 6 |
var _y2 = arg3; |
| 7 |
var _x3 = arg4; |
| 8 |
var _y3 = arg5; |
| 9 |
var _x4 = arg6; |
| 10 |
var _y4 = arg7; |
| 11 |
var _dir1 = point_direction(_x1, _y1, _x2, _y2); |
| 12 |
var _dir2 = point_direction(_x1, _y1, _x3, _y3); |
| 13 |
var _dir3 = point_direction(_x1, _y1, _x4, _y4); |
| 14 |
var _dir4 = point_direction(_x3, _y3, _x4, _y4); |
| 15 |
var _dir5 = point_direction(_x3, _y3, _x1, _y1); |
| 16 |
var _dir6 = point_direction(_x3, _y3, _x2, _y2); |
| 17 |
var _diff1 = sign(angle_difference(_dir1, _dir2)); |
| 18 |
var _diff2 = sign(angle_difference(_dir1, _dir3)); |
| 19 |
if (abs(_diff1 + _diff2) > 1) |
| 20 |
return -1; |
| 21 |
_diff1 = sign(angle_difference(_dir4, _dir5)); |
| 22 |
_diff2 = sign(angle_difference(_dir4, _dir6)); |
| 23 |
if (abs(_diff1 + _diff2) > 1) |
| 24 |
return -1; |
| 25 |
var _C = 90; |
| 26 |
var _A = _dir2 - _dir1; |
| 27 |
var _B = 180 - _A - _C; |
| 28 |
var _c = point_distance(_x1, _y1, _x3, _y3); |
| 29 |
_a = (_c / dsin(_C)) * dsin(_A); |
| 30 |
var _b = (_c / dsin(_C)) * dsin(_B); |
| 31 |
var _l = _b; |
| 32 |
_B = _dir4 - _dir1 - 90; |
| 33 |
_A = 180 - _B - _C; |
| 34 |
if (dsin(_A) == 0) |
| 35 |
{ |
| 36 |
var _x = mean(max(min(_x1, _x2), min(_x3, _x4)), min(max(_x1, _x2), max(_x3, _x4))); |
| 37 |
var _y = mean(max(min(_y1, _y2), min(_y3, _y4)), min(max(_y1, _y2), max(_y3, _y4))); |
| 38 |
_l = point_distance(_x1, _y1, _x, _y); |
| 39 |
return _l / point_distance(_x1, _y1, _x2, _y2); |
| 40 |
} |
| 41 |
_b = (_a / dsin(_A)) * dsin(_B); |
| 42 |
_l += _b; |
| 43 |
var _sc = _l / point_distance(_x1, _y1, _x2, _y2); |
| 44 |
return _sc; |
| 45 |
} |