Chapter 4 Transforms

本文深入探讨了计算机图形学中的基本变换,包括平移、旋转、缩放等,并详细解析了四元数的概念、运算及其在旋转中的应用。通过实例展示了如何使用四元数避免万向锁问题,实现高效稳定的旋转变换。

(个人笔记,由于刚开始学习再加上英语不太好,所以有的地理解的可能不太对,望指正)

Chapter 4 Transforms

基础变换

仿射变换的特点是保证了平行关系,但是长度跟角度可能发生变化。

各种变换操作的描述:

在这里插入图片描述

其中正交投影是正交的。。。

Basic Transforms

Translation

T(t)=T(tx,ty,tz)=(100tx010ty001tz0001)T−1(t)=T(−t) T(t) = T(t_x, t_y, t_z) = \begin{pmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\ 0 & 0 & 1 & t_z \\ 0 & 0 & 0 & 1 \\ \end{pmatrix} \\ \qquad \\ \qquad T^{-1}(t) = T(-t) T(t)=T(tx,ty,tz)=100001000010txtytz1T1(t)=T(t)

Rotation

旋转会保持点之间的距离以及handness

二维旋转

u=(rcos(θ+ϕ)rsin(θ+ϕ))=(r(cosθcosϕ−sinθcosϕ)r(sinθcosϕ+sinϕcosθ))=(cosϕ−sinϕsinϕcosϕ)(rcosθrsinθ)=R(ϕ)v u = \begin{pmatrix} rcos(\theta + \phi) \\ rsin(\theta + \phi) \end{pmatrix} = \begin{pmatrix} r(cos\theta cos\phi - sin\theta cos\phi) \\ r(sin\theta cos\phi + sin\phi cos\theta) \end{pmatrix} = \begin{pmatrix} cos \phi & -sin\phi \\ sin \phi & cos \phi \end{pmatrix} \begin{pmatrix} rcos\theta \\ rsin\theta \end{pmatrix} = R(\phi)v u=(rcos(θ+ϕ)rsin(θ+ϕ))=(r(cosθcosϕsinθcosϕ)r(sinθcosϕ+sinϕcosθ))=(cosϕsinϕsinϕcosϕ)(rcosθrsinθ)=R(ϕ)v

三维旋转

Rx(ϕ)=(10000cosϕ−sinϕ00sinϕcosϕ00001),Ry(ϕ)=(cosϕ0sinϕ00100−sinϕ0cosϕ00001),Rz(ϕ)=(cosϕ−sinϕ00sinϕcosϕ0000100001) R_x(\phi) = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & cos\phi & -sin\phi & 0 \\ 0 & sin\phi & cos\phi & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}, \\ R_y(\phi) = \begin{pmatrix} cos\phi & 0 & sin\phi & 0 \\ 0 & 1 & 0 & 0 \\ -sin\phi & 0 & cos\phi & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}, \\ R_z(\phi) = \begin{pmatrix} cos\phi & -sin\phi & 0 & 0 \\ sin\phi & cos\phi & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} Rx(ϕ)=10000cosϕsinϕ00sinϕcosϕ00001,Ry(ϕ)=cosϕ0sinϕ00100sinϕ0cosϕ00001,Rz(ϕ)=cosϕsinϕ00sinϕcosϕ0000100001

三维旋转矩阵的迹(trace)都为:

tr(R)=1+2cosϕ tr(R) = 1 + 2cos\phi tr(R)=1+2cosϕ

所有旋转矩阵的行列式值都为1并且都是正交的。

Ri−1(ϕ)=Ri(−ϕ) R_i^{-1}(\phi) = R_i(-\phi) Ri1(ϕ)=Ri(ϕ)

例子:绕一点旋转

在这里插入图片描述

旋转公式:

X=T(p)Rz(ϕ)T(−p) X = T(p)R_z(\phi)T(-p) X=T(p)Rz(ϕ)T(p)

Scaling

S(s)=(sx0000sy0000sz00001)S−1(s)=S(1/sx,1/sy,1/sz) S(s) = \begin{pmatrix} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ 0 & 0 & s_z & 0 \\ 0 & 0 & 0 &1 \end{pmatrix} \\ \qquad \\ S^{-1}(s) = S(1/s_x, 1/s_y, 1/s_z) S(s)=sx0000sy0000sz00001S1(s)=S(1/sx,1/sy,1/sz)

反射变换可以通过-1作为参数进行缩放,反射变换可能导致顶点顺序发生变化。要判断某个变换是否是反射,则计算左上3x3矩阵的行列式,如果为负则是反射变换。

Shearing

三维空间下Shearing变换共有六种:Hxy(s),Hxz(s),Hyx(s),Hyz(s),Hzx(s),Hzy(s)H_{xy}(s), H_{xz}(s), H_{yx}(s), H_{yz}(s), H_{zx}(s), H_{zy}(s)Hxy(s),Hxz(s),Hyx(s),Hyz(s),Hzx(s),Hzy(s)其中第一个脚注表示是哪个维度值发生变化,第二个值是哪个维度进行shearing操作,也就是乘以哪个维度的值,以Hxz(s)H_{xz}(s)Hxz(s)为例:

在这里插入图片描述

变换矩阵为:

改变换产生了一个点(px+spz,py,pz)(p_x + sp_z, p_y, p_z)(px+spz,py,pz)
shearing变换的逆变换:Hij−1(s)=Hij(−s)H_{ij}^{-1}(s)=H_{ij}(-s)Hij1(s)=Hij(s)

The Rigid-Body Transform

只包含平移跟旋转的变换矩阵称为刚体变换。

