Chapter8_FundamentalsOfComputerGraphic

个人体会

如何学会一个变换?我觉得需要关注变换前后图像的区别,物体位置、大小变了没有?坐标系位置变了没有?
由于这篇文章介绍了一系列的变换,所以要关注前一个变换的输入,因为它是后一个变换的输出。
一个变换可以分解为多个更简单的变换。对一个向量左乘上一个矩阵,相当于对其执行了某种操作。
The Camera Transformation:实际上这个变换是调整相机朝向,使其与 u v w uvw uvw 坐标系对齐。

The Orthographic Projection Transformation:将 orthographic view volume 映射到 canonical view volume。

The Viewport Transformation:将 [ − 1 , 1 ] 2 [-1,1]^2 [1,1]2 映射到 [ − 0.5 , n x + 0.5 ] × [ − 0.5 , n y + 0.5 ] [-0.5, n_x+0.5]\times[-0.5, n_y+0.5] [0.5,nx+0.5]×[0.5,ny+0.5]

Projective Transformations:用 4 维的仿射变换表示 3 维的线性变换,从而避免不能除以 z 的困扰。

Viewing

原文1:A second important use of geometric transformations is in moving objects between their 3D locations and their positions in a 2D view of the 3D world. This 3D to 2D mapping is called a viewing transformation, and it plays an important role in object-order rendering.
翻译1:几何变换的第二个重要用处是在它们的 3 维位置和他们的在 3 维世界的 2 维视图位置中移动物体。这个 3 维到 2 维的映射称之为视图变换,它在对象-顺序渲染过程中起了很重要的作用。
重点1 3 D → 2 D : v i e w t r a n s f o r m a t i o n \mathbf{3D} \rightarrow \mathbf{2D}:\quad \mathbf{view} \quad \mathbf{transformation} 3D2D:viewtransformation
   
原文2:By itself, the ability to project points from the world to the image is only good for producing wireframe renderings—renderings in which only the edges of objects are drawn, and closer surfaces do not occlude more distant surfaces (Figure 8.1). Just as a ray tracer needs to find the closest surface intersection along each viewing ray, an object-order renderer displaying solid-looking objects has to work out which of the (possibly many) surfaces drawn at any given point on the screen is closest and display only that one. In this chapter, we assume we are drawing a model consisting only of 3D line segments that are specified by the (x, y, z) coordinates of their two endpoints. Later chapters will discuss the machinery needed to produce renderings of solid surfaces.
翻译2:就其本身而言,将点从世界投影到图像的能力仅适用于生成线框渲染——在渲染中仅绘制对象的边缘,并且更近的表面不会遮挡更远的表面(图 8.1)。 就像光线追踪器需要沿着每条视线找到最近的表面交叉点一样,显示实体对象的对象顺序渲染器必须计算出在屏幕上任何给定点绘制的(可能许多)表面中的哪个最接近,并且 只显示那个。 在本章中,我们假设我们正在绘制一个仅由 3D 线段组成的模型,这些线段由它们的两个端点的 (x, y, z) 坐标指定。 后面的章节将讨论生成实体表面渲染所需的机制。
重点 2 :This chapter focus on wireframe renderings instead of solid surface rendering.
   
在这里插入图片描述
   

8.1 Viewing Transformations

原文 3 :The viewing transformation has the job of mapping 3D locations, represented as (x, y, z) coordinates in the canonical coordinate system, to coordinates in the image, expressed in units of pixels. It is a complicated beast that depends on many different things, including the camera position and orientation, the type of projection, the field of view, and the resolution of the image. As with all complicated transformations, it is best approached by breaking it up into a product of several simpler transformations. Most graphics systems do this by using a sequence of three transformations:

  • A camera transformation or eye transformation, which is a rigid body transformation that places the camera at the origin in a convenient orientation. It depends only on the position and orientation, or pose, of the camera.
  • A projection transformation, which projects points from camera space so that all visible points fall in the range −1 to 1 in x and y. It depends only on the type of projection desired.
  • A viewport transformation or windowing transformation, which maps this unit image rectangle to the desired rectangle in pixel coordinates. It depends only on the size and position of the output image.

