intersection of two lines

How can we check that whether the given two non parallel lines will intersect each other or not?? I stored the x and y coordinates of starting and ending point of line1 and line2 in a 2d array, as
1
2
float l1[2][2];
float l2[2][2];


Now how would I check whether there comes a point where l1==l2 (they intersect each other)
non parallel lines


1
2
3
4
bool doNonParellelLinesIntersect(line line1, line line2)
{
   return true;
}


I think I'm missing something, the definition of parallel lines is that they do not intersect, so the definition of non parallel would be that they do intersect.

If you are referring to line segments, do any of the basic algebra methods of solving equations with both an x and a y value, such as linear substituiton, then check if that point actually exists on both lines.

If you are using this for a game, do the much, much easier, more efficent method of hit boxes.
Last edited on
Line intersection can be very useful for games and other applications.

Here's a thread where I go over and explain a method I use to detect line intersections:

http://www.sfml-dev.org/forum/viewtopic.php?p=38393&sid=748c529fed1891dddf817edc91929b59#38393
@ Intrexa: Why would I want to create and track an entire object if I'm "shooting" something in a game that I made? Isn't it much easier to do the calculation then blit an animation to the screen that stops at the relevent point (either at the intersection with the object or just past the drawing point of the screen)? Besides with the simplicity of Hitboxes you end up testing for collisions with EVERY object on the screen regardless of it's location relative the the "ballistics" path.
Topic archived. No new replies allowed.