Maybe this helps: Here are some functions to fit objects within a view using a few lines of trigonometry math: