#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Vector Projection Demo/Screensaver

edited December 2011 Posts: 20

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.

• Mod
Posts: 1,557

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. :-)

• Mod
Posts: 1,557

Hmm - your top link 404s for me.

• Posts: 2,161

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

• Mod
Posts: 1,557

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

/ducks and runs

• Posts: 29

Stunning. Learning a lot on this forum. Thanks!

• Posts: 273
`````` Hmm - your top link 404s for me.
``````

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

• Posts: 622

getPointToLineDistance() will be really helpful