Skip to main content

Appendix 2: Mathematical Formulae for Subpictures

Transformations​

In this appendix positions in a logical coordinate system will be
represented by a row vector with two elements, as in /_ x y_/.  Vectors
and matrices will be delimited by these funny brackets: /_ _/.  Various
symbols will be used to represent parameters in a full subpicture call
relating to a transformation from one coordinate system to another;
these are defined below:

Mx and My : magnifications in x and y to be applied before any
            rotation.
            They may be negative indicating reflection.
A: an angle of rotation in the range 0 to just less than 2pi.
/_ |cx |cy_/ : the center (in the calling picture) of the image of the
          subpicture.

|sx |sy : the half-sizes, in the x and y directions, of the
           image on the calling page in terms of the calling page's
           coordinate system.
           They may be negative to indicate reflection.
/_ x y_/ : a position on the called page.
/_ |x |y_/ : the position on the calling page corresponding to /_x y_/.
/_ Pcx Pcy_/ : The center of the portion of the called subpicture's
               coordinate system which is to be mapped to the calling
               page.
               This defaults to /_ 0 0_/ if not specified.
Psx and Psy : The half-sizes in x and y of the portion of the
              subpicture to be mapped. These both default to +1/2
              in not specified.

(If a uniform magnification is specified, set Mx and My equal to it and
proceed below as if they were specified.)

If magnifications are specified, the following holds:

/_ |x |y_/ = (/_ x y_/ - /_ Pcx Pcy_>) * / Mx/Psx  0    / *
                                        /_   0  My/Psy_/

          / cos 0 sin 0 / * / 1/2 0  / + /_ |cx |cy_/
         /_ -sin0 cos0_/  /_ 0  1/2_/

or in other words,

1)
/_|x |y_/ = /_ x-Pcx y-Pcy_/ * / Mx cosA/2Psx Mx sinA/2Psx /
                             /_ -My sinA/2Psy My cosA/2Psy_/
            +/_ |cx |cy_/

(The factor of 1/2 is necessary because, for instance, (x-Pcx)/Psx
ranges from -1 to +1 for x values within the portion (i.e., such that
|x-Pcx| <|Psx| ) whereas the image, in the calling subpicture's
coordinate system, should only range from -1/2 to +1/2.)

If the image size is specified instead of the magnification, we have the
following:

/_ |x |y_/ = (/_ x y_/ - /_Pcx Pcy_/) * / 1/Psx  0    / *
                                       /_  0  1/Psy _/

          / cosA sinA    / * / |sx 0    / + /_ |cx |cy_/
         /_ -sinA cosA _/   /_ 0  |sy _/

or, in other words,

2)
/_|x |y_/ = /_x-Pcx y-Pcy_/ * /|sx cosA/Psx |sy sinA/Psx /
                            /_-|sx sinA/Psy |sy cosA/Psy_/

           + /_|cx |cy_/

Expanding the parenthesized quantities in equations 1) and 2), we
have:

3a) /_|x |y_/ = /_x y_/ * /Mx cosA/2Psx   Mx  sinA/2Psx /
                         /_-My sinA/2Psy  My cosA/2Psy_/

           + /_|cx-PcxMxcosA/2Psx+PcyMysinA/2Psy
                      |cy-PcxMxsinA/2Psx-PcyMycosA/2Psy _/

and

3b) /_|x |y_/ = /_x y_/ * /|sx cosA/Psx |sy sinA/Psx  /
                        /_-|sx sinA/Psy |sy cosA/Psy_/

           + /_|cx-Pcx|sxcosA/Psx+Pcy|sxsinA/Psy
                      |cy-Pcy|sysinA/Psx-Pcy|sycosA/Psy_/

Various interesting substitutions can be made in 3a) and 3b).
For example, if A=0 (no rotation), then we have:

4a) /_|x |y_/ = /_x y_/ * /Mx/2Psx 0 / + /_|cx-PcxMx/2Psx
|cy-PcyMy/2Psy_/
                         /_ 0 My/2Psy_/

4b) /_|x |y_/ = /_x y_/ *  /|sx/Psx 0 / + /_|cx-Pcx|sx/Psx
|cy-Pcy|sy/Psy_/
                          /_ 0 |sy/Psy_/

Another example is if no portioning is done (Pcx=Pcy=0, Psx=Psy=1/2):

5a) /_|x |y_/ = /_ x y_/  * /Mx cosA Mx sinA   / + /_|cx |cy_/
                           /_-My sinA My sinA_/

5b) /_|x |y_/ = /_ x y_/ * /2|sx cosA 2|sy sinA   / + /_|cx |cy_/
                          /_-2|sx sinA 2|sx cosA_/

If in addition, 0=0, we have:

6a) /_|x |y_/ =  /_ xMx+|cx  yMy+|cy_/

6b) /_|x |y_/ = /_ x*2|sx+|cx y*2|sy+|cy_/

Of course, in all cases, the transformation from /_x y_/ to /_|x |y_/
can be written in the form:

/_|x |y_/ = /_x y_/ * / 2 by 2 / + /_ translation _/
                     /_ matrix _/

In general, a transformation combining a linear transformation and a
translation is called an affine transformation.

Transformations with Nested Levels​

The combination of two affine transformations is again an affine
transformation. Indeed, if

/_|x |y_/ = /_x y_/ * / Mat1 / + /_ Tran1 _/
/_ _/
and

/_|x_ |y__/ = /_|x |y_/ * ( / Mat1 / * / Mat2 /)
/_ _/ /_ _/
+ (/_ Tran2 _/ + /_ Tran1 _/ * / Mat2 /)
/_ _/

Thus if one has nested full subpicture calls, the data at any level need be transformed only once, namely, by the transformation which is the combination of the single step transformations at each level of nesting. A new "grand combination" affine transformation should be computed whenever a full subpicture is called (after pushing down the current transformation) by combining the current grand combination with the affine transformation for this particular subpicture call.

Portions with Nested Levels​

As long as no rotations are involved, or even only rotations in multiples of pi/2, then multiple levels of portions are easy to implement. In the discussion in the next two paragraphs let us assume that no rotations other than whole multiples of pi/2 are involved.

Just as one can keep track of a "grand combination" affine transformation, so can one keep a grand combination of portions. At each level, one can proceed as follows: Save a copy of the current grand portion, and use the inverse of the single level affine transformation (specified in the subpicture call) to determine what rectangle of the called page corresponds to the current grand portion (on calling page).

Various relations may exist between this rectangle and the rectangle specified (or defaulted) in the subpicture call. They may be disjoint (in which case this subpicture need not be called at all); they may be equal (an easy case); one may contain the other or they may partially overlap. If there is any intersection, it will be a rectangle, and this rectangle becomes the new grand combination portion.

The problem with rotations other than multiples of pi/2 is that the inverse image of the rectangle is no longer in the standard orientation (vertical and horizontal edges). This means that its intersection with the portion specified on the subpicture call may have 3, 4, 5, 6, 7, or 8 edges (if it is non-empty). Deeper levels may get even worse if they involve rotations too. While there may be no conceptual difficulty (for some) in working with such a situation, significantly more computation is involved than in the simple horizontal and vertical edge case.

This protocol puts forward no recommendation in the case that rotations other than whole multiples of pi/2 are involved with portions. It does suggest that nested portions be handled as described above in the more straightforward case.

[This RFC was put into machine readable form for entry]
[into the online RFC archives by Helene Morin, Via Genie, 12/1999]