The alogorithim for this isn't that simplistic. I have done something similar using the XNA framework but can't remember the exact alogoritihim.
http://msikes.spaces.live.com/Blog/
that link is an XNA resource, ignore all of the Draw and Update code and focus on the calculations that are preformed about half way down through the source.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html