distance at best angle function in c