二维(三维)坐标系中旋转矩阵详细推导

news/2025/3/5 3:00:18/

求三维坐标系的旋转矩阵通常需要求分别沿3个坐标轴的二维坐标系下的旋转矩阵,二维坐标系下的旋转矩阵的推导过程通常以某一点逆时针旋转 θ \theta θ角度进行推理。以下将通过此例来详细讲解二维坐标系下的旋转矩阵推导过程,并进一步给出其他方式的旋转矩阵。

一、二维坐标中点的旋转变换

点的旋转矩阵(逆时针旋转)

已知点 P ( x , y ) P(x, y) P(x,y),将该点以逆时针方向旋转 θ \theta θ角度后得到点 P ′ ( x ′ , y ′ ) P^{\prime}(x^{\prime}, y^{\prime}) P(x,y),如下图所示。求由点 P P P到点 P ′ P^{\prime} P的旋转矩阵。
请添加图片描述

  • 设半径为 r r r,由图可以分别得到以下三角公式:

    • 对于点 P ( x , y ) P(x, y) P(x,y)
      x = r cos ⁡ α y = r sin ⁡ α (1) \begin{aligned} & x=r \cos \alpha \\ & y=r \sin \alpha \end{aligned} \tag{1} x=rcosαy=rsinα(1)
    • 对于点 P ′ ( x ′ , y ′ ) P^{\prime}(x^{\prime}, y^{\prime}) P(x,y)
      x ′ = r cos ⁡ ( α + θ ) y ′ = r sin ⁡ ( α + θ ) (2) \begin{aligned} & x^{\prime}=r \cos (\alpha+\theta) \\ & y^{\prime}=r \sin (\alpha+\theta) \end{aligned} \tag{2} x=rcos(α+θ)y=rsin(α+θ)(2)
  • 根据两角和的正弦与余弦公式:
    sin ⁡ ( α + θ ) = sin ⁡ α cos ⁡ θ + cos ⁡ α sin ⁡ θ cos ⁡ ( α + θ ) = cos ⁡ α cos ⁡ θ − sin ⁡ α sin ⁡ θ (3) \begin{aligned} & \sin (\alpha+\theta)=\sin \alpha \cos \theta+\cos \alpha \sin \theta \\ & \cos (\alpha+\theta)=\cos \alpha \cos \theta-\sin \alpha \sin \theta \end{aligned} \tag{3} sin(α+θ)=sinαcosθ+cosαsinθcos(α+θ)=cosαcosθsinαsinθ(3)

  • 将公式(3)代入公式(2),可得到:
    x ′ = r cos ⁡ α cos ⁡ θ − r sin ⁡ α sin ⁡ θ y ′ = r sin ⁡ α cos ⁡ θ + r cos ⁡ α sin ⁡ θ (4) \begin{aligned} & x^{\prime} =r \cos \alpha \cos \theta-r \sin \alpha \sin \theta \\ & y^{\prime} =r \sin \alpha \cos \theta+r \cos \alpha \sin \theta \\ \end{aligned} \tag{4} x=rcosαcosθrsinαsinθy=rsinαcosθ+rcosαsinθ(4)

  • 将公式(1)代入公式(4),化简掉 α \alpha α,可得到 ( x ′ , y ′ ) (x^{\prime}, y^{\prime}) (x,y) ( x , y ) (x, y) (x,y)的关系,即:
    x ′ = x cos ⁡ θ − y sin ⁡ θ y ′ = y cos ⁡ θ + x sin ⁡ θ (5) \begin{aligned} & x^{\prime} =x \cos \theta-y \sin \theta \\ & y^{\prime} =y \cos \theta+x \sin \theta \\ \end{aligned} \tag{5} x=xcosθysinθy=ycosθ+xsinθ(5)

  • 整理公式(5)可得到旋转矩阵公式:
    x ′ = cos ⁡ θ ⋅ x − sin ⁡ θ ⋅ y y ′ = sin ⁡ θ ⋅ x + cos ⁡ θ ⋅ y ⇒ [ x ′ y ′ ] = [ cos ⁡ θ − sin ⁡ θ sin ⁡ θ cos ⁡ θ ] [ x y ] (6) \begin{aligned} x^{\prime}&=\cos \theta \cdot x-\sin \theta \cdot y \\ y^{\prime}&=\sin \theta \cdot x+\cos \theta \cdot y \\ \Rightarrow \left[\begin{array}{l} x^{\prime} \\ y^{\prime}\end{array}\right] &=\left[\begin{array}{cc}\cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{array}\right] \left[\begin{array}{l} x \\ y \end{array}\right] \end{aligned} \tag{6} xy[xy]=cosθxsinθy=sinθx+cosθy=[cosθsinθsinθcosθ][xy](6)

  • 因此二维坐标系下逆时针旋转矩阵 R R R为:
    R = [ cos ⁡ θ − sin ⁡ θ sin ⁡ θ cos ⁡ θ ] R = \left[\begin{array}{cc}\cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{array}\right] R=[cosθsinθsinθcosθ]

