坐标变换(二维、三维)

一、四种空间

1.1 定义和对比

  • 标量空间:只有标量;
  • 向量空间(Vector space):除了标量,还有向量;
  • 仿射空间(Affine space):除了标量、向量,还有点。向量空间没有位置的概念,所以不能表述几何物体,因此需要用到仿射空间;(对应齐次坐标系)
  • 欧几里得空间(Euclidean space):除了标量、向量,还有距离。仿射空间定义了点,包含了构建几何模型的必要元素,但是仿射空间没有定义长度的概念,欧几里得空间引入了这个概念。(对应欧几里得坐标系)
    在这里插入图片描述

1.2 齐次坐标系

若在三维空间中有一个向量表示为 v = ( a , b , c ) v=(a, b, c) v=(a,b,c),即 v = a i + b j + c z v=ai+bj+cz v=ai+bj+cz,那么表示为在三维仿射空间中的一个数学对象 o b j e c t = a i + b j + c z + d O object=ai+bj+cz+dO object=ai+bj+cz+dO。当 d=0 时,object 就是一个向量;当 d≠0 时,object 就是一个向量加上一个点,也就是一个点。因此,在齐次坐标系下,既可以表示向量,又可以表示点。在齐次坐标系中,向量的坐标形式为 v = ( x , y , z , 0 ) v=(x, y, z, 0) v=(x,y,z,0)用以表示 v = a i + b j + c z v=ai+bj+cz v=ai+bj+cz;点的坐标形式为 P = ( a , b , c , d ) P=(a, b, c, d) P=(a,b,c,d)用以表示 v = ( a / d ) i + ( b / d ) j + ( c / d ) z + O v=(a/d)i+(b/d)j+(c/d)z+O v=(a/d)i+(b/d)j+(c/d)z+O。也就是说,在三维空间中可以认为 ( x , y , z ) (x, y, z) (x,y,z)是点,也可以认为是向量,

齐次坐标:使用 N+1 维坐标来表示 N 维坐标。齐次坐标具有规模不变性,同一点可以被无数个齐次坐标表达 ( X , Y , 1 ) → ( a x , a y , a ) (X, Y, 1)\rightarrow(ax, ay, a) (X,Y,1)(ax,ay,a)齐次坐标转化为笛卡尔坐标可以通过同除最后一项得到。在计算机图形学中,为了统一将平移、旋转、缩放等用矩阵表示,需要引入齐次坐标。比如使用 2 ∗ 2 2*2 22的矩阵没有办法描述平移操作,需要引入 3 ∗ 3 3*3 33的矩阵,才能统一描述二维中的平移、旋转、缩放等操作。同理,必须使用 4 ∗ 4 4*4 44的矩阵才能描述三维变换。

二、刚性变换

2.1 定义

只有平移和旋转,物体的形状不发生改变的变换。

2.2 平移

假如三维空间中存在点 (x, y),分别对 x 和 y 向右移动 a, b 的单位长度,那么变换后为:
x ′ = x − a y ′ = y − b x'=x-a\\y'=y-b x=xay=yb
表示为矩阵形式有:
[ x ′ y ′ 1 ] = [ 1 0 − a 0 1 − b 0   0 1 ] = [ x y 1 ] \left [ \begin{matrix} x' \\ y' \\ 1 \end{matrix} \right]=\left[\begin{matrix} 1\quad 0\quad -a \\ 0\quad 1\quad -b \\ 0 \,\quad 0\quad\quad1 \end{matrix}\right]=\left[\begin{matrix}x\\y\\1\end{matrix}\right] xy1 = 10a01b001 = xy1
为了使用矩阵表示平移变换,需要将坐标的维度增加一维,因为二维的矩阵无法表示二维空间的平移变换,这就叫做齐次坐标。