$$
X=T(t)R=\begin{pmatrix}
R & T \
0 & 1 \
\end{pmatrix}

x^{-1}=(T(t)R)^{-1}=R^{-1}T(t)^{-1}=R^TT(-t)

$$

Normal Transform

Mn=(A−1)TA−1=1∣A∣A∗ M_n = (A^{-1})^T \\ A^{-1}=\frac{1}{|A|}A^* Mn=(A1)TA1=A1A

法线变化只需要计算左上3x3的部分

Special Matrix Transforms and Operations

x-pitch, y-head, z-roll

Extracting Parameters from the Euler Transform

$$
E(h, p, r) = \begin{pmatrix}
e_{00} & e_{01} & e_{02} \
e_{10} & e_{11} & e_{12} \
e_{20} & e_{21} & e_{22}
\end{pmatrix} = R_z®R_x§R_y(h)
\ \qquad
\ \qquad
\ = \begin{pmatrix}
cosrcosh-sinrsinpsinh & -sinrcosp & cosrsinh+sinrsinpcosh \
sinr
cosh+cosrsinpsinh & cosrcosp & sinrsinh-cosrsinpcosh \
-cospsinh & sinp & cospcosh
\end{pmatrix}

\\ \qquad
\\ \qquad

\\ sinp = e_{21} \\
\frac{e_{01}}{e_{11}} = \frac{-sinr}{cosr}=-tanr\\
\frac{e_{20}}{e_{22}} = \frac{-sinh}{cosh}=-tanh\\
可以得出:\\
h=atan(-e_{20}, e_{22})\\
p=arcsin(e_{21})\\
r=atan(-e_{01},e_{11})

$$

万向锁:https://blog.youkuaiyun.com/hanjuefu5827/article/details/80659343

Rotation about an Arbitrary Axis

绕任意轴r旋转:

在这里插入图片描述

其中M矩阵:

M=(rTsTtT) M = \begin{pmatrix} r^T \\ s^T \\ t^T \end{pmatrix} M=rTsTtT

绕任意轴旋转矩阵:

X=MTRx(α)M X=M^TR_x(\alpha)M X=MTRx(α)M

Quaternions

定义:

q^=(qv→,qw)=iqx+jqy+kqz+qw=qv→+qwqv→=iqx+jqy+kqz=(qz,qy,qz),i2=j2=k2=−1,jk=−ky=i,ki=−ik=j,ij=−ji=k \hat{q}=(\overrightarrow{q_v}, q_w)=iq_x+jq_y+kq_z+q_w=\overrightarrow{q_v}+q_w \\ \overrightarrow{q_v}=iq_x+jq_y+kq_z=(q_z,q_y,q_z),\\ i^2=j^2=k^2=-1,\\ jk=-ky=i,ki=-ik=j,ij=-ji=k q^=(qv,qw)=iqx+jqy+kqz+qw=qv+qwqv=iqx+jqy+kqz=(qz,qy,qz),i2=j2=k2=1,jk=ky=i,ki=ik=j,ij=ji=k

乘法:

