Monday, October 31, 2016

2d - How do I find the intersection of two lines



I have a bounding box on my character, its position in the previous frame an the current frame. The bounding box is axis aligned.


My character is running around inside a cave, I have a list of points (lines) that represents the wall of the cave (not axis aligned)


I've got a coarse grained algorithm that tells me when some part of my character is likely to have collided with some part of the cave wall.


I do not have a fine grained algorithm to tell me specifically which line of the wall was collided with and at which point.


My current thought was that I could just create a line for each corner of the bounding box from its position in the previous frame, to its position in the current frame, then test each of these lines for intersections with any of the lines in the cave wall.


My google fu however hasn't shown me an easy formula for calculating intersections. Have I picked a bad way to do this, or am I just bad at search?


My game is written in scala, however I can read/translate most any c style language and many scripting languages, whatever you feel like answering in



Answer



googling " intersection test line segment line segment" produced this:


http://paulbourke.net/geometry/lineline2d/



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...