主要是基变换与坐标变换。
先不考虑坐标平移(仿射)的情况,只考虑坐标系旋转(0点不变的情况)。
笛卡尔坐标系是三个轴正交的坐标系,在向量空间里,其实就是维数为3的向量空间的一个基,且3个向量正交且都是单位向量。
假设存在一个基本坐标系(自然基),那么三个轴分别是
\(X_{O}=\begin{bmatrix}1\\0\\0\end{bmatrix}Y_{O}=\begin{bmatrix}0\\1\\0\end{bmatrix}Z_{O}=\begin{bmatrix}0\\0\\1\end{bmatrix}\)
对应的坐标系矩阵为
\(O=\begin{bmatrix}1&0&0\\0&1&0\\0&0&1\end{bmatrix}\)
将坐标系延Z轴旋转45度,对应的三个轴变为
\(X_{A}=\begin{bmatrix}\frac{\sqrt{2}}{2}\\\frac{\sqrt{2}}{2}\\0\end{bmatrix}Y_{A}=\begin{bmatrix}-\frac{\sqrt{2}}{2}\\\frac{\sqrt{2}}{2}\\0\end{bmatrix}Z_{A}=\begin{bmatrix}0\\0\\1\end{bmatrix}\)
得到坐标系
\(A=\begin{bmatrix}\frac{\sqrt{2}}{2}&-\frac{\sqrt{2}}{2}&0\\\frac{\sqrt{2}}{2}&\frac{\sqrt{2}}{2}&0\\0&0&1\end{bmatrix}\)
将坐标系延Y轴旋转90度,对应的三个轴变为
\(X_{B}=\begin{bmatrix}0\\0\\-1\end{bmatrix}Y_{B}=\begin{bmatrix}0\\1\\0\end{bmatrix}Z_{B}=\begin{bmatrix}1\\0\\0\end{bmatrix}\)
得到坐标系
\(B=\begin{bmatrix}0&0&1\\0&1&0\\-1&0&0\end{bmatrix}\)
在C#里用Math.Net实现
DenseMatrix O = DenseMatrix.OfArray(new double[,] { {1,0,0 }, {0,1,0 }, {0,0,1 } }); double SqrtTwo = Math.Sqrt(2) / 2.0; DenseMatrix A = DenseMatrix.OfArray(new double[,] { {SqrtTwo,-SqrtTwo,0 }, {SqrtTwo,SqrtTwo,0 }, {0,0,1 } }); DenseMatrix B = DenseMatrix.OfArray(new double[,] { {0,0,-1 }, {0,1,0 }, {1,0,0 } });
定义一个点(向量),即整个向量空间集合里的一个元素,这个点P在基本坐标系下的坐标值为\(\left(1,1,0\right)\),即存在一组常数
\[\begin{cases}\lambda_{O1}=1\\ \lambda_{O2}=1\\ \lambda_{O3}=0\end{cases}\]
满足
\(\begin{align*}P&=\lambda_{O1}X_{O}+\lambda_{O2}Y_{O}+\lambda_{O3}Z_{O}\\&=1*\begin{bmatrix}1\\0\\0\end{bmatrix}+1*\begin{bmatrix}0\\1\\0\end{bmatrix}+0*\begin{bmatrix}0\\0\\1\end{bmatrix}\end{align*}\)
这几个变量满足关系
\[OP=AP_{A}=BP_{B}\]
那么P在A和B基上的坐标为:
\[P_{A}=A^{-1}P=\begin{bmatrix}\sqrt{2}\\0\\0\end{bmatrix}\]
\[P_{B}=B^{-1}P=\begin{bmatrix}0\\1\\1\end{bmatrix}\]
代码实现
DenseVector P = DenseVector.OfArray(new double[] { 1, 1, 0 }); DenseVector PA = A.Inverse() * P as DenseVector; DenseVector PB = B.Inverse() * P as DenseVector; Debug.WriteLine(PA); DenseVector 3-Double 1.41421 0 0 Debug.WriteLine(PB); DenseVector 3-Double 0 1 1
过渡矩阵
\(B=AA^{-1}B\)
另\(Q=A^{-1}B\)
则\(B=AQ\)
过渡矩阵(基变换),实际是上两个坐标系之间的变化关系。
又因为
\[AP_{A}=BP_{B}\]
所以\[P_{A}=A^{-1}BP_{B}\]
\[P_{A}=QP_{B}\]
或
\[P_{B}=Q^{-1}P_{A}\]
值得注意的是过渡矩阵在坐标系变换和坐标变换起的作用是相反的。这也好理解,一个是坐标系转,一个是点在转,所以方向是相反的。