Coyote's Guide to IDL Programming

Bogus Math

QUESTION: Uh, doesn't POSITION=[0.1, 0.1, 0.9, 0.9] actually take up 64% of the display window, Dave?

ANSWER: Ed Vaughan supplies the answer.

I realize that I mentioned this before in relation to your excellent book, but I just noticed something similar in your Positioning Images in IDL tip.

The statement that I have a problem with appears within the paragraph below (and again in the first paragraph of the subsection entitled "Sizing Images in PostScript Output"):

"Suppose for a moment that you weren't fastidious about preserving the aspect ratio of your image (i.e., its relative proportion of length to height). But what you wanted was for your image to always fill up the middle 80% of the display window. In terms of normalized coordinates (see the Position Plots Programming Tip for more information about this), you can say you would like its position to be given like this:

   IDL> position = [0.1, 0.1, 0.9, 0.9] ..."

My contention (which you've may recall having seen before in another context) is that this would result in filling up 64% of the window space, rather than 80%. Because:

     ( 0.9 - 0.1 ) x ( 0.9 - 0.1 )
     ----------------------------- x 100% = 64%
     ( 1.0 - 0.0 ) x ( 1.0 - 0.0 )

CASE I. To fill up 80%, and to retain the upper right-most coordinates, for example, one would have to solve the equation:

       ( 0.9 - X ) x ( 0.9 - X )
     ----------------------------- x 100% = 80%
     ( 1.0 - 0.0 ) x ( 1.0 - 0.0 )

This leads to a quadratic in X, whose only meaningful solution is:

     X = 0.005572809

If we round off to four places, the position vector will instead be:

      position = [0.0056, 0.0056, 0.9, 0.9]

and we will obtain the expected (i.e., almost 80%) result:

    ( 0.9 - 0.0056 ) x ( 0.9 - 0.0056 )
     ----------------------------------- x 100% = 79.995+%
        ( 1.0 - 0.0 ) x ( 1.0 - 0.0 )

CASE II. Similarly, if one wishes to fill up 80%, but to retain the lower left-most coordinates, one would have to solve the equation:

      ( Y - 0.1 ) x ( Y - 0.1 )
     ----------------------------- x 100% = 80%
     ( 1.0 - 0.0 ) x ( 1.0 - 0.0 )

This leads to a quadratic in Y, whose only meaningful solution is:

    Y = 0.994427191

If we round off to four places, the position vector will then be:

      position = [0.1, 0.1, 0.9944, 0.9944]

and again we will obtain the expected (i.e., almost 80%) result:

   ( 0.9944 - 0.1 ) x ( 0.9944 - 0.1 )
     ----------------------------------- x 100% = 79.995+%
        ( 1.0 - 0.0 ) x ( 1.0 - 0.0 )

CASE III. If we postulate a square in (x,y)-space with its opposite cor- ners positioned at (0.0,0.0) and (1.0,1.0), and a square within situated symmetrically at (x,x) and (1-x,1-x), then the area of that internal square is ( ( 1 - x ) - x ) ^ 2, or 1 -4*x -4*x^2.

So, for example, if we seek to find the internal square that occupies exactly 80% of its host square, and is symmetrically placed, then we have only to solve the equation:

        1 -4*x + 4*x^2 = 0.8, or 4*x^2 - 4*x + 0.2 = 0

In the present context, the solutions of this equation are:

   UPPER     x = 0.947213595+ ( or, more precisely, 0.5 + SQRT(0.2) )
   LOWER     x = 0.052786404+ ( or, more precisely, 0.5 - SQRT(0.2) )
   position = [0.052786404, 0.052786404, 0.947213595, 0.947213595]

Checking:

   ( (1-x) - x ) * ( (1-x) -x )           (0.894427192)^2
   ----------------------------- x 100 =  --------------- x 100 = 80%  :-)
   ( 1.0 - 0.0 ) * ( 1.0 - 0.0 )                1.0

It nonetheless seems odd that the internal square with opposing corners at (0.0528-, 0.0528-) and (0.947+, 0.947+) takes up only 80% of the entire area. (But if THAT seems odd, then take a look at some of the collections of classical problems in probability! :-( ).

Google
 
Web Coyote's Guide to IDL Programming