meatball1982 发表于 2018-1-6 13:45:04

豆粑粑 matlab 欧拉角,旋转矩阵 

QL的问题,一开始是想要一个球面上均匀的随机点。
查了一下,我靠,真是个挺麻烦的事儿,特别是定义球面上点之间的距离,然后生成对应的点。

另一个,是如果把一个刚体在一个球面坐标上进行旋转。
还是查了一下,一个baidu百科,把本来挺明白事儿给整迷糊了。后来,找了比较官方的书。
《MATHEMATICAL METHODS FOR PHYSICISTS, SIXTH EDITION, George B. Arfken》

基本思路是按水平面转一下,按新的yoz转一下,再按新的xoy转一下,
至于生成随机的点,随机生成一堆alpha, beta, gamma三个角。把初始向量一边一边的转就行。



基本把Euler角怎么转给整明白了。


clear all
clc
clf

%% outline
% illustrate the rot matrix
% according to
% https://baike.baidu.com/item/%E6%97%8B%E8%BD%AC%E7%9F%A9%E9%98%B5/3265181?fr=aladdin
%

%% main
% % define original vector,
% p0_x =1*(sqrt(3)/3);
% p0_y =1*(sqrt(3)/3);
% p0_z =1*(sqrt(3)/3);

% p0_x =1;
% p0_y =0;
% p0_z =0;


phi0 = pi/8;
the0 = pi/2;
r0   = 1;

p0_x = r0 * cos(phi0) * sin(the0);
p0_y = r0 * sin(phi0) * sin(the0);
p0_z = r0 * cos(the0);

%
alp= -pi/4;   %% yoz
bet= pi/3;      %% xoz
gam= -pi/2;      %% xoy

= fun_mm_rot_mat(alp,0,0)
= fun_mm_rot_mat(0,bet,0)
= fun_mm_rot_mat(0,0,gam)

= mat_alp*mat_bet*mat_gam

mat_eul_fun = fun_mm_rot_mat(alp,bet,gam)


% rot alph
tm=mat_alp*;
p_x_alp=tm(1);
p_y_alp=tm(2);
p_z_alp=tm(3);


tm= mat_bet*;
% tm = mat_bet*;
p_x_bet=tm(1);
p_y_bet=tm(2);
p_z_bet=tm(3);

tm = mat_gam*;
% tm = mat_gam*;
p_x_gam=tm(1);
p_y_gam=tm(2);
p_z_gam=tm(3);

tm = mat_eul_fun * ;
p_x_final = tm(1);
p_y_final = tm(2);
p_z_final = tm(3);


%% plot res
=sphere(50);
hold on

% plot orig vec
plot3(,,,'rs-','linewidth',5);
plot3(,,,'gs-','linewidth',5);
plot3(,,,'bs-','linewidth',5);
plot3(,,,'ms-','linewidth',5);

plot3(p_x_final,p_y_final,p_z_final,'o','markersize',10);

% plot sphere
surf(x,y,z,z,'edgecolor',)
plot3(,,,'k','linewidth',3);
plot3(,,,'k','linewidth',3);
plot3(,,,'k','linewidth',3);
% plot xoy
hxoy=surf(x,y,zeros(size(x)),'edgecolor','none')
axis equal
alpha(0.2)
alpha(hxoy,0.5)
xlabel('x')
ylabel('y')
zlabel('z')
view(144,23)
grid on

h_leg=legend('ori vec', '1st vec alpha','2nd vec beta','3rd vec gamma','final point','location','northwest')
%,'sphere','x axis ','y axis ','z axis ','xoy')
axis tight
% legend('boxoff')
h_leg.Color =;
set(h_leg.BoxFace, 'ColorType','truecoloralpha', 'ColorData',uint8(255*[.8;.8;.8;.3]));



function =fun_mm_rot_mat(alpha,beta,gamma);
% =fun_mm_rot_mat(alpha,beta,gamma);
% alph, beta, gamma : three angles
% mat               : euler matrix
%
%%
%
% Euler Angles
% Page 202
% MATHEMATICAL
% METHODS FOR
% PHYSICISTS
% SIXTH EDITION
% George B. Arfken

%% main
% three angles
a = alpha;
b = beta;
r = gamma;


% matrix alpha ------------------------------
mat_a = [cos(a)sin(a)      0
          -sin(a)cos(a)      0
               0       0       1 ];


% matrix beta ------------------------------
mat_b = [cos(b)      0-sin(b)
               0       1       0
         sin(b)      0   cos(b)];


% matrix gamma ------------------------------
mat_r = [cos(r)sin(r)      0
          -sin(r)cos(r)      0
               0       0       1];

% euler matrix
mat_eul= mat_r * mat_b * mat_a;

页: [1]
查看完整版本: 豆粑粑 matlab 欧拉角,旋转矩阵