点的旋转矩阵(顺时针旋转)

已知点 P ′ ( x ′ , y ′ ) P^{\prime}(x^{\prime}, y^{\prime}) P(x,y),将该点以顺时针方向旋转 θ \theta θ角度后得到点 P ( x , y ) P(x, y) P(x,y),求 P P P

1、利用求逆矩阵的方式

  • 二阶矩阵的逆的求法为:主对角元素换位置,次对角元素变符号,再乘上系数1/(ad-bc),由于旋转矩阵 R R R的ad-bc=1,因此 R R R的逆矩阵 R ′ R^{\prime} R为:
    R ′ = [ cos ⁡ θ sin ⁡ θ − sin ⁡ θ cos ⁡ θ ] R^{\prime} = \left[\begin{array}{cc}\cos \theta & \sin \theta \\ -\sin \theta & \cos \theta \end{array}\right] R=[cosθsinθsinθcosθ]
  • 因此旋转公式为:
    [ x y ] = [ cos ⁡ θ sin ⁡ θ − sin ⁡ θ cos ⁡ θ ] [ x ′ y ′ ] \left[\begin{array}{l} x \\ y \end{array}\right] = \left[\begin{array}{cc}\cos \theta & \sin \theta \\ -\sin \theta & \cos \theta \end{array}\right] \left[\begin{array}{l} x^{\prime} \\ y^{\prime}\end{array}\right] [xy]=[cosθsinθsinθcosθ][xy]

2、利用几何知识推导

P ′ P^{\prime} P顺时针旋转 θ \theta θ角度到 P P P,相当于逆时针旋转 ( 2 π − θ ) (2 \pi-\theta) (2πθ),由于三角函数的周期为 2 π 2 \pi 2π,因此相当于旋转 − θ -\theta θ角度。

  • − θ -\theta θ代入到公式(6),得到:
    x = cos ⁡ ( − θ ) ⋅ x ′ − sin ⁡ ( − θ ) ⋅ y ′ = cos ⁡ θ ⋅ x ′ + sin ⁡ θ ⋅ y ′ y = sin ⁡ ( − θ ) ⋅ x ′ + cos ⁡ ( − θ ) ⋅ y ′ = − sin ⁡ θ ⋅ x ′ + cos ⁡ θ ⋅ y ′ \begin{aligned} x & =\cos (-\theta) \cdot x^{\prime}-\sin (-\theta) \cdot y^{\prime} \\ & =\cos \theta \cdot x^{\prime}+\sin \theta \cdot y^{\prime} \\ y & =\sin (-\theta) \cdot x^{\prime}+\cos (-\theta) \cdot y^{\prime} \\ & =-\sin \theta \cdot x^{\prime}+\cos \theta \cdot y^{\prime} \end{aligned} xy=cos(θ)xsin(θ)y=cosθx+sinθy=sin(θ)x+cos(θ)y=sinθx+cosθy
  • 整理上述公式可得到顺时针时的旋转矩阵公式:
    x = cos ⁡ θ ⋅ x ′ + sin ⁡ θ ⋅ y ′ y = − sin ⁡ θ ⋅ x ′ + cos ⁡ θ ⋅ y ′ ⇒ [ x y ] = [ cos ⁡ θ sin ⁡ θ − sin ⁡ θ cos ⁡ θ ] [ x ′ y ′ ] \begin{aligned} x&=\cos \theta \cdot x^{\prime}+\sin \theta \cdot y^{\prime} \\ y&=-\sin \theta \cdot x^{\prime}+\cos \theta \cdot y^{\prime} \\ \Rightarrow \left[\begin{array}{l} x \\ y \end{array}\right] &= \left[\begin{array}{cc}\cos \theta & \sin \theta \\ -\sin \theta & \cos \theta \end{array}\right] \left[\begin{array}{l} x^{\prime} \\ y^{\prime}\end{array}\right] \end{aligned} xy[xy]=cosθx+sinθy=sinθx+cosθy=[cosθsinθsinθcosθ][xy]

二、二维坐标系的旋转变换

