3
$\begingroup$

I am sorry if this is a noob question, I need help with relatively simple math problem and assurance that I understand the problem correctly.

I have a map-like program that zooms in and zooms out if you press the + and - icons (much like google map). Every time you zoom the map size doubles or halves. I know the minimum and maximum size of the map, how do I calculate the number of the doubling steps?

I was thinking of this:

A on power of 2*x equals B, where A is the minimal zoom, B is the maximal zoom a x is the number of steps between them. Am I right?

How do I calculate x form that formula?

Many thanks

  • 2
    I see you have tagged logarithms - have you tried what happens when you take the logarithm of your formula?2011-07-03
  • 0
    @daniel.sedlacek: You are certainly right that if $x$ is the number of steps then $(2^x)A=B$.2011-07-03

1 Answers 1

2

If I understand the question right, after the step $1$ you doubled $A$; after the step $2$, you have $2^{2}A$; after step $x$ you have $$2^{x}A=B.$$ Applying logarithms we get

$$\ln \left( 2^{x}A\right) =\ln B\Leftrightarrow \ln \left( 2^{x}\right) +\ln A=\ln B$$

$$\Leftrightarrow x\ln 2+\ln A=\ln B\Leftrightarrow x=\frac{\ln B-\ln A}{\ln 2}$$

If $x\notin \mathbb{Z}$, then you have to take

$$\left\lceil x\right\rceil =\left\lceil \frac{\ln B-\ln A}{\ln 2}% \right\rceil $$

or

$$\left\lfloor x\right\rfloor =\left\lfloor \frac{\ln B-\ln A}{\ln 2}\right\rfloor .$$

i.e. $n$ steps

$$\left\lfloor \frac{\ln B-\ln A}{\ln 2}\right\rfloor \leq n\leq \left\lceil \frac{\ln B-\ln A}{\ln 2}\right\rceil $$

  • 0
    I think that's exactly it. Many thanks.2011-07-03
  • 0
    Does this formula have a name? I am trying it with my application, but it doesn't like that formula.2012-04-16
  • 0
    @JohnRiselvato: I don't know if it has a name in this context.2012-04-16
  • 0
    For solving for a step, what can i look into?2012-04-16
  • 0
    Given $A$ and $B$ you compute $x=\frac{\ln B-\ln A}{\ln 2}$, and choose the integer $n$ equal to $n=\left\lfloor \frac{\ln B-\ln A}{\ln 2}\right\rfloor$ or $n=\left\lceil \frac{\ln B-\ln A}{\ln 2}\right\rceil $2012-04-16