How to fit object inside canvas

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