首页 > 解决方案 > matlab中真的没有预定义的旋转矩阵吗?

问题描述

我只是想知道,如果 MathWorks Matlab 中真的没有预定义的函数可以给你一些这样的:

R = rot(a)

rot(a)存在[cos(a) -sin(a); sin(a) cos(a)]

标签: matlabmatrix

解决方案


没有内置这样的函数。但你基本上是自己写的,所以保存它(下)并调用它:rot2d()。如果您想要 3d 旋转矩阵,请发布另一个问题。如果要旋转行向量,请转置显示的矩阵,并在相乘时将向量放在矩阵之前。

function [R] = rot2d(a)
%ROT2D Return 2D rotation matrix
%   Returns matrix that rotates a column vector by angle a (in radians).
%   Example 1: v=[1;1]; w=rot2d(pi/4)*v; {w now = [0;1.414]}
%   Example 2: Rotate 3 (or more) [x;y] pairs at a time: 
%       v1=[1,0]; v2=[1;1]; v3=[0;1]; vc=[v1,v2,v3]; wc=rot2d(pi/6)*vc;
%   The examples show the correct multiplication order.
%   Note that this is not the matrix to use if you want to express a
%   vector in terms of a coordinate system rotated by angle a. 
%   Use w=inv(rot2d(a))*v to express vector v in a coordinate system
%   rotated by a.
R = [cos(a),-sin(a);sin(a),cos(a)];
end

推荐阅读