Advertisement
bailex

rotation around a line

Jul 27th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 1.15 KB | None | 0 0
  1. format('v',15)
  2.  
  3. //rotation axis
  4. u = [rand(), rand(), rand()];
  5. u = u./ sqrt(u*u')
  6.  
  7. //angle
  8. t = 2*%pi*rand(); //picked randomly
  9.  
  10. c = cos(t);
  11. s = sin(t);
  12.  
  13. //translation vector
  14. T= [rand(); rand(); rand()] //picked randomly
  15.  
  16. //rotation matrix
  17. R = [c+u(1)*u(1)*(1-c), u(1)*u(2)*(1-c)-u(3)*s, u(1)*u(3)*(1-c)+u(2)*s;
  18.  u(1)*u(2)*(1-c)+u(3)*s, c+u(2)*u(2)*(1-c), u(2)*u(3)*(1-c)-u(1)*s;
  19.  u(1)*u(3)*(1-c)-u(2)*s, u(2)*u(3)*(1-c)+u(1)*s, c+u(3)*u(3)*(1-c)]
  20.  
  21. // FIRST TEST
  22. //transformation matrix: rotation around the line u*t+T
  23. // - the upper left 3x3 matrix is actually a rotation
  24. // - the translation part depends on the line and the rotation
  25. M = [eye(3,3),T;0,0,0,1]*[R,[0;0;0];0,0,0,1]*[eye(3,3),-T;0,0,0,1]
  26.  
  27. // SECOND TEST
  28. //transformation matrix: rotation and post-rotation translation
  29. // - the upper left 3x3 matrix is actually a rotation
  30. // - the translation part is generated randomly (no link to the rotation)
  31. //M = [eye(3,3),T;0,0,0,1]*[R,[0;0;0];0,0,0,1]
  32.  
  33. //identity
  34. I = eye(4,4);
  35.  
  36. //system
  37. A = I-M
  38.  
  39. //row reduction
  40. S = rref(A)
  41.  
  42. //line direction
  43. nu = S(1:3,3);
  44. nu(3)=1;
  45. nu = nu./ sqrt(nu'*nu)
  46.  
  47. //line position
  48. nt = S(1:3,4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement