I hope I am not writing down something that allready had been posted, but here I go:
I am trying to get the intersection point of two lines but as we know lines in mathimatics starts from negative infinity and gos to positive infinty. I found how to get the intersection point of two lines in the great site MathWorld in the page : http://mathworld.wolfram.com/Line-LineIntersection.html
So I wroted a litle program to get this point. And interact a litle bit with the lines.
Here it is.
Evrything its ok but I need to get the point only if there is intersection betwen the two virtual lines as drawn and not as real lines. Or I can say to get the vector vector Intersection.
I am trying to get the intersection point of two lines but as we know lines in mathimatics starts from negative infinity and gos to positive infinty. I found how to get the intersection point of two lines in the great site MathWorld in the page : http://mathworld.wolfram.com/Line-LineIntersection.html
So I wroted a litle program to get this point. And interact a litle bit with the lines.
Here it is.
Strict Framework brl.Math Import BRL.StandardIO Import BRL.Max2d Import BRL.GLMax2D Global x1:Int = 10 Global y1:Int = 10 Global x2:Int = 100 Global y2:Int = 160 Global x3:Int = 10 Global y3:Int = 100 Global x4:Int = 100 Global y4:Int = 60 Local xi = ( (x1 * y2 - x2 * y1) * (x3 - x4) - (x3 * y4 - x4 * y3) * (x1 - x2) ) / ( (x1 - x2) * (y3 - y4) - (x3 - x4) * (y1 - y2) ) Local yi = ( (x1 * y2 - x2 * y1) * (y3 - y4) - (x3*y4 - x4 * y3) * (y1 - y2) ) / ( (x1 - x2) * (y3 - y4) - (x3 - x4) * (y1 - y2) ) SetGraphicsDriver GLMax2DDriver() Graphics 640 , 480 , 0 While Not KeyDown(Key_escape) Cls SetColor 255 , 0 , 0 DrawLine x1 , y1 , x2 , y2 SetColor 0 , 255 , 0 DrawLine x3 , y3 , x4 , y4 SetColor 0 , 0 , 255 DrawLine xi , 0 , xi , 480 DrawLine 0 , yi , 640 , yi keys() xi = ( (x1 * y2 - x2 * y1) * (x3 - x4) - (x3 * y4 - x4 * y3) * (x1 - x2) ) / ( (x1 - x2) * (y3 - y4) - (x3 - x4) * (y1 - y2) ) yi = ( (x1 * y2 - x2 * y1) * (y3 - y4) - (x3*y4 - x4 * y3) * (y1 - y2) ) / ( (x1 - x2) * (y3 - y4) - (x3 - x4) * (y1 - y2) ) Flip FlushMem Wend End Function Keys() If KeyDown(Key_1) x1 = MouseX() y1 = MouseY() End If If KeyDown(Key_2) x2 = MouseX() y2 = MouseY() End If If KeyDown(Key_3) x3 = MouseX() y3 = MouseY() End If If KeyDown(Key_4) x4 = MouseX() y4 = MouseY() End If End Function
Evrything its ok but I need to get the point only if there is intersection betwen the two virtual lines as drawn and not as real lines. Or I can say to get the vector vector Intersection.