Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ra.rotate(instanceList=('PART-1-MESH-1-1', ), axisPoint=(a, b, c), axisDirection=(u, v, w), angle=t)
- """
- Assumes a Right-handed coordinate system.
- """
- import numpy as np
- def _Ru(t, u):
- 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)],
- [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)],
- [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))]])
- def general_rotation(axis_order, angles, axes_dir=((1.0,0.0,0.0),(0.0,1.0,0.0))):
- """
- Inputs:
- axis_order - Iterable of ints specifying the axis order to apply the transformation.
- For example, (0,1,2) means to apply the rotations around the (x,y,z) axes, in that order.
- angles - Iterable of angles (in degrees) specifying the rotations. This should be the same length as axis_order.
- 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.
- """
- # Convert all angles to radians
- angles = np.deg2rad(angles)
- # Calculate the third (z) axis and normalise all axes
- ax0 = np.array(axes_dir[0])
- ax1 = np.array(axes_dir[1])
- ax2 = np.cross(ax0, ax1)
- ax0 = ax0/np.linalg.norm(ax0)
- ax1 = ax1/np.linalg.norm(ax1)
- ax2 = ax2/np.linalg.norm(ax2)
- ax = [ax0, ax1, ax2] # Or similar iterable but must be mutable
- intermediate_axes = [None]*len(axis_order)
- # Calculate total transformation
- for i, a in enumerate(axis_order):
- # Store intermediate axes
- intermediate_axes[i] = list(ax)
- R = _Ru(angles[i], ax[a])
- # Don't bother transforming current axis that's being rotated about
- zot = [0,1,2]
- zot.remove(a)
- for aj in zot:
- ax[aj] = np.dot(R, ax[aj])
- # Return combined axis of rotation, combined angle of rotation, and intermediate axes
- return intermediate_axes
- rotate_axes = general_rotation(axis_order, angles, axes_dir)
- for i in range(len(rotate_axes)):
- ra.rotate(instanceList=(instanceName, ), axisPoint=origin, axisDirection=rotate_axes[i][axis_order[i]], angle=angles[i])
Add Comment
Please, Sign In to add comment