翻译 3 :视图变换的任务是将以在典范坐标系中(x,y,z)表示的 3 维坐标,映射到在图像中的坐标系,以像素作单位表示。这是一个复杂的东西,它取决于许多不同的东西,包括相机的位置和朝向,投影的类型,视野和图像的分辨率。对于所有复杂的转换,最好的方法是将其分解为几个更简单的转换的乘积。大多数图形系统通过使用三个转换序列来实现这一点:

  • 一个相机变换或眼睛变换,这是一个刚体变换将相机以一个方便的方向放在原点。它只取决于相机的位置和方向,或位姿。
  • 投影变换,从相机空间投射点,使所有可见点都落在x 和 y 的 −1 到 1 范围内。它只取决于所需的投影类型
  • 视口转换或窗口转换,它将这个单元图像矩形映射到像素坐标中所需的矩形。它只取决于输出图像的大小和位置。
       
    为了便于描述过程的各个阶段(图8.2),我们对这些转换的输入和输出坐标系进行了命名。
    在这里插入图片描述
       
    原文 4 :The camera transformation converts points in canonical coordinates (or world space) to camera coordinates or places them in camera space. The projection transformation moves points from camera space to the canonical view volume. Finally, the viewport transformation maps the canonical view volume to screen space.
    Each of these transformations is individually quite simple. We’ll discuss them in detail for the orthographic case beginning with the viewport transformation and then cover the changes required to support perspective projection.
       

8.1.1 The Viewport Transformation

The word “canonical” crops up again-it means something arbitrarily chosen for convenience.
For instance, the unit circle could be called the “canonical circle”.
翻译:“规范”这个词又出现了——它指的是为了方便而随意选择的东西。
例如,单位圆可以被称为“规范圆”。
在这里插入图片描述

原文 5
在这里插入图片描述
我们从一个问题开始,这个问题的解决方案将在任何视图条件下重复使用。我们假设我们想要看到的几何是在规范视图体里。我们希望以一个正交相机沿着 -z 轴观察。规范视图体是包含了所有某种 3 维点的立方体。如图8.3所示,这些 3 维点的笛卡尔坐标都在 -1与+1之间,即
( x , y , z ) ∈ [ − 1 , 1 ] 3 (x,y,z)\in[-1,1]^3 (x,y,z)[1,1]3
重点来了!!!!
我们将 x = − 1 x=-1 x=1 投影到屏幕的左侧, x = + 1 x=+1 x=+1 投影到屏幕的右侧, y = − 1 y=-1 y=1 投影到屏幕的底端, y = + 1 y=+1 y=+1 投影到屏幕的顶端。
回忆来自第三章的针对像素坐标的传统:
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

每个像素“拥有”一个在整数坐标的单位正方形;图像边界与像素中心有半个单位的 overshoot;最小的像素中心坐标是(0,0)。如果我们画的图像有 n x × n y n_x\times n_y nx×ny像素,我们需要将正方形 [ − 1 , 1 ] [-1,1] [1,1] 映射到 [ − 0.5 , n x − 0.5 ] × [ − 0.5 , n y − 0.5 ] [-0.5,n_x-0.5] \times [-0.5,n_y-0.5] [0.5,nx0.5]×[0.5,ny0.5]

目前,我们假设所有需要画的线段是完全在规范视图体内。过后,我们会放松假设当我们讨论 clipping 的时候。
在这里插入图片描述

注意上图,说了是要将
[ − 1 , 1 ] 2 [-1,1]^2 [1,1]2
映射到
[ − 0.5 , n x − 0.5 ] × [ − 0.5 , n y − 0.5 ] [-0.5,n_x-0.5]\times [-0.5,n_y-0.5] [0.5,nx0.5]×[0.5,ny0.5]
这个结果可以用等式 (8.1)来验证,当 x c a n o n i c a l = − 1 o r 1 x_{canonical}=-1\quad or\quad 1 xcanonical=1or1时,结果符合。
在这里插入图片描述

8.1.2 The Orthographic Projection Transformation

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

注意,下图中的式(8.3)在下面会介绍!!!
下图中提到 orthographic transform 是将
o r t h o g r a p h i c v i e w v o l u m e orthographic\quad view \quad volume orthographicviewvolume
映射到 c a n o n i c a l v i e w v o l u m e canonical \quad view \quad volume canonicalviewvolume
而,canonical view volume 在上图 8.3 中有介绍。
在这里插入图片描述

在这里插入图片描述
注意,上面所说的 equation(7.7)如下:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

8.1.3 The Camera Transformation

实际上这个变换是调整相机朝向,使其与 u v w uvw uvw 坐标系对齐。
先阅读博主这两篇 单/二向量构造正交向量基底坐标系变换有利于理解。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

下图中说明了,要将坐标系 x y z − xyz- xyz
转换到 u v w − uvw- uvw坐标系。

