【图形学】04 数学部分(四、放射变换)

1、线性变换

线性变换从几何直观有三个要点:

  • 变换前是直线的,变换后依然是直线
  • 直线比例保持不变
  • 变换前是原点的,变换后依然是原点
    比如说旋转,剪切

2、仿射变换

仿射变换从几何直观只有两个要点:

  • 变换前是直线的,变换后依然是直线
  • 直线比例保持不变
inline Vector2D operator * ( const Vector2D& vec,const Matrix3x3& ma) {
	Vector2D new_vec;
	float x = ma._11 * vec.x + ma._21 * vec.y + ma._31;
	float y = ma._12 * vec.x + ma._22 * vec.y + ma._32;
	float z = ma._13 * vec.x + ma._23 * vec.y + ma._33;
	new_vec.x = x / z;
	new_vec.y = y / z;
	return new_vec;
}

  之前我问过谢老师一个问题,为什么代码第6、7行要除以 z,实际上这就涉及到放射变化的部分,因为平移已经不是。线性变换了,平移之后,原点离开了原来的坐标位置。
在这里插入图片描述

  所以,我们平移的时候,实际上是增加了一个向量[0,0,1],同时增加了一个维度,最后我们要把我们的向量还原到之前的维度。
在这里插入图片描述

3、张成空间

  • 二维的张成空间
    在这里插入图片描述

  • 三维的张成空间
    在这里插入图片描述

  • 线性相关:有多组向量构成张成空间,移除其中一个 不减少 张成空间的大小
    线性无关:所有向量 给张成空间增添了新的维度

  • 线性相关:多组向量中,有向量 = 其他向量的线性组合
    在这里插入图片描述

  • 齐次向量:表示同一条直线的一类向量

4、对于齐次坐标的理解

参考链接:https://www.cnblogs.com/csyisong/archive/2008/12/09/1351372.html

  “齐次坐标表示是计算机图形学的重要手段之一,它既能够用来明确区分向量和点,同时也更易用于进行仿射(线性)几何变换。”—— F.S. Hill, JR。

  如何在普通坐标(Ordinary Coordinate)和齐次坐标(Homogeneous Coordinate)之间进行转换:

  • (1)从普通坐标转换成齐次坐标时
      如果(x,y,z)是个点,则变为(x,y,z,1);
      如果(x,y,z)是个向量,则变为(x,y,z,0)

  • (2)从齐次坐标转换成普通坐标时
      如果是(x,y,z,1),则知道它是个点,变成(x,y,z);
      如果是(x,y,z,0),则知道它是个向量,仍然变成(x,y,z)

  《GAMES101》中,也介绍了关于3D坐标系下,齐次坐标的问题。
在这里插入图片描述

  以上是通过齐次坐标来区分向量和点的方式。从中可以思考得知,对于平移T、旋转R、缩放S这3个最常见的仿射变换,平移变换只对于点才有意义,因为普通向量没有位置概念,只有大小和方向。
  而旋转和缩放对于向量和点都有意义,你可以用类似上面齐次表示来检测。从中可以看出,齐次坐标用于仿射变换非常方便。

  此外,对于一个普通坐标的点P=(Px, Py, Pz),有对应的一族齐次坐标(wPx, wPy, wPz, w),其中w不等于零。比如,P(1, 4, 7)的齐次坐标有(1, 4, 7, 1)、(2, 8, 14, 2)、(-0.1, -0.4, -0.7, -0.1)等等。因此,如果把一个点从普通坐标变成齐次坐标,给x,y,z乘上同一个非零数w,然后增加第4个分量w;如果把一个齐次坐标转换成普通坐标,把前三个坐标同时除以第4个坐标,然后去掉第4个分量。

  由于齐次坐标使用了4个分量来表达3D概念,使得平移变换可以使用矩阵进行,从而如F.S. Hill, JR所说,仿射(线性)变换的进行更加方便。由于图形硬件已经普遍地支持齐次坐标与矩阵乘法,因此更加促进了齐次坐标使用,使得它似乎成为图形学中的一个标准。

n、多边形重心的推论