二维坐标系 XOY \text{XOY} XOY中有一点 P ( x , y ) P(x, y) P(x,y),将坐标系 XOY \text{XOY} XOY逆时针旋转 θ \theta θ角度后得到新坐标系 X ′ O ′ Y ′ \text{X}^{\prime}\text{O}^{\prime}\text{Y}^{\prime} XOY,求点 P P P在新坐标系下的坐标 P ′ ( x ′ , y ′ ) P^{\prime}(x^{\prime}, y^{\prime}) P(x,y),这个过程称为坐标系变换。

新坐标的求法可以转换为逆向旋转坐标点的方式,并利用点的旋转变换求得。因此,坐标系时针旋转 θ \theta θ角度,相当于原坐标系中某一点时针旋转 θ \theta θ角度,反之亦然。

总结

  • 某点逆时针旋转 θ \theta θ角度(坐标系顺时针旋转 θ \theta θ角度)的旋转矩阵为:
    R = [ cos ⁡ θ − sin ⁡ θ sin ⁡ θ cos ⁡ θ ] R = \left[\begin{array}{cc}\cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{array}\right] R=[cosθsinθsinθcosθ]
  • 某点顺时针旋转 θ \theta θ角度(坐标系逆时针旋转 θ \theta θ角度)的旋转矩阵为:
    R ′ = [ cos ⁡ θ sin ⁡ θ − sin ⁡ θ cos ⁡ θ ] R^{\prime} = \left[\begin{array}{cc}\cos \theta & \sin \theta \\ -\sin \theta & \cos \theta \end{array}\right] R=[cosθsinθsinθcosθ]
    三维坐标变换可进一步参考Link3。

参考:
Link1
Link2
Link3


http://www.ppmy.cn/news/505818.html

相关文章

directx12三维坐标系转二维坐标系

有时候需要在三维坐标系中绘制二维元素,像文字、表格等,需要使用二维坐标系,DirectX之前都说取图不精,也就是没法在整数位置画出一个对应这个整数坐标的像素,譬如我想在二维屏幕坐标(400,50&…

从世界坐标系到相机坐标系(3D物体到2D图像的转变)

转载:http://blog.sina.com.cn/s/blog_8c388a3a0101dd15.html 〇.各种坐标系及其存在的原因: 要谈坐标系变换,那么坐标系有哪些呢?依次有:物体坐标系,世界坐标系,相机坐标系,投影坐…

3D 坐标系 2D坐标系

二维笛卡儿坐标系的平移等式。t( tx, ty ): ( x, y ) > ( x tx, y ty )二维笛卡儿坐标系的缩放等式。s( k ): ( x, y ) > ( kx, ky )旋转等式:r( q ): ( x, y ) > ( x cos(q) - y sin(q), x sin(q) y cos(q) ) 三维坐标系公式。平移公式:t( tx, ty, tz…

3D和2D游戏开发技术里的坐标系总结

from:http://www.liketocode.com/coding/208.htm 最近在做unity3d开发,坐标系的概念把自己搞得好迷糊,发现理解好坐标系的东西的确对一个新手来说是必经之路,而且是基础中的重点。故在此总结下在Unity3D开发中,以及在其他游戏开发…

2d-3d坐标转换

对于常规相机,SLAM里使用针孔相机模型   简而言之,一个空间点[x,y,z]和它在图像中的像素坐标[u,v,d] (d 指深度数据) 的对应关系是这样的: u x ⋅ f x z c x , ux⋅f_xzcx, ux⋅fx​zcx, v y ⋅ f y z c y , vy⋅f_yzcy, vy⋅fy​zcy…

2d图形旋转

2d图形旋转 1.这里旋转使用数学公式: xr x * cos(theta) - y * sin(theta); yr x * sin(theta) y * cos(theta); 2.如果以左上角为原点(0,0),x方向向右增加,y方向向下增加的话,对于原图形旋转的100度并不等于连续20次的旋转5度的结果,可以…

2D-2D:对极几何与三角测量

文章目录 尺度不确定性对极几何尺度不确定性初始化的纯旋转问题 三角测量最小二乘法 单应性矩阵由像素系到相机系由像素系a到像素系b求解单应性矩阵 尺度不确定性 如果把相机的运动和场景同时放大两倍,单目相机所看到的像是一样的。同样的,把这个大小乘…

3D空间中的点坐标转化为屏幕二维点坐标(二)

👉原文地址:3D空间中的点坐标转化为屏幕二维点坐标(二)👈 上一节,简单的介绍了计算机时如何将三维世界中的点转化成屏幕上的二维点坐标的,知道了透视矩阵的作用。这一节内容,就是介…