This is probably the wrong place to ask but...
How do you know if two lines intersects in 2D if you know the two vectors of the lines? And, in that case, how do you know where they intersect?
How do you know if two lines intersects in 2D if you know the two vectors of the lines? And, in that case, how do you know where they intersect?
You did not google?
http://mathworld.wolfram.com/Line-LineIntersection.html
http://mathworld.wolfram.com/Line-LineIntersection.html
Thanks! Does any of you have this coded down in ASM? I have troubles getting it right. I guess I haven't done vector math for some time.
For a simple concept think of two two dimensional arrays:
array
array1[100][100] - Initialize To Zero
array2[100][100] - Initialize To Zero
let's say line1 is a diagonal, so Array1[0+ecx][0+ecx] ... inc ecx until it's 99.
And line2 is a straight vertical line(Array2[0][0+ecx] ) ... inc ecx until it's 99.
Output in this example is
In this case:
Array1[0][0] = 1 (Not Zero To Signify A Line - Imaginary)
Array1[1][1] = 1
Array1[2][2] = 1
...
Array1[99][99] = 1
and
Array2[0][0] = 1
Array2[0][1] = 1
Array2[0][2] = 1
...
Array2[0][99] = 1
All parts of the arrays are 0 except the ones mentioned above. Notice that only Array1[0][0] == 1 and Array2[0][0] == 1 are both equal -> This is the intersection point.
I hope you can pick up the idea... :)
array
array1[100][100] - Initialize To Zero
array2[100][100] - Initialize To Zero
let's say line1 is a diagonal, so Array1[0+ecx][0+ecx] ... inc ecx until it's 99.
/
/
/ <- Starting Point
And line2 is a straight vertical line(Array2[0][0+ecx] ) ... inc ecx until it's 99.
|
|
|<- Starting Point
Output in this example is
| /
| /
|/
In this case:
Array1[0][0] = 1 (Not Zero To Signify A Line - Imaginary)
Array1[1][1] = 1
Array1[2][2] = 1
...
Array1[99][99] = 1
and
Array2[0][0] = 1
Array2[0][1] = 1
Array2[0][2] = 1
...
Array2[0][99] = 1
All parts of the arrays are 0 except the ones mentioned above. Notice that only Array1[0][0] == 1 and Array2[0][0] == 1 are both equal -> This is the intersection point.
I hope you can pick up the idea... :)
Well that will work but it's not mathematically correct nor it is fast. I have read a little more and I'm now able to understand the formula on the page BitRAKE (or is it BitRACK? :) ) gave me.
Heres one I wrote a while ago, Call it through the Macro passing the x,y coords of the 4 ends of each line segment and it will return 1 if the lines intersect, 0 if they don't.
Posted on 2002-01-30 07:02:47 by Eóin
Posted on 2002-01-30 07:02:47 by Eóin