Yes, yes, but why? The current answers (as well as Wikipedia) do not contain enough detail to understand these formulas immediately. So let’s start with the very basic definition of the area centroid: C ⃗ = ∬ r ⃗ ( x , y )   d x   d y ∬ d x   d y = ( ∬ x   d x   d y , ∬ y   d x   d y ) ∬ d x   d y = ( m x , m y ) A = ( C x , C y ) \vec{C} = \frac{\iint \vec{r}(x,y)\,dx\,dy}{\iint dx\,dy} = \frac{(\iint x\,dx\,dy,\iint y\,dx\,dy)}{\iint dx\,dy} = \frac{(m_x,m_y)}{A}=(C_x,C_y) C =dxdyr (x,y)dxdy=dxdy(xdxdy,ydxdy)=A(mx,my)=(Cx,Cy) Allright, let’s get rid of the double integrals in the first place, by employing Green’s theorem : ∬ ( ∂ M ∂ x − ∂ L ∂ y ) d x   d y = ∮ ( L   d x + M   d y ) \iint \left( \frac{\partial M}{\partial x} - \frac{\partial L}{\partial y} \right) dx\,dy = \oint \left( L\,dx + M\,dy \right) (xMyL)dxdy=(Ldx+Mdy) At the edges of the (convex) polygon we have: KaTeX parse error: Undefined control sequence: \mbox at position 88: …d{cases} \quad \̲m̲b̲o̲x̲{with} \quad \b… Then by substitution of M ( x , y ) = x M(x,y) = x M(x,y)=x and L ( x , y ) = 0 L(x,y) = 0 L(x,y)=0 we have: A = ∬ d x   d y = ∮ x   d y = ∑ i = 0 n − 1 ∫ 0 1 [ x i + ( x i + − x i )   t ] ( y i + − y i )   d t = ∑ i = 0 n − 1 ( y i + − y i ) [ x i t ∣ 0 1 + ( x i + − x i ) 1 2 t 2 ∣ 0 1 ] = 1 2 ∑ i = 0 n − 1 ( x i + + x i ) ( y i + − y i ) = 1 2 ∑ i = 0 n − 1 ( x i y i + − x i + y i ) A = \iint dx\,dy = \oint x\,dy = \sum_{i=0}^{n-1} \int_0^1 \left[x_i + (x_{i+}-x_i)\,t\right](y_{i+}-y_i)\,dt=\\ \sum_{i=0}^{n-1}(y_{i+}-y_i)\left[x_i\left.t\right|_0^1 + (x_{i+}-x_i)\frac{1}{2}\left.t^2\right|_0^1\right] = \frac{1}{2}\sum_{i=0}^{n-1}(x_{i+}+x_i)(y_{i+}-y_i)=\\ \frac{1}{2}\sum_{i=0}^{n-1} (x_iy_{i+}-x_{i+}y_i) A=dxdy=xdy=i=0n101[xi+(xi+xi)t](yi+yi)dt=i=0n1(yi+yi)[xit01+(xi+xi)21t201]=21i=0n1(xi++xi)(yi+yi)=21i=0n1(xiyi+xi+yi) The last move by telescoping.
The main integral for the x x x-coordinate of the centroid is,
with M ( x , y ) = x 2 / 2 M(x,y) = x^2/2 M(x,y)=x2/2 and L ( x , y ) = 0 L(x,y) = 0 L(x,y)=0: m x = ∬ x   d x   d y = ∮ 1 2 x 2   d y = 1 2 ∑ i = 0 n − 1 ( y i + − y i ) ∫ 0 1 [ x i + ( x i + − x i )   t ] 2   d t = 1 2 ∑ i = 0 n − 1 ( y i + − y i ) [ x i 2 t ∣ 0 1 + 2 x i ( x i + − x i ) 1 2 t 2 ∣ 0 1 + ( x i + − x i ) 2 1 3 t 3 ∣ 0 1 ] = 1 2 ∑ i = 0 n − 1 ( y i + − y i ) [ x i 2 + x i ( x i + − x i ) + 1 3 ( x i + − x i ) 2 ] = 1 6 ∑ i = 0 n − 1 ( y i + − y i ) [ x i + 2 + x i x i + + x i 2 ] = 1 6 ∑ i = 0 n − 1 [ x i x i + y i + + x i 2 y i + − x i + 2 y i − x i x i + y i ] ⟹ m x = 1 6 ∑ i = 0 n − 1 ( x i + x i + ) ( x i y i + − x i + y i ) m_x = \iint x\,dx\,dy = \oint \frac{1}{2}x^2 \,dy = \frac{1}{2}\sum_{i=0}^{n-1}(y_{i+}-y_i)\int_0^1\left[x_i + (x_{i+}-x_i)\,t\right]^2\,dt=\\ \frac{1}{2}\sum_{i=0}^{n-1}(y_{i+}-y_i)\left[x_i^2\left.t\right|_0^1+2x_i(x_{i+}-x_i)\frac{1}{2}\left.t^2\right|_0^1 +(x_{i+}-x_i)^2\frac{1}{3}\left.t^3\right|_0^1\right]=\\ \frac{1}{2}\sum_{i=0}^{n-1}(y_{i+}-y_i)\left[x_i^2+x_i(x_{i+}-x_i)+\frac{1}{3}(x_{i+}-x_i)^2\right]=\\ \frac{1}{6}\sum_{i=0}^{n-1}(y_{i+}-y_i)\left[x_{i+}^2+x_ix_{i+}+x_i^2\right]=\\ \frac{1}{6}\sum_{i=0}^{n-1}\left[x_ix_{i+}y_{i+}+x_i^2y_{i+}-x_{i+}^2y_i-x_ix_{i+}y_i\right]\quad\Longrightarrow\\ m_x = \frac{1}{6}\sum_{i=0}^{n-1}(x_i+x_{i+})(x_iy_{i+}-x_{i+}y_i) mx=xdxdy=21x2dy=21i=0n1(yi+yi)01[xi+(xi+xi)t]2dt=21i=0n1(yi+yi)[xi2t01+2xi(xi+xi)21t201+(xi+xi)231t301]=21i=0n1(yi+yi)[xi2+xi(xi+xi)+31(xi+xi)2]=61i=0n1(yi+yi)[xi+2+xixi++xi2]=61i=0n1[xixi+yi++xi2yi+xi+2yixixi+yi]mx=61i=0n1(xi+xi+)(xiyi+xi+yi) The last two moves after telescoping again.
The main integral for the y y y-coordinate of the area centroid is,
with M ( x , y ) = 0 M(x,y) = 0 M(x,y)=0 and L ( x , y ) = − y 2 / 2 L(x,y) = -y^2/2 L(x,y)=y2/2: m y = ∬ y   d x   d y = ∮ − 1 2 y 2   d x = − 1 2 ∑ i = 0 n − 1 ( x i + − x i ) ∫ 0 1 [ y i + ( y i + − y i )   t ] 2   d t m_y = \iint y\,dx\,dy = \oint -\frac{1}{2}y^2 \,dx = -\frac{1}{2}\sum_{i=0}^{n-1}(x_{i+}-x_i)\int_0^1\left[y_i + (y_{i+}-y_i)\,t\right]^2\,dt my=ydxdy=21y2dx=21i=0n1(xi+xi)01[yi+(yi+yi)t]2dt Which is similar to the main integral for the x x x-coordinate of the centroid: m x = ∬ x   d x   d y = ∮ 1 2 x 2   d y = 1 2 ∑ i = 0 n − 1 ( y i + − y i ) ∫ 0 1 [ x i + ( x i + − x i )   t ] 2   d t m_x = \iint x\,dx\,dy = \oint \frac{1}{2}x^2 \,dy = \frac{1}{2}\sum_{i=0}^{n-1}(y_{i+}-y_i)\int_0^1\left[x_i + (x_{i+}-x_i)\,t\right]^2\,dt mx=xdxdy=21x2dy=21i=0n1(yi+yi)01[xi+(xi+xi)t]2dt It is seen that everything is the same if we just exchange x x x and y y y, except for the minus sign, hence: m y = − 1 6 ∑ i = 0 n − 1 ( y i + y i + ) ( y i x i + − y i + x i ) = 1 6 ∑ i = 0 n − 1 ( y i + y i + ) ( x i y i + − x i + y i ) m_y = -\frac{1}{6}\sum_{i=0}^{n-1}(y_i+y_{i+})(y_ix_{i+}-y_{i+}x_i)=\frac{1}{6}\sum_{i=0}^{n-1}(y_i+y_{i+})(x_iy_{i+}-x_{i+}y_i) my=61i=0n1(yi+yi+)(yixi+yi+xi)=61i=0n1(yi+yi+)(xiyi+xi+yi) Combining the partial results found gives the end result, as displayed in the question.

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值