CodingTrain / Suggestion-Box

A repo to track ideas for topics
572 stars 86 forks source link

Collision Detection #374

Open slowizzm opened 7 years ago

slowizzm commented 7 years ago

I would love to see an entire series on collision detection.

Point/Point Point/Circle Circle/Circle Point/Rectangle Rectangle/Rectangle Circle/Rectangle Line/Point Line/Circle Line/Line Line/Rectangle Polygon/Point Polygon/Circle Polygon/Rectangle Polygon/Line Polygon/Polygon Triangle/Point Object-Oriented Collision

jmorrow1 commented 7 years ago

If you go down this route, I would consider looking the Separating Axis Test (SAT). The cool thing about this algorithm is that it's not too difficult, and it's general enough to work for any polygon/polygon intersection, and even circle/polygon intersection, which covers most of the things on this list.

These are some resources I found useful when learning the SAT: http://www.dyn4j.org/2010/01/sat/ http://www.sevenson.com.au/actionscript/sat/ http://www.metanetsoftware.com/technique/tutorialA.html

I could also post some processing code implementing the SAT if that's useful.

slowizzm commented 7 years ago

@jmorrow1 ... feel free to share your code, i would love to take a look. i have found some good resources on this subject (collision detection) and have been making some progress.

Ultimately I think a Shiffman style series on this subject would be highly beneficial to the community. I know he covers dist() to get us started, also box2d, but I think we(I) can largely benefit from Dan's style of teaching on this subject.

Thank you for the links, I will look into SAT as this is new to me. 🙏

jmorrow1 commented 7 years ago

I totally agree that intersection/collision detection would be a really valuable coding train topic.

Also, I forgot to mention that the algorithm also works for lines and convex polygons, but it doesn't work for concave polygons.

@shiffman I've put my code of the SAT algorithm up on openprocessing, in case you want to use it in some way in a future coding train episode

shiffman commented 7 years ago

Awesome, thanks for this thread! Agree this could be a great topic. Too many ideas, too little time!