Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --https://gamedev.stackexchange.com/questions/26004/how-to-detect-2d-line-on-line-collision
- function line_collision(x1,y1,x2,y2,x3,y3,x4,y4)
- denominator= ((x2 - x1) * (y4 - y3)) - ((y2 - y1) * (x4 - x3));
- numerator1 = ((y1 - y3) * (x4 - x3)) - ((x1 - x3) * (y4 - y3));
- numerator2 = ((y1 - y3) * (x2 - x1)) - ((x1 - x3) * (y2 - y1));
- --// Detect coincident lines
- if (denominator == 0) then
- return (numerator1 == 0 and numerator2 == 0)
- else
- r = numerator1 / denominator;
- s = numerator2 / denominator;
- return ((r >= 0 and r <= 1) and (s >= 0 and s <= 1));
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement