thanks a lot guys, i think there's a minor glitch with the programming.
It's working now with DIG.

But the mathematical approach was good.