1

Intro

I'm writing a program that zooms in and out on an image and the only way to do it with the data I have is to change the limits of my graph. The aspect ratio (scale of x to y) always remains 1:1 and the ratio of the x limits to the y limits must be 1280/720. The zoom is based off of just one variable, we call $d =$ depth

Question

I am having trouble scaling it when the parameter $d$ changes from the default value, which is just a scale factor, and the default value is $1$. I can get it to scale correctly at the default value, but the current equations I have slowly deviate from what I want as I increasee/decrease $d$. The hardest part for me is that I need the image to always be centered within the limits of the plot, as well as keeping the proper scale between $x$ and $y$. The variables used are:

$R_f = d \cdot R_i \rightarrow$ final resolution (resolution of my depth-scaled image)

$R_i = 250\times250 $ resolution $ \rightarrow$ initial resolution (resolution of image before being scaled by depth)

$d = $ depth

The default position of my image has it's top left corner at the origin $(0,0)$ and propagates in the $+x,-y$ direction, so the bottom right corner is at $(R_f, -R_f)$. Now I need equations to define the limits of $(x_i,y_i)$ and $(x_f,y_f)$ based on those parameters so that the image is always centered, no matter how $d$ changes (well, it can't be negative).

My Attempt

This is what I tried. I think my error comes from forming my last term for the $x$ limits. I just can't figure out how to make a correct combination of the 2nd and 3rd terms I discuss...anyways. First I defined $$y_i = \frac{R_f}{2} - \frac{R_i}{2}$$ $$y_f = \frac{R_f}{2} + \frac{R_i}{2}$$

which seems to do the job for centering the image for all $d$. The limits become larger in comparison to the resolution of my image as $d$ increases and vice-versa, so I think I'm good here. Now the trouble comes with $x_i, x_f$. At all values, we know that the limits of $x$ must be $1280/720 = 1.778$ times larger than the $y$ limits. Taking note of this at the default value, where $d=1$, we know that we must add in a term for the $x$ limits (using a simple scale factor on the y-limits here doesn't work, since the image needs to be centered). I came up with $\frac{1}{2} \cdot R_f(\frac{1280}{720} - 1)$. Now I just subtract this term for $x_i$ and add it for $x_f$ to the respective y limits, and this works for the default value.

Now we face more problems when we aren't at the default value though. This problem can be illustrated if we draw a small square box (our image) in a very large rectangle and look at our given equations. Clearly, the added term in the previous paragraph becomes negligible in comparison to the total growth of the $x$ limits. But the $y$ limits and $x$ limits can't be increasing at the same rate, otherwise our resolution will be compromised. So one more term is neccessary. I thought the final term would be $\frac{1280}{720}(\frac{R_f}{2} - \frac{R_i}{2})$, giving my $x$ limits as

$$x_i = \left(1 + \frac{1280}{720}\right) \left(\frac{R_f}{2} - \frac{R_i}{2}\right) - \frac{1}{2} \cdot R_f\left(\frac{1280}{720} - 1\right)$$ $$x_f = \left(\frac{R_f}{2} + \frac{R_i}{2}\right) - \frac{1}{2} \cdot R_f\left(\frac{1280}{720} - 1\right) - \frac{1280}{720} \left(\frac{R_f}{2} - \frac{R_i}{2}\right)$$

But this doesn't quite work. If my $d \le 1$ it actually works pretty well (but not perfect) but as $d$ gets bigger and bigger, my error blows up more and more. Anyways, if someone can figure out where I'm going wrong, that would be great! I honestly didn't think this task would be too difficult!

  • I don't have enough reputation to comment. You say that the resolution of the image must always be 1280x720 But then if $ R_f = d.R_i$ and $ R_i $= 250 x 250 Like for d=2 $R_f = $ 500x500 right. So what do you mean by the resolution of the image must always be 1280x720 –  Aug 27 '13 at 13:38
  • Sorry I may have been a little unclear there. When I say the resolution must be that, I must just the ratio of the rectangle's width to height that I am plotting my image in. So it doesn't have to always have units of 1280x720...just as long as the ratio between the x coordinates to the y coordinates is the same as 1280/720 that is fine. But you're right, if $d = 2$ the resolution of the image is 500x500. Forget the "resolution must be 1280x720", just think that the rectangle I'm plotting in must have limits that correspond to that ratio – Spaderdabomb Aug 27 '13 at 13:51
  • Honestly, I'm completely confused about what the task is. It looks like you are trying to turn a square into a rectangle without changing the ratio of coordinate scales, which makes no sense. Also, what is the point to which you are zooming? Can you edit your post and describe the task at hand precisely? – fedja Aug 27 '13 at 15:26

0 Answers0