q^r^=(iqx+jqy+kqz+qw)(irx+jry+krz+rw)=i(qyrz−qzry+rwqx+qwrx)+j(qzrx−qxrz+rwqy+qwry)+k(qxry−qyrx+rwqz+qwrz)+qwrw−qxrx−qyry−qzrz‘=(qv→∗rv→+rwqv→+qwrv→, qwrw−qv→∙rv→) \hat{q}\hat{r}=(iq_x+jq_y+kq_z+q_w)(ir_x+jr_y+kr_z+r_w)\\ =i(q_yr_z-q_zr_y+r_wq_x+q_wr_x)+j(q_zr_x-q_xr_z+r_wq_y+q_wr_y)+k(q_xr_y-q_yr_x+r_wq_z+q_wr_z)+q_wr_w-q_xr_x-q_yr_y-q_zr_z\\` =(\overrightarrow{q_v}*\overrightarrow{r_v} + r_w\overrightarrow{q_v}+q_w\overrightarrow{r_v},\ q_wr_w-\overrightarrow{q_v}\bullet \overrightarrow{r_v}) q^r^=(iqx+jqy+kqz+qw)(irx+jry+krz+rw)=i(qyrzqzry+rwqx+qwrx)+j(qzrxqxrz+rwqy+qwry)+k(qxryqyrx+rwqz+qwrz)+qwrwqxrxqyryqzrz=(qvrv+rwqv+qwrv, qwrwqvrv)

共轭(conjugate):

$$
\hat{q}*=(\overrightarrow{q_v},q_w)=(-\overrightarrow{q_v},q_w)\
(\hat{q}*)
=\hat{q}\
(\hat{q}+\hat{r})*=\hat{q}+\hat{r}^\
(\hat{q}\hat{r})*=\hat{r}\hat{q}^

$$

模(norm):

n(q^)=q^∗q^=qv→∙qv→+qw2=qx2+qy2+qz2+qw2n(q^∗)=n(q^)n(q^r^)=n(q^)n(r^) n(\hat{q})=\sqrt{\hat{q}^*\hat{q}}=\sqrt{\overrightarrow{q_v} \bullet \overrightarrow{q_v}+q_w^2}\\ =\sqrt{q_x^2+q_y^2+q_z^2+q_w^2}\\ \\n(\hat{q}^*)=n(\hat{q}) \\n(\hat{q}\hat{r})=n(\hat{q})n(\hat{r}) n(q^)=q^q^=qvqv+qw2=qx2+qy2+qz2+qw2n(q^)=n(q^)n(q^r^)=n(q^)n(r^)

Identity:

i^=(0→,1) \hat{i}=(\overrightarrow{0}, 1) i^=(0,1)

逆:

q^−1=1n(q^)2q^∗ \hat{q}^{-1}=\frac{1}{n(\hat{q})^2}\hat{q}^* q^1=n(q^)21q^

对于单位四元素它的模为1,所以他可以被写成:

q^=(sinϕuq,cosϕ)∣∣uq∣∣=1 \hat{q}=(sin\phi u_q, cos\phi)\\ ||u_q||=1 q^=(sinϕuq,cosϕ)uq=1

根据欧拉公式,也可以写成:

q^=sinϕuq+cosϕ=eϕuqlog(q^)=log(eϕuq)=ϕuqq^t=(sinϕuq+cosϕ)t=eϕtuq=sin(ϕt)uq+cos(ϕt) \hat{q}=sin\phi u_q+cos\phi=e^{\phi u_q}\\ log(\hat{q})=log(e^{\phi u_q})=\phi _uq \hat{q}^t=(sin\phi u_q+cos\phi)^t=e^{\phi tu_q}=sin(\phi t)u_q+cos(\phi t) q^=sinϕuq+cosϕ=eϕuqlog(q^)=log(eϕuq)=ϕuqq^t=(sinϕuq+cosϕ)t=eϕtuq=sin(ϕt)uq+cos(ϕt)

Quaternion Transforms

假定一个点或者是向量p=(px py pz pw)Tp=(p_x \ p_y \ p_z \ p_w)^Tp=(px py pz pw)T,一个单位四元数q^=(sinϕuq,cosϕ)\hat{q}=(sin\phi u_q,cos\phi)q^=(sinϕuq,cosϕ),可以证明q^p^q^−1\hat{q}\hat{p}\hat{q}^{-1}q^p^q^1可以表示为p^\hat{p}p^绕轴uqu_quq旋转2ϕ2\phi2ϕ,由于是单位四元数所以q^−1=q^∗\hat{q}^{-1}=\hat{q}^*q^1=q^

对于任何非零实数诚意q^\hat{q}q^任然表示相同的变换,这意味着q^\hat{q}q^−q^-\hat{q}q^表示相同的旋转。

对于多个旋转,可以通过结合律:

r^(q^p^q^∗)r^∗=(r^q^)p^(q^∗r^∗) \hat{r}(\hat{q}\hat{p}\hat{q}^*)\hat{r}^*=(\hat{r}\hat{q})\hat{p}(\hat{q}^*\hat{r}^*) r^(q^p^q^)r^=(r^q^)p^(q^r^)

Matrix Conversion

Mq=(1−s(qy2+qz2)s(qxqy−qwqz)s(qxqz+qwqy)0s(qxqy+qwqz)1−s(qx2+qz2)s(qyqz−qwqx)0s(qxqz−qwqy)s(qyqz+qwqx)1−s(qx2+qy2)00000) M^q = \begin{pmatrix} 1-s(q_y^2+q_z^2) & s(q_xq_y-q_wq_z) & s(q_xq_z+q_wq_y) & 0 \\ s(q_xq_y+q_wq_z) & 1-s(q_x^2+q_z^2) & s(q_yq_z-q_wq_x) & 0 \\ s(q_xq_z-q_wq_y) & s(q_yq_z+q_wq_x) & 1-s(q_x^2+q_y^2) & 0 \\ 0 & 0 & 0 & 0 \end{pmatrix}\\ Mq=1s(qy2+qz2)s(qxqy+qwqz)s(qxqzqwqy)0s(qxqyqwqz)1s(qx2+qz2)s(qyqz+qwqx)0s(qxqz+qwqy)s(qyqzqwqx)1s(qx2+qy2)00000

其中s=2/(n(q^))2s=2/(n(\hat{q}))^2s=2/(n(q^))2
对于单位四元数,可以简化为

Mq=(1−2(qy2+qz2)2(qxqy−qwqz)2(qxqz+qwqy)02(qxqy+qwqz)1−2(qx2+qz2)2(qyqz−qwqx)02(qxqz−qwqy)2(qyqz+qwqx)1−2(qx2+qy2)00000) M^q = \begin{pmatrix} 1-2(q_y^2+q_z^2) & 2(q_xq_y-q_wq_z) & 2(q_xq_z+q_wq_y) & 0 \\ 2(q_xq_y+q_wq_z) & 1-2(q_x^2+q_z^2) & 2(q_yq_z-q_wq_x) & 0 \\ 2(q_xq_z-q_wq_y) & 2(q_yq_z+q_wq_x) & 1-2(q_x^2+q_y^2) & 0 \\ 0 & 0 & 0 & 0 \end{pmatrix}\\ Mq=12(qy2+qz2)2(qxqy+qwqz)2(qxqzqwqy)02(qxqyqwqz)12(qx2+qz2)2(qyqz+qwqx)02(qxqz+qwqy)2(qyqzqwqx)12(qx2+qy2)00000

球面线性插值

根据q^\hat{q}q^r^\hat{r}r^以及参数t∈[0,1]t\in[0,1]t[0,1]求一个差值四元数

s^(q^,r^,t)=(r^q^−1)tq^ \hat{s}(\hat{q}, \hat{r}, t)=(\hat{r}\hat{q}^{-1})^t\hat{q} s^(q^,r^,t)=(r^q^1)tq^

实际计算中使用

s^(q^,r^,t)=slerp(q^,r^,t)=sin(ϕ(1−t))sinϕq^+sin(ϕt)sinϕr^ \hat{s}(\hat{q}, \hat{r}, t)=slerp(\hat{q}, \hat{r}, t)\\ =\frac{sin(\phi(1-t))}{sin\phi}\hat{q}+\frac{sin(\phi t)}{sin\phi}\hat{r} s^(q^,r^,t)=slerp(q^,r^,t)=sinϕsin(ϕ(1t))q^+sinϕsin(ϕt)r^

其中cosϕ=qxrx+qyry+qzrz+qwrwcos\phi=q_xr_x+q_yr_y+q_zr_z+q_wr_wcosϕ=qxrx+qyry+qzrz+qwrw

将一个向量旋转到另一个向量

将限量sss旋转到向量ttt:首先归一化sssttt,然后计算旋转轴u=(s∗t)/∣∣s∗t∣∣u=(s*t)/||s*t||u=(st)/st,第三设e=s∙t=cos(2ϕ)   ∣∣s∗t∣∣=sin(2ϕ)e=s\bullet t=cos(2\phi) \ \ \ ||s*t||=sin(2\phi)e=st=cos(2ϕ)   st=sin(2ϕ),其中2ϕ2\phi2ϕsssttt的夹角。那么这个四元数可以表示为q^=(sinϕu,cosϕ)\hat{q}=(sin\phi u,cos\phi)q^=(sinϕu,cosϕ),化简可得:

q^=(sinϕsin2ϕ(s∗t),cosϕ)=(qv,qw)=(12(1+e)(s∗t),2(1+e)2) \hat{q}=(\frac{sin\phi}{sin2\phi}(s*t), cos\phi)\\ =(q_v,q_w)=(\frac{1}{\sqrt{2(1+e)}}(s*t),\frac{\sqrt{2(1+e)}}{2}) q^=(sin2ϕsinϕ(st),cosϕ)=(qv,qw)=(2(1+e)1(st),22(1+e))

顶点混合(Vertex Blending)

皮肤表面顶点收到多个骨骼影响,经过动画变换最终位置的基本公式是:

u(t)=∑i=0n−1ωiBi(t)Mi−1p,  where∑i=0n−1=1,  ωi≥0 u(t)=\sum_{i=0}^{n-1}\omega_iB_i(t)M_i^{-1}p,\ \ where \sum_{i=0}^{n-1}=1,\ \ \omega_i\ge 0 u(t)=i=0n1ωiBi(t)Mi1p,  wherei=0n1=1,  ωi0

其中ωi\omega_iωi表示第iii块骨骼对于顶点ppp的影响权重。MiM_iMi表示从骨骼的本地坐标转换到世界坐标的变换矩阵。Bi(t)B_i(t)Bi(t)表示第iii个骨骼随着物体动画的进行所需要的世界变换矩阵,通常来讲是一系列矩阵的结合,比如说是之前各级骨骼的变换以及本地动画矩阵(什么鬼。。。)

每一个骨骼将一个顶点根据每一帧中的索引变换到一个位置,最终的位置是根据一系列计算出的顶点差值得到的。在一些说明中MiM_iMi会作为Bi(t)B_i(t)Bi(t)的一部分,在实际中也是。发现的计算也可以使用上述公式,需要将Bi(t)MiB_i(t)M_iBi(t)Mi替换成逆的转置。

在GPU计算中,mesh顶点会作为静态的缓存一次性发送给GPU,这部分数据可以被GPU反复使用,每次要变化的只有骨骼的矩阵。骨骼变换也可以储存到纹理当中,每一次变换如果使用四元数则只需要两个纹理元素来表示旋转的话。

顶点混合的缺点是会出现一些折叠(folding)、扭曲(twisting)和自相交(self intersection)。解决的方法之一是使用对偶四元数(dual quaternions),它可以很好地避免肢体的糖纸扭曲(candy wrapper twist)

变形(Morphing)

变形效果主要有两个主要问题:顶点对应(vertex correspondence)问题和插值问题。对于两个顶点数量不同,拓扑结构不同,网格连接关系不同的模型进行变形首先要做的就是顶点对应。

如果对于一个顶点能够一一对应的模型,那么就可以进行逐顶点的插值了。对于一个时间点t∈[t0,t1]t\in[t_0,t_1]t[t0,t1],首先计算s=(t−t0)/(t1−t0)s=(t-t_0)/(t_1-t_0)s=(tt0)/(t1t0),然后就可以先行插值了:

m=(1−s)p0+sp1 m=(1-s)p_0+sp_1 m=(1s)p0+sp1

Geometry Cache Playback

Projections

正交投影(Orthographic Projection)

Po=S(s)T(t)=(2r−l00002t−b00002f−n00001)(100−l+r2010−t+b2001−f+n20001)=(2r−l00−r+lr−l02t−b0−t+bt−b002f−n−f+nf−n0001) P_o = S(s)T(t) = \begin{pmatrix} \frac{2}{r-l} & 0 & 0 & 0 \\ 0 & \frac{2}{t-b} & 0 & 0 \\ 0 & 0 & \frac{2}{f-n} & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} 1 & 0 & 0 & -\frac{l+r}{2} \\ 0 & 1 & 0 & -\frac{t+b}{2} \\ 0 & 0 & 1 & -\frac{f+n}{2} \\ 0 & 0 & 0 & 1 \end{pmatrix} \\ = \begin{pmatrix} \frac{2}{r-l} & 0 & 0 & -\frac{r+l}{r-l} \\ 0 & \frac{2}{t-b} & 0 & -\frac{t+b}{t-b} \\ 0 & 0 & \frac{2}{f-n} & -\frac{f+n}{f-n} \\ 0 & 0 & 0 & 1 \end{pmatrix} Po=S(s)T(t)=rl20000tb20000fn2000011000010000102l+r2t+b2f+n1=rl20000tb20000fn20rlr+ltbt+bfnf+n1

示意图如下:

在这里插入图片描述

透视投影(Perspective Projection)

示意图如下:

在这里插入图片描述

p在投影平面上的投影q的坐标为q=(qx,qy,−d)q=(q_x,q_y,-d)q=(qx,qy,d)qxq_xqxqyq_yqy的计算公式如下:

qxpx=−dpz ⇒ qx=−dpxpz \frac{q_x}{p_x}=\frac{-d}{p_z} \ \Rightarrow \ q_x=-d\frac{p_x}{p_z} pxqx=pzd  qx=dpzpx

透视矩阵:
Pp=(10000100001000−1/d0) P_p = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & -1/d & 0 \end{pmatrix} Pp=100001000011/d0000

变换效果如下:

在这里插入图片描述

点p的透视变换

q=Ppp=(10000100001000−1/d0)(pxpypz1)=(pxpypz−pz/d)⇒(−dpx/pz−dpy/pz−d1) q = P_pp = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & -1/d & 0 \end{pmatrix} \begin{pmatrix} p_x \\ p_y \\ p_z \\ 1 \end{pmatrix} =\begin{pmatrix} p_x \\ p_y \\ p_z \\ -p_z/d \end{pmatrix} \Rightarrow \begin{pmatrix} -dp_x/p_z \\ -dp_y/p_z \\ -d \\ 1 \end{pmatrix} q=Ppp=100001000011/d0000pxpypz1=pxpypzpz/ddpx/pzdpy/pzd1

Field of view

ϕ=2arctan(w/(2d)) \phi = 2arctan(w/(2d)) ϕ=2arctan(w/(2d))

其中ϕ\phiϕ表示field of view,www表示垂直于视线的物体的宽度,ddd表示距离物体的距离

透视变换

Pp=(2nr−l0−r+lr−l002nt−b−t+bt−b000f+nf−n−2fnf−n0010) P_p = \begin{pmatrix} \frac{2n}{r-l} & 0 & -\frac{r+l}{r-l} & 0 \\ 0 & \frac{2n}{t-b} & -\frac{t+b}{t-b} & 0 \\ 0 & 0 & \frac{f+n}{f-n} & -\frac{2fn}{f-n} \\ 0 & 0 & 1 & 0 \end{pmatrix} Pp=rl2n0000tb2n00rlr+ltbt+bfnf+n100fn2fn0

对于fff趋近于无穷,也可以写成

Pp=(2nr−l0−r+lr−l002nt−b−t+bt−b0001−2n0010) P_p = \begin{pmatrix} \frac{2n}{r-l} & 0 & -\frac{r+l}{r-l} & 0 \\ 0 & \frac{2n}{t-b} & -\frac{t+b}{t-b} & 0 \\ 0 & 0 & 1 & -2n \\ 0 & 0 & 1 & 0 \end{pmatrix} Pp=rl2n0000tb2n00rlr+ltbt+b11002n0

在OpenGL当中会首先乘以S(1, 1, -1, 1),那么0<n′<f′0<n'<f'0<n<f得到:

Pp=(2n′r−l0−r+lr−l002n′t−b−t+bt−b000−f′+n′f′−n′−2f′n′f′−n′00−10) P_p = \begin{pmatrix} \frac{2n'}{r-l} & 0 & -\frac{r+l}{r-l} & 0 \\ 0 & \frac{2n'}{t-b} & -\frac{t+b}{t-b} & 0 \\ 0 & 0 & -\frac{f'+n'}{f'-n'} & -\frac{2f'n'}{f'-n'} \\ 0 & 0 & -1 & 0 \end{pmatrix} Pp=rl2n0000tb2n00rlr+ltbt+bfnf+n100fn2fn0

根据fov可以化简为:

Pp=(c/a0000c0000−f′+n′f′−n′−2f′n′f′−n′00−10)其中a=w/h,c=1.0/tan(ϕ/2) P_p = \begin{pmatrix} c/a & 0 & 0 & 0 \\ 0 & c & 0 & 0 \\ 0 & 0 & -\frac{f'+n'}{f'-n'} & -\frac{2f'n'}{f'-n'} \\ 0 & 0 & -1 & 0 \end{pmatrix} \\ 其中 a = w / h,c=1.0/tan(\phi/2) Pp=c/a0000c0000fnf+n100fn2fn0a=w/hc=1.0/tan(ϕ/2)

z-buffer的精确度

点p经过透视变换之后可得:

v=Pp=(⋯⋯dpz+e±pz) v=Pp=\begin{pmatrix} \cdots \\ \cdots \\ dp_z+e \\ \pm p_z \end{pmatrix} v=Pp=dpz+e±pz

其中d=−f′+n′f′−n′d=-\frac{f'+n'}{f'-n'}d=fnf+ne=−2f′n′f′−n′e=-\frac{2f'n'}{f'-n'}e=fn2fn,可以得到:

zNDC=dpz+e−pz=d−epz z_{NDC}=\frac{dp_z+e}{-p_z}=d-\frac{e}{p_z} zNDC=pzdpz+e=dpze

变换曲线:

在这里插入图片描述

为了提高深度的精确度,一个常用的方法是翻转z(reversed z),也就是使用1.0−zNDC1.0-z_{NDC}1.0zNDC。几种不同处理的对比如下:

在这里插入图片描述

对于屏幕空间的深度计算,可以使用以下公式进行remapping:

z=w(log2(max(10−6,1+w))fc−1),[OpenGL]z=wlog2(max(10−6,1+w))fc/2,[DX] z=w(log_2(max(10^{-6}, 1+w))f_c-1), \qquad [OpenGL] \\ z=wlog_2(max(10^{-6}, 1+w))f_c/2, \qquad [DX] \\ z=w(log2(max(106,1+w))fc1),[OpenGL]z=wlog2(max(106,1+w))fc/2,[DX]

其中www是顶点经过透视变换之后的www值,zzz是顶点着色器中得到的zzz值,fc=2/log2(f+1)f_c=2/log_2(f+1)fc=2/log2(f+1)

内容概要:本文介绍了一个基于Matlab的综合能源系统优化调度仿真资源,重点实现了含光热电站、有机朗肯循环(ORC)和电含光热电站、有机有机朗肯循环、P2G的综合能源优化调度(Matlab代码实现)转气(P2G)技术的冷、热、电多能互补系统的优化调度模型。该模型充分考虑多种能源形式的协同转换与利用,通过Matlab代码构建系统架构、设定约束条件并求解优化目标,旨在提升综合能源系统的运行效率与经济性,同时兼顾灵活性供需不确定性下的储能优化配置问题。文中还提到了相关仿真技术支持,如YALMIP工具包的应用,适用于复杂能源系统的建模与求解。; 适合人群:具备一定Matlab编程基础和能源系统背景知识的科研人员、研究生及工程技术人员,尤其适合从事综合能源系统、可再生能源利用、电力系统优化等方向的研究者。; 使用场景及目标:①研究含光热、ORC和P2G的多能系统协调调度机制;②开展考虑不确定性的储能优化配置与经济调度仿真;③学习Matlab在能源系统优化中的建模与求解方法,复现高水平论文(如EI期刊)中的算法案例。; 阅读建议:建议读者结合文档提供的网盘资源,下载完整代码和案例文件,按照目录顺序逐步学习,重点关注模型构建逻辑、约束设置与求解器调用方式,并通过修改参数进行仿真实验,加深对综合能源系统优化调度的理解。
这是一篇关于人工智能方向的论文初稿,请帮我完善其中的各个部分。 标题:A Physics-Informed Multi-Modal Fusion Approach for Intelligent Assessment and Life Prediction of Geomembrane Welds in High-Altitude Environments 摘要: The weld seam is the most critical yet vulnerable part of a geomembrane anti-seepage system in high-altitude environments. Traditional assessment methods struggle with inefficiency and an inability to characterize internal defects, while existing prediction models fail to capture the complex degradation mechanisms under multi-field coupling conditions. This study proposes a novel physics-informed deep learning framework for the intelligent assessment and life prediction of geomembrane welds. First, a multi-modal sensing system integrating vision, thermal, and ultrasound is developed to construct a comprehensive weld defect database. Subsequently, a Physics-Informed Attention Fusion Network (PIAF-Net) is proposed, which embeds physical priors (e.g., the oxidation sensitivity of the Heat-Affected Zone) into the attention mechanism to guide the fusion of heterogeneous information, achieving an accuracy of 94.7% in defect identification with limited samples. Furthermore, a Physics-Informed Neural Network with Uncertainty Quantification (PINN-UQ) is established for long-term performance prediction. By hard-constraining the network output with oxidation kinetics and damage evolution equations, and incorporating a Bayesian uncertainty quantification framework, the model provides probabilistic predictions of the remaining service life. Validation results from both laboratory and a case study at the Golmud South Mountain Pumped Storage Power Station (over 3500m altitude) demonstrate the high accuracy (R&sup2; > 0.96), robustness, and physical consistency of the proposed framework, offering a groundbreaking tool for the predictive maintenance of critical infrastructure in extreme environments. 关键词: Geomembrane Weld; Multi-Modal Fusion; Physics-Informed Neural Network; Defect Assessment; Life Prediction; High-Altitude Environment 1. Introduction High-density polyethylene (HDPE) geomembranes are pivotal as impermeable liners in major water conservancy projects, such as pumped storage power stations in high-altitude regions of western China [1, 2]. However, the long-term performance and sealing reliability of the entire system are predominantly determined by the quality of the field welds, which are subjected to extreme environmental stresses including low temperature, intense ultraviolet (UV) radiation, significant diurnal temperature cycles, and strong windblown sand [3, 4]. Statistics indicate that over 80% of geomembrane system failures originate from weld seams [5], highlighting them as the primary薄弱环节 (weak link). Current non-destructive evaluation (NDE) methods, such as air pressure testing and spark testing, are largely qualitative, inefficient, and incapable of identifying internal flaws like incomplete fusion [6, 7]. While some researchers have begun exploring machine learning and deep learning for automated defect recognition [8, 9], these data-driven approaches often suffer from two fundamental limitations: (1) a lack of physical interpretability, making their predictions untrustworthy for high-stakes engineering decisions, and (2) poor generalization performance under "small-sample" conditions typical of specialized weld defects [10]. For long-term performance prediction, the classical Arrhenius model remains the most common tool but is primarily suited for homogeneous materials under constant, single-factor thermal aging [11, 12]. It fails to account for the significant microstructural heterogeneity, residual stresses, and the synergistic effects of multi-field coupling inherent in weld seams under real-world high-altitude service conditions [13, 14]. Pure data-driven models like Gaussian Process Regression (GPR) or standard Neural Networks (NNs), while flexible, often exhibit high extrapolation risks and lack physical consistency [15]. To bridge these gaps, this study introduces a physics-informed deep learning framework that seamlessly integrates physical knowledge with data-driven models. The main contributions are threefold: We propose a Physics-Informed Attention Fusion Network (PIAF-Net) that leverages physical priors derived from material aging mechanisms to guide the fusion of multi-modal NDE data, significantly enhancing defect identification accuracy and interpretability under small-sample constraints. We develop a Physics-Informed Neural Network with Uncertainty Quantification (PINN-UQ) for life prediction, which embds oxidation kinetics and damage mechanics laws directly into the loss function, ensuring physical plausibility while providing probabilistic life predictions through a Bayesian framework. We validate the proposed framework rigorously through independent laboratory tests and a real-world engineering case study at a high-altitude pumped storage power station, demonstrating its superior performance, robustness, and practical engineering value. 2. Methodology The overall framework of the proposed methodology is illustrated in Fig. 1, comprising three main stages: multi-modal data acquisition, intelligent defect assessment, and physics-informed life prediction. 2.1 Multi-Modal Data Acquisition and Database Construction A synchronized multi-sensor data acquisition system was developed, comprising: Vision Module: A 5-megapixel CCD camera with uniform LED lighting to capture high-resolution surface images. Features like Local Binary Patterns (LBP), Histogram of Oriented Gradients (HOG), and morphological parameters (weld width uniformity, edge straightness) were extracted. Thermal Module: A mid-wave infrared thermal camera (100 Hz) recorded the dynamic temperature field during the natural cooling of the weld. Key features included cooling rate and temperature distribution uniformity. Ultrasound Module: A high-frequency ultrasonic probe using pulse-echo mode acquired A-scan signals. Features such as sound velocity, attenuation coefficient, and spectral centroid were derived to characterize internal fusion status. A comprehensive weld defect database was constructed, containing 600 samples covering various process defects (virtual weld, over-weld, weak weld, contamination) and aging states (0h, 500h, 1500h of accelerated multi-field coupling aging). 2.2 Physics-Informed Attention Fusion Network (PIAF-Net) for Defect Assessment The architecture of PIAF-Net is shown in Fig. 2. It consists of a dual-stream feature extraction module and a novel physics-informed attention fusion module. *2.2.1 Dual-Stream Feature Extraction* One stream processes appearance information (visual + thermal features) using a pre-trained CNN (e.g., VGG16) and a custom 3D CNN, respectively. The other stream processes internal information (ultrasonic features) using a 1D CNN. This separation allows for dedicated feature abstraction from different physical domains. *2.2.2 Physics-Informed Attention Fusion Module* Instead of learning attention weights purely from data, this module incorporates physical priors p p (e.g., known correlations between ultrasonic signal attenuation and internal lack of fusion, or between abnormal cooling rates and over-weld-induced grain coarsening). The attention weight a i a i ​ for the i i-th modality is computed as: a i = softmax ( ( W p ⋅ p ) ⊙ ( W f ⋅ f i ) ) a i ​ =softmax((W p ​ ⋅p)⊙(W f ​ ⋅f i ​ )) where f i f i ​ is the feature vector, W p W p ​ and W f W f ​ are learnable projection matrices, and ⊙ ⊙ denotes element-wise multiplication. This design forces the model to focus on feature combinations that are physically meaningful. *2.2.3 Meta-Learning for Small-Sample Training* To address the limited defect samples, a Model-Agnostic Meta-Learning (MAML) paradigm was adopted. The model is trained on a multitude of N-way K-shot tasks, enabling it to rapidly adapt to new, unseen defect types with very few examples. 2.3 Physics-Informed Neural Network with Uncertainty Quantification (PINN-UQ) for Life Prediction The PINN-UQ model integrates physical laws governing weld degradation, as summarized from accelerated aging tests (see Fig. 3 for the conceptual physical model). 2.3.1 Physical Mechanism Module The degradation is modeled through a coupled chemical and mechanical process: Non-Homogeneous Oxidation Kinetics: d α d t = A ⋅ f ( C I 0 , T weld ) ⋅ exp ⁡ ( − E a R T ) ⋅ ( 1 − α ) n ⋅ g ( I U V ) dt dα ​ =A⋅f(CI 0 ​ ,T weld ​ )⋅exp(− RT E a ​ ​ )⋅(1−α) n ⋅g(I UV ​ ) where α α is the aging degree, f ( C I 0 , T weld ) f(CI 0 ​ ,T weld ​ ) is a spatial function accounting for initial antioxidant depletion in the Heat-Affected Zone (HAZ), and g ( I U V ) g(I UV ​ ) is the UV intensity function. Damage Evolution Model: d D d t = C 1 ⋅ ( σ eff σ 0 ) m ⋅ N f + C 2 ⋅ ( Abrasion ) dt dD ​ =C 1 ​ ⋅( σ 0 ​ σ eff ​ ​ ) m ⋅N f ​ +C 2 ​ ⋅(Abrasion) where D D is the damage variable, σ eff σ eff ​ is the equivalent thermal stress from temperature cycles, and N f N f ​ is the cycle count. Macroscopic Performance Coupling: P = P 0 ⋅ ( 1 − α ) β ⋅ ( 1 − D ) γ P=P 0 ​ ⋅(1−α) β ⋅(1−D) γ where P P is a macroscopic property (e.g., tensile strength), and β , γ β,γ are coupling coefficients. *2.3.2 PINN-UQ Architecture and Hybrid Loss Function* The network input is the multi-modal feature sequence X fusion ( t ) X fusion ​ (t) and environmental stress data. Crucially, the network's final layer outputs the physical state variables α α and D D, not the performance P P directly. The predicted performance P pred P pred ​ is then calculated using the physical equation above, enforcing physical consistency. The hybrid loss function is defined as: L total = L data + λ ⋅ L physics L total ​ =L data ​ +λ⋅L physics ​ L data = 1 N ∑ i = 1 N ( P pred , i − P meas , i ) 2 L data ​ = N 1 ​ i=1 ∑ N ​ (P pred,i ​ −P meas,i ​ ) 2 L physics = 1 N ∑ i = 1 N [ ( d α d t − R α ) 2 + ( d D d t − R D ) 2 ] L physics ​ = N 1 ​ i=1 ∑ N ​ [( dt dα ​ −R α ​ ) 2 +( dt dD ​ −R D ​ ) 2 ] where R α R α ​ and R D R D ​ are the right-hand sides of the oxidation and damage evolution equations, computed via automatic differentiation. 2.3.3 Uncertainty Quantification Framework A Bayesian Neural Network (BNN) with Monte Carlo (MC) Dropout is employed to quantify both epistemic (model) and aleatoric (data) uncertainties. The predictive distribution is obtained by performing M M stochastic forward passes, providing the mean prediction and its confidence interval. 3. Results and Discussion 3.1 Performance of PIAF-Net for Defect Assessment The performance of PIAF-Net was evaluated using 5-fold cross-validation and compared against baseline models on the same dataset (Table 1). Table 1. Performance comparison of different models for weld defect identification (Mean ± Std). Model Accuracy (%) Precision (%) Recall (%) F1-Score Vision Only (CNN) 85.3 ± 1.5 84.1 ± 2.1 83.7 ± 1.8 0.839 Thermal Only (3D-CNN) 80.2 ± 2.1 79.5 ± 2.8 78.9 ± 2.5 0.792 Simple Feature Concatenation 90.5 ± 1.2 89.8 ± 1.5 89.4 ± 1.7 0.896 PIAF-Net (Proposed) 95.8 ± 0.8 95.2 ± 1.0 94.9 ± 1.1 0.951 PIAF-Net significantly outperformed all single-modality and simple fusion models, demonstrating the effectiveness of physics-guided attention. The t-SNE visualization (Fig. 4a) showed clear clustering of different defect types in the learned feature space, with samples of the same defect type forming continuous trajectories reflecting severity, indicating the model captured physically meaningful representations. 3.2 Performance and Analysis of PINN-UQ for Life Prediction The PINN-UQ model was trained on data from multi-field coupled aging tests and tested on an independent validation set. Fig. 4b shows the model's prediction of tensile strength degradation under full coupling conditions, alongside the 95% confidence interval. The prediction mean (red line) closely matches the experimental measurements (black dots), with a high R&sup2; value of 0.963 and a low RMSE of 1.18 MPa. The 95% confidence interval (blue shaded area) effectively encapsulates the dispersion of the experimental data, especially during the accelerated degradation phase after 1500 hours, quantitatively reflecting prediction uncertainty. Analysis of the internally predicted physical variables α α and D D revealed that the aging degree in the HAZ evolved much faster than in the parent material, aligning perfectly with micro-FTIR observations from our mechanistic studies (Chapter 2 of the thesis). This emergent behavior, enforced by the physical constraints, confirms the model's physical consistency. 3.3 Engineering Application and Validation The framework was applied to assess welds that had been in service for 3 years at the Golmud South Mountain Pumped Storage Power Station. PIAF-Net successfully identified two welds with "weak weld" characteristics from 15 in-situ inspections, which were later confirmed by destructive tests to have substandard peel strength. For life prediction, the PINN-UQ model, taking the field-derived features and local environmental spectrum as input, predicted a mean remaining service life of 42 years with a 95% confidence interval of [35, 51] years for the welds. The model also identified the HAZ as the life-limiting factor, providing critical guidance for targeted maintenance. 4. Discussion The superior performance of the proposed framework stems from its deep integration of physical knowledge. In PIAF-Net, the physical priors act as an expert guide, steering the model away from spurious correlations and towards physically plausible feature interactions, which is crucial for generalization with small samples. In PINN-UQ, the physical laws serve as a powerful regularizer, constraining the solution space to physically admissible trajectories. This not only improves extrapolation but also imbues the model with a degree of interpretability often missing in pure "black-box" models. The probabilistic output provided by the UQ framework is of paramount practical importance. It transforms a single-point life estimate into a risk-informed decision support tool, allowing engineers to plan maintenance based on conservative lower-bound estimates (e.g., 35 years) or to assess the probability of failure within a design lifetime. 5. Conclusion This study has developed and validated a novel physics-informed deep learning framework for the intelligent assessment and life prediction of geomembrane welds in high-altitude environments. The main conclusions are: The proposed PIAF-Net model, by embedding physical priors into the attention mechanism, achieves high-accuracy (95.8%), interpretable defect identification with limited labeled data, overcoming the limitations of traditional methods and pure data-driven models. The PINN-UQ model successfully integrates the physics of weld degradation into a data-driven framework, providing accurate (R&sup2; > 0.96), physically consistent, and probabilistic predictions of long-term performance and remaining service life. The successful application in a real-world high-altitude engineering case demonstrates the framework's robustness and practical value, paving the way for a paradigm shift from experience-based and reactive maintenance towards model-guided and predictive management of critical infrastructure. Acknowledgments (This section will be completed as needed) References [1] Koerner, R. M., & Koerner, G. R. (2018). Journal of Geotechnical and Geoenvironmental Engineering, 144(6), 04018029. [2] Rowe, R. K. (2020). Geotextiles and Geomembranes, 48(4), 431-446. [3] ... (Other references will be meticulously added from the thesis and relevant literature)
11-29
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值