Line Collisions
I''m looking for an algorithm to check for a collision between 2 lines (each line is defined by a set of X,Y cordinates). I''ve already tried one that just checks for a point of intersection but I''m having problems with paralelle lines, slope=0 and other special cases. Is there an easier way? I''m programming it in Object Pascal but if you can show me an example in C it would be just as good.
**Newbie Alert** (that''s me)
Good Question.
I would like to hear an answer also. I''m working on my first "Test Engine". Real simple stuff. My map only has one floor level (Y=-1) and all I do for collision detection is something like Bounding-Sphere-Overlaps-Line = Collide. Right now I can only detect collisions with vertical and horizontal lines. I would like to add some more sophisticated collision detection but there seems to be little documentation on the net or in books.
In my LevelWall type I have 4 floats that define the end points of a line. Since my level only has one floor height (and my character can''t jump) I only need to check for collisions in two dimensions.
In my collision detection algorithm I would like to define a sencond line made from two more points.
The first point defined by the players new x,z.
The second point would be made from the players rotation (rad) and his bounding sphere radius.
Then I would like to check to see if the lines intersect.
A detailed answer with some source (simple for my newbie brain) or a link to something good would not suck at all.
:-)
Good Question.
I would like to hear an answer also. I''m working on my first "Test Engine". Real simple stuff. My map only has one floor level (Y=-1) and all I do for collision detection is something like Bounding-Sphere-Overlaps-Line = Collide. Right now I can only detect collisions with vertical and horizontal lines. I would like to add some more sophisticated collision detection but there seems to be little documentation on the net or in books.
In my LevelWall type I have 4 floats that define the end points of a line. Since my level only has one floor height (and my character can''t jump) I only need to check for collisions in two dimensions.
In my collision detection algorithm I would like to define a sencond line made from two more points.
The first point defined by the players new x,z.
The second point would be made from the players rotation (rad) and his bounding sphere radius.
Then I would like to check to see if the lines intersect.
A detailed answer with some source (simple for my newbie brain) or a link to something good would not suck at all.
:-)
If you just want to know if they intersect, the easiest way would be to think of the coordinates as the left, top and right, bottom edges of a rectangle. Then all you have to do is check to see if the rectangles overlap with a few if statements. If you want to to know where they intersect, you have to use algebra and derive some sort of algorithm. I''m sure there''s one, and I know I''ve already used it, but I don''t have time to look for it.
Domini
Domini
Domini Miracle Man Studios
Unfortunately I need to be working with true lines (not sprites) which can be at any angle. It''s like a 3D engine, but with only 2 dimensions (if that makes sense).
I made a similar program once, and yes: you''ll have to check those special cases. But don''t worry, there aren''t many of them (only two ones you listed).
-Hans
-Hans
If the lines have are defined by two (x,y) coordinates, the algorithm will work. It''s not for sprites, but the same principle applies. If you want to check it, draw a few situations so you can visualize what is happening. Just think of the lines as diagonals of a rectangle.
Domini
Domini
Domini Miracle Man Studios
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement