附录 2: 子图的数学公式
变换
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.
以上代码块保留了原文的公式记法 (本附录原文为纯文本排版的公式), 其中的说明文字沿用原文。各符号含义: Mx 和 My 为旋转之前应用的 x 和 y 放大倍率 (可为负, 表示反射); A 为旋转角; (cx, cy) 为子图图像在调用图形中的中心; sx 和 sy 为图像在调用页面上 x 和 y 方向的半尺寸; (Pcx, Pcy) 为被调用子图坐标系中要映射的部分的中心 (默认为 (0, 0)); Psx 和 Psy 为该部分在 x 和 y 方向的半尺寸 (默认均为 +1/2)。
嵌套层级下的变换
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 /)
/_ _/
因此, 如果存在嵌套的完整子图调用, 则任何一层的数据只需被变换一次, 即通过由各嵌套层级的单步变换组合而成的变换。每当调用一个完整子图时 (在下推当前变换之后), 都应计算一个新的"总组合"仿射变换, 方法是将当前的总组合与这一次特定子图调用的仿射变换相组合。
嵌套层级下的部分
只要不涉及旋转, 或者只涉及 pi/2 整数倍的旋转, 那么多层级的部分就很容易实现。在接下来两段的讨论中, 我们假设除了 pi/2 的整数倍之外不涉及其他旋转。
正如可以记录一个"总组合"仿射变换一样, 也可以记录一个部分的总组合。在每一层, 可以按如下步骤进行: 保存当前总部分的一份副本, 并利用单层仿射变换 (在子图调用中指定) 的逆变换, 确定被调用页面上的哪个矩形对应于当前总部分 (在调用页面上)。
该矩形与子图调用中指定 (或默认) 的矩形之间可能存在各种关系。它们可能不相交 (此时根本无需调用该子图); 可能相等 (简单的情形); 一个可能包含另一个, 或者两者可能部分重叠。如果存在交集, 它将是一个矩形, 而这个矩形成为新的总组合部分。
对于 pi/2 整数倍以外的旋转, 问题在于矩形的逆像不再处于标准方向 (垂直和水平的边)。这意味着它与子图调用中指定的部分的交集 (如果非空) 可能有 3、4、5、6、7 或 8 条边。如果更深的层级也涉及旋转, 情况可能变得更糟。虽然 (对某些人而言) 处理这种情况在概念上可能没有困难, 但所涉及的计算量比简单的水平和垂直边的情形要大得多。
对于部分涉及 pi/2 整数倍以外旋转的情形, 本协议不提出任何建议。它确实建议, 嵌套的部分按上述较为简单的情形处理。
[This RFC was put into machine readable form for entry]
[into the online RFC archives by Helene Morin, Via Genie, 12/1999]