Guest User

Untitled

a guest
Mar 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. ra.rotate(instanceList=('PART-1-MESH-1-1', ), axisPoint=(a, b, c), axisDirection=(u, v, w), angle=t)
  2.  
  3. """
  4. Assumes a Right-handed coordinate system.
  5. """
  6.  
  7. import numpy as np
  8.  
  9.  
  10. def _Ru(t, u):
  11. return np.array([[np.cos(t) + (u[0]**2)*(1 - np.cos(t)), u[0]*u[1]*(1 - np.cos(t)) - u[2]*np.sin(t), u[0]*u[2]*(1 - np.cos(t)) + u[1]*np.sin(t)],
  12. [u[1]*u[0]*(1 - np.cos(t)) + u[2]*np.sin(t), np.cos(t) + (u[1]**2)*(1 - np.cos(t)), u[1]*u[2]*(1 - np.cos(t)) - u[0]*np.sin(t)],
  13. [u[2]*u[1]*(1 - np.cos(t)) - u[1]*np.sin(t), u[2]*u[1]*(1 - np.cos(t)) + u[0]*np.sin(t), np.cos(t) + (u[2]**2)*(1 - np.cos(t))]])
  14.  
  15. def general_rotation(axis_order, angles, axes_dir=((1.0,0.0,0.0),(0.0,1.0,0.0))):
  16. """
  17. Inputs:
  18. axis_order - Iterable of ints specifying the axis order to apply the transformation.
  19. For example, (0,1,2) means to apply the rotations around the (x,y,z) axes, in that order.
  20. angles - Iterable of angles (in degrees) specifying the rotations. This should be the same length as axis_order.
  21. axes_dir - Iterable of iterable of floats, specifying two orthogonal directions forming the local x and y axes, respectively. Defaults to global x and y axes.
  22. """
  23.  
  24. # Convert all angles to radians
  25. angles = np.deg2rad(angles)
  26.  
  27. # Calculate the third (z) axis and normalise all axes
  28. ax0 = np.array(axes_dir[0])
  29. ax1 = np.array(axes_dir[1])
  30. ax2 = np.cross(ax0, ax1)
  31. ax0 = ax0/np.linalg.norm(ax0)
  32. ax1 = ax1/np.linalg.norm(ax1)
  33. ax2 = ax2/np.linalg.norm(ax2)
  34. ax = [ax0, ax1, ax2] # Or similar iterable but must be mutable
  35.  
  36. intermediate_axes = [None]*len(axis_order)
  37.  
  38. # Calculate total transformation
  39. for i, a in enumerate(axis_order):
  40.  
  41. # Store intermediate axes
  42. intermediate_axes[i] = list(ax)
  43.  
  44. R = _Ru(angles[i], ax[a])
  45.  
  46. # Don't bother transforming current axis that's being rotated about
  47. zot = [0,1,2]
  48. zot.remove(a)
  49. for aj in zot:
  50. ax[aj] = np.dot(R, ax[aj])
  51.  
  52. # Return combined axis of rotation, combined angle of rotation, and intermediate axes
  53. return intermediate_axes
  54.  
  55. rotate_axes = general_rotation(axis_order, angles, axes_dir)
  56. for i in range(len(rotate_axes)):
  57. ra.rotate(instanceList=(instanceName, ), axisPoint=origin, axisDirection=rotate_axes[i][axis_order[i]], angle=angles[i])
Add Comment
Please, Sign In to add comment