Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Line Collision Detection?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Geog




PostPosted: Wed Mar 12, 2008 1:36 pm   Post subject: Line Collision Detection?

I am working on an asteroids game, where the asteroids are generated randomly using 8 logical points, and the spaceship is drawn using 3 points. Is there is a method I could use to detect if a line of the asteroid has touched a line of the spaceship?
Sponsor
Sponsor
Sponsor
sponsor
richcash




PostPosted: Wed Mar 12, 2008 1:50 pm   Post subject: Re: Line Collision Detection?

I covered line segment vs line segment in my tutorial. You can also google line intersection (you probably learned it in math class), assume both line segments are infinite lines, and then use some logic to check if the intersection is on both line segments.

However, are your spaceship and asteroids convex polygons? If they are convex, then in that same tutorial it shows how to do convex polygons intersection, so that would be more efficient than checking all possible pairs of lines. But, again, the polygons have to be convex.

If you don't understand the tutorial, I can try to re-explain it in another way.
Geog




PostPosted: Fri Mar 14, 2008 2:17 pm   Post subject: RE:Line Collision Detection?

I had collision detection for the bullets/asteroids, but I'd really like to use your polygon/polygon collision detection code. It is a little bit complicated for me though... could you explain your example a little bit more? I don't really understand why you are checking for a minimum/maximum, and what it is a minumum/maximum of.
richcash




PostPosted: Fri Mar 14, 2008 5:33 pm   Post subject: Re: Line Collision Detection?

I am just finding the highest (max) and lowest (min) points on each line segment (projection). Because the projections are on the same axis, the easiest way to check if they overlap would just be to check if the highest point on line 1 is higher than the lowest point on line 2 and if the highest point on line 2 is higher than the lowest point on line 2. It's sort of like rectangular collision.

That is not that important, you can use any method you want to check if the projections are overlapping. The most important part is understanding what the algorithm is and why it works.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: