Advertisement

Test for intersection of lines with endpoints

Started by June 20, 2003 02:02 AM
5 comments, last by Drastick 21 years, 8 months ago
I have a nice algorithem that calculates the intersection of 2 lines for the point of intersection but the problem is that the lines are tested as if they were each on an infanate plane (no endpoints). What I need is one for lines with endpoints so if there is no intersection I want to return false. Maybe I am just not thinking because it is late, but it seems like this should be an easy test. Any help is much thanks.
Find the intersection, and see if it''s within the bounding boxes of both lines. There''re also other ways, but this way I found the easiest, and maybe even the fastest, but don''t quote me on that!
Advertisement
I''ve never done it myself, but I think a parametric solution would be faster. Get parameterized equations for the lines, including t start and t end, do the infinite check, and then check for being within the parameter range. This is how I plan to do my ray-triangle function if I ever get around to doing it.
You know what I never noticed before?
quote:
Original post by vanillacoke
I''ve never done it myself, but I think a parametric solution would be faster. Get parameterized equations for the lines, including t start and t end, do the infinite check, and then check for being within the parameter range. This is how I plan to do my ray-triangle function if I ever get around to doing it.


That''s the same as what Zipster suggested, except the bounding box values are different.

People have also suggested doing a bounding box check first to avoid a costly intersection computation if possible.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Zipsters way sounds the most pratical, and yes it would be smart to test the boxes before hand. Thanks
jambolo: with parametric, there are only two values two compare, instead of four, and I think they would be faster to compute. Of course, if the lines aren't already represented as parametric, it would be better to do bounding box.

edit: scratch that... now that I think about it, its probably faster to do bounding box either way.

[edited by - vanillacoke on June 20, 2003 12:29:53 AM]
You know what I never noticed before?
Advertisement
Could you post your algorithm on here? I''ve been looking for something like that for my (future) air hockey game.

This topic is closed to new replies.

Advertisement