Vector Projection Demo/Screensaver

While messing with another project I realized I needed point-line collision detection. I came across this for how to do it: http://funplosion.com/devblog/collision-detection-line-vs-point-circle-and-rectangle.html After trying to figure out how that algorithm works, I realized it was using vector projection (http://en.wikipedia.org/wiki/Vector_projection) to figure out what was the closest point on the line.

To test things out I put together a little demo program: http://ea115.posterous.com/. There are lines and balls that bounce around the screen and it uses the above algorithm to figure out how close each ball is to any of the lines. If its close enough it’ll draw a line from the ball to the closest point on that given line. The color of that line depends on how close the ball is to it. The end result is pretty cool looking I thought. More lines and balls looks cooler, although it’s probably easier to understand what’s going on with less.

That’s hypnotic. Neat demo! And thanks for posting the science behind it - it makes it more than just pretty graphics.

Yes, math is science. :slight_smile:

Hmm - your top link 404s for me.

Science?!?! That’s not science, that’s mathematics!

Ah, Andrew - you know math is just a tool to be used by the real primary discipline - Applied Sciences. :slight_smile:

/ducks and runs

Stunning. Learning a lot on this forum. Thanks!

 Hmm - your top link 404s for me.

The link works fine if you remove that pesky trailing period…

getPointToLineDistance() will be really helpful