Mathematica中文论坛-非官方

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 8416|回复: 0
打印 上一主题 下一主题

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

[复制链接]

532

主题

602

帖子

3029

积分

论坛元老

Rank: 8Rank: 8

积分
3029
跳转到指定楼层
楼主
发表于 2018-1-6 13:45:04 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
QL的问题,一开始是想要一个球面上均匀的随机点。
查了一下,我靠,真是个挺麻烦的事儿,特别是定义球面上点之间的距离,然后生成对应的点。

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

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



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


  1. clear all
  2. clc
  3. clf

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

  9. %% main
  10. % % define original vector, [1 0 0 ]
  11. % p0_x =1*(sqrt(3)/3);
  12. % p0_y =1*(sqrt(3)/3);
  13. % p0_z =1*(sqrt(3)/3);

  14. % p0_x =1;
  15. % p0_y =0;
  16. % p0_z =0;


  17. phi0 = pi/8;
  18. the0 = pi/2;
  19. r0   = 1;

  20. p0_x = r0 * cos(phi0) * sin(the0);
  21. p0_y = r0 * sin(phi0) * sin(the0);
  22. p0_z = r0 * cos(the0);

  23. %
  24. alp= -pi/4;     %% yoz
  25. bet= pi/3;      %% xoz
  26. gam= -pi/2;      %% xoy

  27. [mat_alp]= fun_mm_rot_mat(alp,0,0)
  28. [mat_bet]= fun_mm_rot_mat(0,bet,0)
  29. [mat_gam]= fun_mm_rot_mat(0,0,gam)

  30. [mat_eul]= mat_alp*mat_bet*mat_gam

  31. mat_eul_fun = fun_mm_rot_mat(alp,bet,gam)


  32. % rot alph
  33. tm=mat_alp*[p0_x;p0_y;p0_z];
  34. p_x_alp=tm(1);
  35. p_y_alp=tm(2);
  36. p_z_alp=tm(3);


  37. tm= mat_bet*[p_x_alp;p_y_alp;p_z_alp];
  38. % tm = mat_bet*[p0_x;p0_y;p0_z];
  39. p_x_bet=tm(1);
  40. p_y_bet=tm(2);
  41. p_z_bet=tm(3);

  42. tm = mat_gam*[p_x_bet;p_y_bet;p_z_bet];
  43. % tm = mat_gam*[p0_x;p0_y;p0_z];
  44. p_x_gam=tm(1);
  45. p_y_gam=tm(2);
  46. p_z_gam=tm(3);

  47. tm = mat_eul_fun * [p0_x;p0_y;p0_z];
  48. p_x_final = tm(1);
  49. p_y_final = tm(2);
  50. p_z_final = tm(3);


  51. %% plot res
  52. [x,y,z]=sphere(50);
  53. hold on

  54. % plot orig vec
  55. plot3([0 p0_x],[0 p0_y],[0 p0_z],'rs-','linewidth',5);
  56. plot3([0 p_x_alp],[0 p_y_alp],[0 p_z_alp],'gs-','linewidth',5);
  57. plot3([0 p_x_bet],[0 p_y_bet],[0 p_z_bet],'bs-','linewidth',5);
  58. plot3([0 p_x_gam],[0 p_y_gam],[0 p_z_gam],'ms-','linewidth',5);

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

  60. % plot sphere
  61. surf(x,y,z,z,'edgecolor',[0.8 0.8 0.8])
  62. plot3([0 1],[0 0],[0 0],'k','linewidth',3);
  63. plot3([0 0],[0 1],[0 0],'k','linewidth',3);
  64. plot3([0 0],[0 0],[0 1],'k','linewidth',3);
  65. % plot xoy
  66. hxoy=surf(x,y,zeros(size(x)),'edgecolor','none')
  67. axis equal
  68. alpha(0.2)
  69. alpha(hxoy,0.5)
  70. xlabel('x')
  71. ylabel('y')
  72. zlabel('z')
  73. view(144,23)
  74. grid on

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

复制代码

  1. function [mat_eul,mat_a,mat_b,mat_r]=fun_mm_rot_mat(alpha,beta,gamma);
  2. % [mat_eul,mat_a,mat_b,mat_r]=fun_mm_rot_mat(alpha,beta,gamma);
  3. % alph, beta, gamma : three angles
  4. % mat               : euler matrix
  5. %
  6. %%
  7. %
  8. % Euler Angles
  9. % Page 202
  10. % MATHEMATICAL
  11. % METHODS FOR
  12. % PHYSICISTS
  13. % SIXTH EDITION
  14. % George B. Arfken

  15. %% main
  16. % three angles
  17. a = alpha;
  18. b = beta;
  19. r = gamma;


  20. % matrix alpha ------------------------------
  21. mat_a = [  cos(a)  sin(a)      0
  22.           -sin(a)  cos(a)      0
  23.                0       0       1 ];


  24. % matrix beta ------------------------------
  25. mat_b = [  cos(b)      0  -sin(b)
  26.                0       1       0
  27.            sin(b)      0   cos(b)];


  28. % matrix gamma ------------------------------
  29. mat_r = [  cos(r)  sin(r)      0
  30.           -sin(r)  cos(r)      0
  31.                0       0       1];

  32. % euler matrix
  33. mat_eul= mat_r * mat_b * mat_a;
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|Mathematica中文论坛-非官方 ( 辽ICP备16001491号-1

GMT+8, 2024-4-26 04:13 , Processed in 0.117348 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表