当前位置:   article > 正文

三维手臂动态matlab仿真,可以灵活控制手指运动_灵巧手 matlab

灵巧手 matlab

目录

1.算法描述

2.仿真效果预览

3.MATLAB核心程序

4.完整MATLAB


1.算法描述

三维手臂动态matlab仿真,可以灵活控制手指运动

2.仿真效果预览

matlab2022a仿真如下:

 

3.MATLAB核心程序

  1. clc;
  2. clear;
  3. close all;
  4. warning off;
  5. addpath(genpath(pwd));
  6. % Load the faces, vertices and weights
  7. faces = csvread('handfaces.txt');
  8. V0 = csvread('handverts.txt');
  9. V0=V0';
  10. N = size(V0,1);
  11. weights = csvread('handweights.txt');
  12. sk = loadbvh('HandBase.bvh');
  13. wmap = [1 2 3 4 0 15 16 17 0 5 6 7 0 8 9 10 0 11 12 13 0 14 0];
  14. wzero = wmap==0;
  15. W = sparse(weights(:,1)+1,weights(:,2)+1,weights(:,3));
  16. W = full(W);%W = W./repmat(sum(W,2),[1 size(W,2)]);
  17. W = W(:,wmap+wzero);
  18. W(:,wzero)=0;
  19. cla
  20. for displayWeightIndex=find(~wzero)
  21. h = trisurf(faces+1,V0(1,:),V0(2,:),V0(3,:),W(:,displayWeightIndex));
  22. axis equal; axis vis3d;
  23. shading interp;
  24. set(h,'FaceAlpha',0.5)
  25. axis([-200 200 -100 100 -100 500]);
  26. pause(0.2);
  27. end
  28. hold on
  29. for j=2:258
  30. V=V0*0;
  31. cla
  32. for i=1:length(sk)
  33. % -------------------------------------------------------------------------
  34. % Display the bones
  35. if sk(i).parent
  36. s=sk(i).t_xyz(:,j); sp = sk(sk(i).parent).t_xyz(:,j);
  37. plot3([s(1) sp(1)],[s(2) sp(2)],[s(3) sp(3)],'r','LineWidth',5);
  38. end
  39. plot3(sk(i).t_xyz(1,j),sk(i).t_xyz(2,j),sk(i).t_xyz(3,j),'g.','MarkerSize',10);
  40. if sk(i).Nchannels
  41. plotax(sk(i).t_xyz(:,j)',sk(i).T(1:3,1:3,j)*sk(i).R0,15)
  42. end
  43. % -------------------------------------------------------------------------
  44. if sk(i).Nchannels
  45. % Takes a local bone coordinate and puts it into the new pose global position
  46. poseMatrix(:,:,i,j) = [(sk(i).T(1:3,1:3,j)*sk(i).R0) sk(i).t_xyz(:,j);0 0 0 1];
  47. % Takes a local bone coordinate and puts it into the base pose global position
  48. restMatrix(:,:,i) = [((sk(i).R0)) sk(i).head0 ;0 0 0 1];
  49. M(:,:,j) = poseMatrix(:,:,i,j)*inv(restMatrix(:,:,i));
  50. R = M(1:3,1:3,j);
  51. t = M(1:3,4,j);
  52. % We add the influence from every bone
  53. V = V + (R*V0 + repmat(t,1,length(V0))) * spdiags(W(:,i),0,length(V),length(V));
  54. % --------------------------------------------------------------------------------
  55. end
  56. end
  57. % -------------------------------------------------------------------------
  58. % Display nicely
  59. h = trisurf(faces+1,V(1,:),V(2,:),V(3,:),W(:,2)*0);
  60. axis off;
  61. axis equal
  62. shading interp;
  63. light
  64. lighting phong
  65. set(h,'FaceAlpha',0.8)
  66. drawnow
  67. end
  68. i = 20; j=2;
  69. T = poseMatrix(1:3,1:3,i,j); Tp = poseMatrix(1:3,1:3,i-1,j); T_0 = restMatrix(1:3,1:3,i); Tp_0 = restMatrix(1:3,1:3,i-1);
  70. R = (T_0')*(Tp_0)*(Tp')*(T);
  71. [Rx Ry Rz] = dcm2angle(R,'XYZ');
  72. Rx = rad2deg(-Rx); Ry = rad2deg(-Ry); Rz = rad2deg(-Rz);
  73. [Rx Ry Rz]
  74. A_100

4.完整MATLAB

V

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/314754
推荐阅读
相关标签
  

闽ICP备14008679号