三维空间:(x, y, z, 1) 经过平移变换后变成 (x+a, y+b, z+c, 1),写成矩阵的形式为:
[ 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\quad0\quad0\quad a\\ 0\quad1\quad0\quad b\\ 0\quad0\quad1\quad c\\0\quad0\quad0\quad1\end{matrix}\right]\left[\begin{matrix}x\\y\\z\\1\end{matrix}\right] xyz1 = 100a010b001c0001 xyz1

2.3 旋转

二维旋转是围绕一个点进行旋转,三维旋转是围绕一个轴进行旋转。

一文读懂图像中点的坐标变换(刚体变换,相似变换,仿射变换,投影变换)

Python 3D坐标系下的点的转换矩阵(平移、缩放、旋转、错切)

2.3.1 二维

2.3.1.1 绕原点

在这里插入图片描述

向量 v 绕原点旋转至 v’,那么旋转前后坐标可分别表示为:
在这里插入图片描述
即:
{ x ′ = r c o s ϕ c o s θ − r s i n ϕ s i n θ = x c o s θ − y s i n θ y ′ = r s i n ϕ c o s θ + r c o s ϕ s i n θ = y c o s θ + x s i n θ \begin{cases} x'=rcos\phi cos\theta-rsin\phi sin\theta=xcos\theta-ysin\theta \notag\\ y'=rsin\phi cos\theta +rcos\phi sin\theta=ycos\theta+xsin\theta\notag \end{cases} {x=rcosϕcosθrsinϕsinθ=xcosθysinθy=rsinϕcosθ+rcosϕsinθ=ycosθ+xsinθ

矩阵形式为:
[ x ′ y ′ ] = [ c o s θ     − s i n θ s i n θ     c o s θ ] = [ x y ] \left [ \begin{matrix} x' \\ y' \end{matrix} \right]=\left[\begin{matrix} cos\theta\,\,\,-sin\theta\\ sin\theta\,\,\,\quad cos\theta\\ \end{matrix}\right]=\left[\begin{matrix}x\\y\end{matrix}\right] [xy]=[cosθsinθsinθcosθ]=[xy]

2.3.1.2 绕任意点

绕任意点旋转可以转换为绕原点的旋转,处理思路:①首先将旋转点移动到原点处;②执行绕原点旋转;③再将旋转点移回到原来位置。也就是说,绕任意点的旋转可以处理为:平移+绕原点旋转+平移。因此,绕任意点旋转的旋转矩阵为:
M = [ 1 0 t x 0 1 t y 0 0    1 ] [ c o s θ − s i n θ 0 s i n θ c o s θ 0 0       0       1 ] [ 1 0 − t x 0 1 − t y 0 0     1 ] = [ c o s θ − s i n θ ( 1 − c o s θ ) t x + t y s i n θ s i n θ c o s θ ( 1 − c o s θ ) t y − t x s i n θ 0 0 1 ] \begin{align}M&=\left[\begin{matrix} 1\quad0\quad t_x\\ 0\quad1\quad t_y\\ 0\quad 0 \quad\,\, 1 \end{matrix}\right]\left[\begin{matrix} cos\theta\quad-sin\theta\quad 0\\ sin\theta\qquad cos\theta\quad 0\\ 0\qquad\,\,\,\,\, 0 \qquad\,\,\,\,\, 1 \end{matrix}\right] \left[\begin{matrix} 1\quad0\quad -t_x\\ 0\quad1\quad -t_y\\ 0\quad 0 \qquad\,\,\, 1 \end{matrix}\right]\notag\\ &\notag\\ &=\left[\begin{matrix} cos\theta\quad-sin\theta\quad (1-cos\theta)t_x+t_ysin\theta\\ sin\theta\qquad cos\theta\quad (1-cos\theta)t_y-t_xsin\theta\\ 0\qquad\qquad\qquad 0 \qquad\qquad\qquad 1 \end{matrix}\right] \notag\end{align} M= 10tx01ty001 cosθsinθ0sinθcosθ0001 10tx01ty001 = cosθsinθ(1cosθ)tx+tysinθsinθcosθ(1cosθ)tytxsinθ001
在这里插入图片描述

2.3.2 三维

绕那个轴旋转,哪个轴的坐标值不变。(注意:坐标顺序要符合右手坐标系!!!x-front,y-right,z-up)
在这里插入图片描述

3维旋转矩阵推导与助记

2.3.2.1 绕x轴

绕x轴旋转,旋转前后x的坐标值不变,三维旋转可理解为 zOy 平面上的向量绕原点 O 旋转,因此旋转过程为:
{ x ′ = x y ′ = y c o s β − z s i n β z ′ = z c o s β + y s i n β \left \{\begin{equation}\begin{aligned} &x'=x\notag\\ &y'=ycos\beta-zsin\beta \notag \\ &z'=zcos\beta+ysin\beta\notag\\ \end{aligned}\end{equation}\right . x=xy=ycosβzsinβz=zcosβ+ysinβ
矩阵形式为:
[ x ′ y ′ z ′ ] = [ 1 0 0 0 c o s β − s i n β 0 s i n β c o s β ] [ x y z ] \left[\begin{matrix}x'\\y'\\z'\end{matrix}\right]= \left[\begin{matrix} &1\quad &0\quad &0\\ &0\quad &cos\beta\quad &-sin\beta\\ &0\quad &sin\beta\quad &cos\beta\\ \end{matrix}\right] \left[\begin{matrix}x\\y\\z\end{matrix}\right] xyz = 1000cosβsinβ0sinβcosβ xyz

2.3.2.2 绕y轴

绕y轴旋转,旋转前后y的坐标值不变,三维旋转可理解为 xOz 平面上的向量绕原点 O 旋转,旋转过程为:
{ x ′ = x c o s β + z s i n β y ′ = y z ′ = z c o s β − x s i n β \left \{\begin{equation}\begin{aligned} &x'=xcos\beta+zsin\beta \notag\\ &y'=y\notag \\ &z'=zcos\beta-xsin\beta \notag\\ \end{aligned}\end{equation}\right . x=xcosβ+zsinβy=yz=zcosβxsinβ
矩阵形式为:
[ x ′ y ′ z ′ ] = [ c o s β 0 s i n β 0 1 0 − s i n β 0 c o s β ] [ x y z ] \left[\begin{matrix}x'\\y'\\z'\end{matrix}\right]= \left[\begin{matrix} &cos\beta\quad &0\quad &sin\beta\\ &0\quad &1\quad &0\\ &-sin\beta\quad &0\quad &cos\beta\\ \end{matrix}\right] \left[\begin{matrix}x\\y\\z\end{matrix}\right] xyz = cosβ0sinβ010sinβ0cosβ xyz

2.3.2.3 绕z轴

绕z轴旋转,旋转前后z的坐标值不变,三维旋转可理解为 yOx 平面上的向量绕原点 O 旋转,旋转过程为:
{ x ′ = x c o s β − y s i n β y ′ = y c o s β + x s i n β z ′ = z \left \{\begin{equation}\begin{aligned} &x'=xcos\beta-ysin\beta\notag\\ &y'=ycos\beta+xsin\beta\notag \\ &z'=z\notag\\ \end{aligned}\end{equation}\right . x=xcosβysinβy=ycosβ+xsinβz=z
矩阵形式为:
[ x ′ y ′ z ′ ] = [ c o s β − s i n β 0 s i n β c o s β 0 0 0 1 ] [ x y z ] \left[\begin{matrix}x'\\y'\\z'\end{matrix}\right]= \left[\begin{matrix} &cos\beta\quad &-sin\beta\quad &0\\ &sin\beta\quad &cos\beta\quad &0\\ &0\quad &0\quad &1\\ \end{matrix}\right] \left[\begin{matrix}x\\y\\z\end{matrix}\right] xyz = cosβsinβ0sinβcosβ0001 xyz

 
(本文完整的pdf请关注公众号“张张学算法”,并回复“020”获取~)
 

  • 15
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Satisfying

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

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

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

打赏作者

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

抵扣说明:

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

余额充值