坐标系变换矩阵推导 | 您所在的位置:网站首页 › 位移法公式的推导过程怎么写 › 坐标系变换矩阵推导 |
坐标系的变换矩阵推导
1.平移变换
假设存在点(x,y,z),将x移动a,y移动b,z移动c,到新的点 ( x ′ , y ′ , z ′ ) (x^{'},y^{'},z^{'}) (x′,y′,z′),则: x ′ = x + a x^{'}=x+a x′=x+a y ′ = y + b y^{'}=y+b y′=y+b z ′ = y + c z^{'}=y+c z′=y+c 写成矩阵形式: [ x ′ y ′ z ′ 1 ] = [ 1 0 0 a 0 1 0 b 0 0 1 c 0 0 0 1 ] [ x y z 1 ] \left[\begin{matrix}x^{'}\\y^{'}\\z^{'}\\1 \end{matrix}\right]= \left[\begin{matrix}1&0&0&a\\0&1&0&b\\0&0&1&c\\0&0&0&1 \end{matrix}\right] \left[\begin{matrix}x\\y\\z\\1 \end{matrix}\right] ⎣⎢⎢⎡x′y′z′1⎦⎥⎥⎤=⎣⎢⎢⎡100001000010abc1⎦⎥⎥⎤⎣⎢⎢⎡xyz1⎦⎥⎥⎤ 中间4x4的矩阵叫变换矩阵。可见,如果要平移坐标,要将坐标维度增加1,变成齐次坐标(齐次坐标(homogeneous coordinates)就是将一个原本是n维的向量用一个n+1维向量来表示,常用于投影几何)。 在计算机图形学中,为了实现平移、旋转、缩放等图像操作,需要用到齐次坐标。 例1:世界坐标系wor相对相机坐标系cam的x、y、z分别平移了10,20,30,求次变换齐次矩阵。 [ x ′ y ′ z ′ 1 ] = [ 1 0 0 10 0 1 0 0 0 0 1 0 0 0 0 1 ] × [ 1 0 0 0 0 1 0 20 0 0 1 0 0 0 0 1 ] × [ 1 0 0 0 0 1 0 0 0 0 1 30 0 0 0 1 ] × [ x y z 1 ] = [ 1 0 0 10 0 1 0 20 0 0 1 30 0 0 0 1 ] × [ x y z 1 ] \left[\begin{matrix}x^{'}\\y^{'}\\z^{'}\\1 \end{matrix}\right]=\left[\begin{matrix}1&0&0&10\\0&1&0&0\\0&0&1&0\\0&0&0&1 \end{matrix}\right] \times \left[\begin{matrix}1&0&0&0\\0&1&0&20\\0&0&1&0\\0&0&0&1 \end{matrix}\right]\times \left[\begin{matrix}1&0&0&0\\0&1&0&0\\0&0&1&30\\0&0&0&1 \end{matrix}\right]\times \left[\begin{matrix}x\\y\\z\\1 \end{matrix}\right]= \left[\begin{matrix}1&0&0&10\\0&1&0&20\\0&0&1&30\\0&0&0&1 \end{matrix}\right]\times \left[\begin{matrix}x\\y\\z\\1 \end{matrix}\right] ⎣⎢⎢⎡x′y′z′1⎦⎥⎥⎤=⎣⎢⎢⎡10000100001010001⎦⎥⎥⎤×⎣⎢⎢⎡10000100001002001⎦⎥⎥⎤×⎣⎢⎢⎡10000100001000301⎦⎥⎥⎤×⎣⎢⎢⎡xyz1⎦⎥⎥⎤=⎣⎢⎢⎡1000010000101020301⎦⎥⎥⎤×⎣⎢⎢⎡xyz1⎦⎥⎥⎤ 三个分量矩阵位置可以交换,因为是独立变量,互不影响。 所以,平移齐次矩阵为: [ 1 0 0 10 0 1 0 20 0 0 1 30 0 0 0 1 ] \left[\begin{matrix}1&0&0&10\\0&1&0&20\\0&0&1&30\\0&0&0&1 \end{matrix}\right] ⎣⎢⎢⎡1000010000101020301⎦⎥⎥⎤ 旋转变换有两种,一种是向量在当前坐标系内的旋转,一种是坐标系的旋转。 2. 坐标系旋转变换:由固定坐标系旋转到另一个坐标系。旋转变换有两种,一种是向量在当前坐标系内的旋转,一种是坐标系的旋转。这里推导坐标系旋转矩阵。 (1) 绕X轴旋转(逆时针) α \alpha α:
写成矩阵形式: [ x ′ y ′ z ′ 1 ] = [ 1 0 0 0 0 c o s α s i n α 0 0 − s i n α c o s α 0 0 0 0 1 ] × [ x y z 1 ] \left[\begin{matrix}x^{'}\\y^{'}\\z^{'}\\1 \end{matrix}\right]= \left[\begin{matrix}1&0&0&0\\0&cos{\alpha}&sin{\alpha}&0\\0&-sin{\alpha}&cos{\alpha}&0\\0&0&0&1 \end{matrix}\right] \times \left[\begin{matrix}x\\y\\z\\1 \end{matrix}\right] ⎣⎢⎢⎡x′y′z′1⎦⎥⎥⎤=⎣⎢⎢⎡10000cosα−sinα00sinαcosα00001⎦⎥⎥⎤×⎣⎢⎢⎡xyz1⎦⎥⎥⎤ (2) 绕Y轴旋转(逆时针) β \beta β:
写成矩阵形式: [ x ′ ′ y ′ ′ z ′ ′ 1 ] = [ c o s β 0 s i n β 0 0 1 0 0 − s i n α 0 c o s β 0 0 0 0 1 ] × [ x ′ y ′ z ′ 1 ] \left[\begin{matrix}x^{''}\\y^{''}\\z^{''}\\1 \end{matrix}\right]= \left[\begin{matrix}cos{\beta}&0&sin{\beta}&0\\0&1&0&0\\-sin{\alpha}&0&cos{\beta}&0\\0&0&0&1 \end{matrix}\right] \times \left[\begin{matrix}x'\\y'\\z'\\1 \end{matrix}\right] ⎣⎢⎢⎡x′′y′′z′′1⎦⎥⎥⎤=⎣⎢⎢⎡cosβ0−sinα00100sinβ0cosβ00001⎦⎥⎥⎤×⎣⎢⎢⎡x′y′z′1⎦⎥⎥⎤ (3)绕Z轴旋转(逆时针) γ \gamma γ:
写成矩阵形式: [ x ′ ′ ′ y ′ ′ ′ z ′ ′ ′ 1 ] = [ c o s γ s i n γ 0 0 − s i n γ c o s γ 0 0 0 0 1 0 0 0 0 1 ] × [ x ′ ′ y ′ ′ z ′ ′ 1 ] \left[\begin{matrix}x^{'''}\\y^{'''}\\z^{'''}\\1 \end{matrix}\right]= \left[\begin{matrix}cos{\gamma}&sin{\gamma}&0&0\\-sin{\gamma}&cos{\gamma}&0&0\\0&0&1&0\\0&0&0&1 \end{matrix}\right] \times \left[\begin{matrix}x''\\y''\\z''\\1 \end{matrix}\right] ⎣⎢⎢⎡x′′′y′′′z′′′1⎦⎥⎥⎤=⎣⎢⎢⎡cosγ−sinγ00sinγcosγ0000100001⎦⎥⎥⎤×⎣⎢⎢⎡x′′y′′z′′1⎦⎥⎥⎤ 所以,坐标轴分别依次绕x,y,z轴旋转 α \alpha α, β \beta β, γ \gamma γ的变换矩阵(前后用左乘来连接): R = R z ( γ ) R y ( β ) R x ( α ) = [ c o s γ s i n γ 0 0 − s i n γ c o s γ 0 0 0 0 1 0 0 0 0 1 ] × [ c o s β 0 s i n β 0 0 1 0 0 − s i n α 0 c o s β 0 0 0 0 1 ] × [ 1 0 0 0 0 c o s α s i n α 0 0 − s i n α c o s α 0 0 0 0 1 ] × [ x y z 1 ] R=R_z(\gamma)R_y(\beta)R_x(\alpha)=\left[\begin{matrix}cos{\gamma}&sin{\gamma}&0&0\\-sin{\gamma}&cos{\gamma}&0&0\\0&0&1&0\\0&0&0&1 \end{matrix}\right]\times \left[\begin{matrix}cos{\beta}&0&sin{\beta}&0\\0&1&0&0\\-sin{\alpha}&0&cos{\beta}&0\\0&0&0&1 \end{matrix}\right] \times \left[\begin{matrix}1&0&0&0\\0&cos{\alpha}&sin{\alpha}&0\\0&-sin{\alpha}&cos{\alpha}&0\\0&0&0&1 \end{matrix}\right] \times \left[\begin{matrix}x\\y\\z\\1 \end{matrix}\right] R=Rz(γ)Ry(β)Rx(α)=⎣⎢⎢⎡cosγ−sinγ00sinγcosγ0000100001⎦⎥⎥⎤×⎣⎢⎢⎡cosβ0−sinα00100sinβ0cosβ00001⎦⎥⎥⎤×⎣⎢⎢⎡10000cosα−sinα00sinαcosα00001⎦⎥⎥⎤×⎣⎢⎢⎡xyz1⎦⎥⎥⎤ |
CopyRight 2018-2019 实验室设备网 版权所有 |