There is some mathematical formula to check collision between two lines?
without using sprites or function collision_line native game maker.
collision between lines
Started by ChaosMaker, Jul 14 2011 01:58 AM
2 replies to this topic
#1
Posted 14 July 2011 - 01:58 AM
#2
Posted 14 July 2011 - 02:19 AM
Non-vertical lines may be expressed in the form
. Where (if the line passes through points <x1, y1> and <x2, y2>)
and 
If line 1 is
and line 2 is
, then because we want a point on both lines (x1 = x2, y1 = y2) we substitute to get:
. Solving, we get
. With x known, we now substitute that value back into one of the line equations to get y.
For vertical lines, substitute the x of the vertical line into the other line's equation.
Another more general way to do it is (without error-checking):
If line 1 is
For vertical lines, substitute the x of the vertical line into the other line's equation.
Another more general way to do it is (without error-checking):
// line_intersect (line1x1, line1y1, line1x2, line1y2, line2x1, line2y1, line2x2, line2y2); argument2 -= argument0; argument3 -= argument1; argument6 -= argument4; argument7 -= argument5; var t; t = (argument2 * (argument5 - argument1) + argument3 * (argument0 - argument4)) / (argument6 * argument3 - argument2 * argument7); global.x = argument6 * t + argument4; global.y = argument7 * t + argument5;
#3
Posted 14 July 2011 - 02:30 AM
Thank you very much, works fine.
*.*
*.*
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