在这里插入图片描述
上面构造 w , u , v \mathbf{w},\mathbf{u},\mathbf{v} w,u,v 的方法来自博文
下面变换矩阵来自坐标系变换
在这里插入图片描述
在这里插入图片描述

8.2 Projective Transformations

透视(perspective)的一个关键性质是:针对眼镜在原点,视线沿着负z轴看地情况,一个物体的大小在屏幕上与 1 / z 1/z 1/z等比例放缩。即
y s = d z y y_s = \frac{d}{z}y ys=zdy
图 8.8 很好地展示出了这个性质
在这里插入图片描述
其中, y y y 是空间中三维点沿着 y y y 轴的距离, y s y_s ys 是该点应该在屏幕上画出的位置。
我们希望用和处理正交投影一样的矩阵机制来画透视图像;我们能够在我们的复合矩阵上再乘上另外一个矩阵,再使用已经有的算法。然而,这种变换,输入向量的某个坐标出现再分母的位置上,是不能使用仿射(affine)变换得到的。
我们可以用齐次坐标的简单推广来允许除法,我们一直在仿射变换中使用齐次坐标。在齐次坐标下,我们表示一个点 ( x , y , z ) (x,y,z) (x,y,z) 使用 [ x y z 1 ] T [x \quad y \quad z\quad 1]^T [xyz1]T多余的坐标 w w w ,总是等于 1 ,这确保总是使用 [ 0 0 0 1 ] T [0\quad 0 \quad 0 \quad 1]^T [0001]T作为仿射变换矩阵的最后一行。
齐次坐标
[ x y z w ] T [x \quad y \quad z\quad w]^T [xyzw]T
代表的点是
[ x / w y / w z / w ] T [x/w \quad y/w \quad z/w]^T [x/wy/wz/w]T
具体地,线性变换允许我们计算如下的形式:
x ′ = a x + b y + c z x'=ax+by+cz x=ax+by+cz
而仿射变换推广至
x ′ = a x + b y + c z + d x'=ax+by+cz+d x=ax+by+cz+d
w w w作为分母进一步扩展了可能性,允许我们计算这样的函数
x ′ = a x + b y + c z + d e x + f y + g z + h x'=\frac{ ax+by+cz+d}{ ex+fy+gz+h} x=ex+fy+gz+hax+by+cz+d
这可以被称为 x 、 y x、y xy z z z的“线性有理函数”。
但是还有一个额外的限制——对于变换点的所有坐标,分母都是相同的。
x ′ = a 1 x + b 1 y + c 1 z + d 1 e x + f y + g z + h x'=\frac{ a_1x+b_1y+c_1z+d_1}{ ex+fy+gz+h} x=ex+fy+gz+ha1x+b1y+c1z+d1
y ′ = a 2 x + b 2 y + c 2 z + d 2 e x + f y + g z + h y'=\frac{ a_2x+b_2y+c_2z+d_2}{ ex+fy+gz+h} y=ex+fy+gz+ha2x+b2y+c2z+d2
z ′ = a 3 x + b 3 y + c 3 z + d 2 e x + f y + g z + h z'=\frac{ a_3x+b_3y+c_3z+d_2}{ ex+fy+gz+h} z=ex+fy+gz+ha3x+b3y+c3z+d2
表示成一个矩阵变换
[ x ~ y ~ z ~ w ~ ] = [ a 1 b 1 c 1 d 1 a 2 b 2 c 2 d 2 a 3 b 3 c 3 d 3 e f g h ] [ x y z 1 ] \begin{bmatrix} \tilde{x} \\ \tilde{y} \\\tilde{z}\\\tilde{w} \end{bmatrix} = \begin{bmatrix} a_1&b_1 &c_1 & d_1\\ a_2 & b_2& c_2& d_2\\ a_3& b_3 &c_3 & d_3\\ e & f &g & h \end{bmatrix}\begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} x~y~z~w~ = a1a2a3eb1b2b3fc1c2c3gd1d2d3h xyz1
而且,
( x ′ , y ′ , z ′ ) = ( x ~ / w ~ , y ~ / w ~ , z ~ / w ~ ) (x',y',z') = (\tilde{x}/\tilde{w},\tilde{y}/\tilde{w},\tilde{z}/\tilde{w}) (x,y,z)=(x~/w~,y~/w~,z~/w~)

这样的一个变换被称之为 projective transformation 或者 一个 homography

例子17,矩阵
M = [ 2 0 − 1 0 3 0 0 2 3 1 3 ] \mathbf{M}=\begin{bmatrix} 2 & 0 & -1 \\ 0 & 3 & 0\\ 0 & \frac{2}{3} & \frac{1}{3} \end{bmatrix} M= 20003321031
表示一个 2 维投影变换,将单位正方形( [ 0 , 1 ] × [ 0 , 1 ] [0,1]\times[0,1] [0,1]×[0,1])转换到如图 8.9 所示的四边形。
例如,右下角的点 (1,0)以齐次坐标 [ 1 0 1 ] T [1 \quad 0 \quad 1]^T [101]T 表示,被如下变换
[ 2 0 − 1 0 3 0 0 2 3 1 3 ] [ 1 0 1 ] = [ 1 0 1 3 ] \begin{bmatrix} 2 & 0 & -1 \\ 0 & 3 & 0\\ 0 & \frac{2}{3} & \frac{1}{3} \end{bmatrix} \begin{bmatrix} 1\\0\\1 \end{bmatrix}=\begin{bmatrix} 1\\0\\\frac{1}{3} \end{bmatrix} 20003321031 101 = 1031
它代表点 [ 3 0 ] \begin{bmatrix} 3\\0 \end{bmatrix} [30]
在这里插入图片描述
注意,如果我们使用
3 M = [ 6 0 − 3 0 9 0 0 2 1 ] 3\mathbf{M}=\begin{bmatrix} 6 & 0 & -3 \\ 0 & 9 & 0\\ 0 & {2} & {1} \end{bmatrix} 3M= 600092301
上面的结果将会是 [ 3 0 1 ] T [3 \quad 0 \quad 1]^T [301]T,这同样也代表 [ 3 0 ] T [3 \quad 0 ]^T [30]T
事实上,任何标量系数乘上去的结果 c M c\mathbf{M} cM都是等价的:分子和分母都同时被 系数 c放缩,这不改变结果。

3 维的投影变换只是简单的 4 维线性变换,拥有额外的约定:所有标量乘上一个向量指代的是同一个点:
x ∼ α x f o r a l l α ≠ 0 \mathbf{x} \sim \alpha \mathbf{x} \qquad for\quad all \quad \alpha \neq 0 xαxforallα=0
符号 ∼ \sim 被读作 等价于,表示两个齐次向量都刻画了三维空间中的同一个点。

Perspective Projection

投影变换的机制使得实现透视变换需要的除以 z z z 更加简单。
在上图 8.8 展示出来的 2 维例子中,我们可以用如下的一个矩阵变换来实现透视变换
[ y s 1 ] ∼   [ d 0 0 0 1 0 ] [ y z 1 ] \begin{bmatrix} y_s\\1 \end{bmatrix}\sim\ \begin{bmatrix} d & 0 & 0\\ 0 & 1 & 0\\ \end{bmatrix}\begin{bmatrix} y\\ z \\ 1\end{bmatrix} [ys1] [d00100] yz1
这个变换将 2 维齐次向量 [ y , z , 1 ] T [y,z,1]^T [y,z,1]T 转换到 1 维齐次向量 [ d y , z ] T [dy ,z]^T [dy,z]T ,该向量代表一维点 d y / z dy/z dy/z
在 3 维透视变换中,我们采用传统的方式:相机在原点,朝向 − z -z z 轴方向,所以点 ( x , y , z ) (x,y,z) (x,y,z) 的距离是 − z -z z
与正投影一样,我们也采用近面和远面的概念来限制可见距离的范围。在本文中,我们将使用近平面作为投影平面,因此像平面距离为 − n −n n

注意, n n n是负数

这个变换可以用 透视矩阵来实现
P = [ n 0 0 0 0 n 0 0 0 0 n + f − f n 0 0 1 0 ] \mathbf{P}= \begin{bmatrix} n & 0 & 0 &0\\ 0 & n & 0 & 0\\ 0 & 0 & n+f & -fn\\ 0 & 0 & 1 & 0 \end{bmatrix} P= n0000n0000n+f100fn0
第一、二、四行只是简单地实现了透视方程。 第三行,与正交矩阵和视口矩阵一样,旨在将 z 坐标“随行”,以便我们以后可以使用它来去除隐藏的表面。 然而,在透视投影中,非常数分母的添加阻止了我们实际保留 z 的值——实际上不可能在让 x 和 y 做我们需要它们做的事情的同时阻止 z 的变化。 相反,我们选择在近平面或远平面上的点保持 z 不变。
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

8.4 Some Properties of the Perspective Transform

透视变换保直线,保平面。它将在 view volume 里面的线段变换到 canonical volume 里。
为了看出这个,考虑一条线段
q + t ( Q − q ) \mathbf{q}+t(\mathbf{Q}-\mathbf{q}) q+t(Qq)
当通过一个 4 × 4 4\times4 4×4的矩阵 M \mathbf{M} M 来变换,
M q + t ( M Q − M q ) ≡ r + t ( R − r ) \mathbf{Mq}+t(\mathbf{MQ-Mq})\equiv \mathbf{r}+t(\mathbf{R}-\mathbf{r}) Mq+t(MQMq)r+t(Rr)
齐次的 3 维线段是
r + t ( R − r ) w r + t ( W R − w r ) (8.6) \frac{\mathbf{r}+t(\mathbf{R}-\mathbf{r})}{w_r+t(W_R-w_r)}\tag{8.6} wr+t(WRwr)r+t(Rr)(8.6)
如果等式(8.6)可以重写为如下形式
r w r + f ( t ) ( R w R − r w r ) \frac{r}{w_r}+f(t)(\frac{\mathbf{R}}{w_R}-\frac{\mathbf{r}}{w_r}) wrr+f(t)(wRRwrr)
则所有的齐次化点都在一条 3 维直线上。暴力操作上上面的等式(8.6),可以得到如下式子
f ( t ) = w R t w r + t ( w R − w r ) f(t)=\frac{w_Rt}{w_r+t(w_R-w_r)} f(t)=wr+t(wRwr)wRt
事实也证明,线段映射到线段时保留了点的顺序(练习8);也就是说,它们不会被重新排序。
将线段转换为线段的一个副产品是将三角形的边和顶点转换为另一个三角形的边和顶点。 因此,它将三角形转换成三角形和平面转换成平面。

8.5 Field-of-View

虽然我们可以使用 ( l , r , b , t ) (l, r, b, t) (l,r,b,t) n n n 值指定任何窗口,但有时我们希望有一个更简单的系统,我们可以通过窗口的中心确定。 这意味着约束
l = − r b = − t l=-r \\ b=-t l=rb=t
如果我们还加上像素是正方形的约束,即图像中没有形状失真,那么 r r r t t t的比值必须与水平像素数与垂直像素数的比值相同:
n x n y = r t \frac{n_x}{n_y}=\frac{r}{t} nynx=tr
在这里插入图片描述
一旦 n x n_x nx n y n_y ny 被指定,这只留下一个自由度。那就是在图 8.14 中以 θ \theta θ 表示的 field-of-view。
这有时也称作竖直 field-of-view,为了和从左边和右边构成的角区分开。从图 8.14 中,我们可以看到
tan ⁡ θ 2 = t ∣ n ∣ \tan{\frac{\theta}{2}}=\frac{t}{|n|} tan2θ=nt
如果 n n n θ \theta θ 被指定,则我们可以推导出 t t t。在一些系统中, n n n 的值是硬编码为某些合理值的,因此,我们拥有更少的自由度。

Frequently Asked Questions

Is orthographic projection ever useful in practice?

它在相对长度判断很重要的应用中很有用。在某些医疗可视化应用中,透视法过于昂贵,这种方法还可以简化透视法。

The tessellated spheres I draw in perspective look like ovals.Is this a bug?我用透视画的镶嵌球体看起来像椭圆形。这是bug吗?

没有。这是正确的行为。如果你的眼睛相对于屏幕的位置与虚拟观察者相对于视口的位置相同,那么这些椭圆就会看起来像圆圈,因为它们本身是在一个角度观看的。

Does the perspective matrix take negative z values to positive z values with a reversed ordering?Doesn’t that cause trouble?

是的。变换 z z z 的方程是
z ′ = n + f − f n z z'=n+f-\frac{fn}{z} z=n+fzfn
所以当 向 z ′ = − ∞ z'=-\infty z=或者 z ′ = ∞ z'=\infty z= 做变换 z = + ϵ z=+\epsilon z=+ϵ 时。
So any line segments that span z = 0 will be “torn” although all points will be projected to an appropriate screen location. This tearing is not relevant when all objects are contained in the viewing volume. This is usually assured by clipping to the view volume. However, clipping itself is made more complicated by the tearing phenomenon as is discussed in Chapter 9.

The perspective matrix changes the value of the homogeneous coordinate. Doesn’t that make the move and scale transformations no longer work properly?

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

培之

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值