Please have a look ? I debugged it, it works flawlessly. (though I'm sure there are easier and more efficient ways to do it, just don't know the math functions well enough to use it)