|
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, [1 0 0 ]
- % 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
- [mat_alp]= fun_mm_rot_mat(alp,0,0)
- [mat_bet]= fun_mm_rot_mat(0,bet,0)
- [mat_gam]= fun_mm_rot_mat(0,0,gam)
- [mat_eul]= mat_alp*mat_bet*mat_gam
- mat_eul_fun = fun_mm_rot_mat(alp,bet,gam)
- % rot alph
- tm=mat_alp*[p0_x;p0_y;p0_z];
- p_x_alp=tm(1);
- p_y_alp=tm(2);
- p_z_alp=tm(3);
- tm= mat_bet*[p_x_alp;p_y_alp;p_z_alp];
- % tm = mat_bet*[p0_x;p0_y;p0_z];
- p_x_bet=tm(1);
- p_y_bet=tm(2);
- p_z_bet=tm(3);
- tm = mat_gam*[p_x_bet;p_y_bet;p_z_bet];
- % tm = mat_gam*[p0_x;p0_y;p0_z];
- p_x_gam=tm(1);
- p_y_gam=tm(2);
- p_z_gam=tm(3);
- tm = mat_eul_fun * [p0_x;p0_y;p0_z];
- p_x_final = tm(1);
- p_y_final = tm(2);
- p_z_final = tm(3);
- %% plot res
- [x,y,z]=sphere(50);
- hold on
- % plot orig vec
- plot3([0 p0_x],[0 p0_y],[0 p0_z],'rs-','linewidth',5);
- plot3([0 p_x_alp],[0 p_y_alp],[0 p_z_alp],'gs-','linewidth',5);
- plot3([0 p_x_bet],[0 p_y_bet],[0 p_z_bet],'bs-','linewidth',5);
- plot3([0 p_x_gam],[0 p_y_gam],[0 p_z_gam],'ms-','linewidth',5);
- plot3(p_x_final,p_y_final,p_z_final,'o','markersize',10);
- % plot sphere
- surf(x,y,z,z,'edgecolor',[0.8 0.8 0.8])
- plot3([0 1],[0 0],[0 0],'k','linewidth',3);
- plot3([0 0],[0 1],[0 0],'k','linewidth',3);
- plot3([0 0],[0 0],[0 1],'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 =[0.8 0.8 0.8 0.2];
- set(h_leg.BoxFace, 'ColorType','truecoloralpha', 'ColorData',uint8(255*[.8;.8;.8;.3]));
复制代码
- function [mat_eul,mat_a,mat_b,mat_r]=fun_mm_rot_mat(alpha,beta,gamma);
- % [mat_eul,mat_a,mat_b,mat_r]=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;
复制代码
|
|