I am writing for HTML5 Canvas, using it as a viewport on which I maintain a central origin and zoom level. I want to track and zoom to a region, but have encountered a naturally occurring effect that spoils the look I am trying to obtain. This question concerns how I might mitigate this while preserving a natural-looking effect.
Imagine I have a downwards-pointing camera mounted on the ceiling, and somewhere on the floor is a piece of paper. I move the camera at a constant speed along the ceiling until it is above the paper, while zooming at a linear rate so that the paper will eventually fill the rendered image. These actions occur simultaneously.
When doing this, an effect can be observed whereby the paper slides out of frame before it returns to centre. This is probably best explained visually, and kept to two dimensions:
This is not a good look. Consider the user requesting focus on something. Their conceptualization is that the entity is moving into view, and it is strange, then, that it appears to first move away before it comes closer.
The effect I wish for is of the target object only approaching the centre of the frame, and never retreating. I suppose the answer is to deform the rate of zoom somehow (or the rate of movement, though I would not prefer this) presumably as a function of the distances involved, or artificially adjust the zoom so the page is kept in frame. I would prefer help towards a solution along the lines of the former approach.
Update:
I think one answer might be to split the zoom part of the operation into two phases. Let the parameters of the problem inform a derivative function that yields the distance between the centres of target and viewport on the rendered output, and find the time at which this is the maximum. Do this for both axes and pick a time between the two: this is the boundary of the zoom phases. In the first phase, zoom to fit the paper just inside the boundary of the image. In the second phase, zoom to the paper to give the same result as before.
This intuitively seems better, but I still have two problems. I can doubtless find the equation for d at t, but my calculus is weak and I might end up sampling for the maximum rather than produce an inverse function to find it, which is what I'd really prefer. I also am not sure how to choose between the two maxima for finding the boundary time (although it may be that there is no 'right' answer to this question, and it is less of a worry to me). Any help with either problem, or any other insight into the broader challenge, will be very gratefully received.