### Extract Translation & Large Rotation

Figure 1: Z-X'-Y'' Rotation of the 'Grip'

PADT has a recent post on Extracting Relative Displacements in ANSYS Mechanical. The macro only works for small angles (in the order of 5 degrees). The accompanied PDF file shows:
$u = dR \cdot (x-\overline{x}) + \overline{u}$

Their nomenclature:
$dR$ : Small rotation matrix
$x$ : Nodal position vector
$\overline{x}$ : Center of Gravity (CG) position vector
$u$ : Nodal displacement vector
$\overline{u}$ : CG displacement vector

To extend their work to account for large deflection, I've added some terms:
$x + u - \overline{x} \approx R \cdot (x - \overline{x}) + \overline{u}$
$R$ : Rotation Matrix

The left side of the equation is the final deformed body. The right side of the equation is the rigid body rotation and translation. As the rotation is applied at the center of the body, $\overline{x}$ is accounted for on both sides of the equation.

Note that 'equal' is just an approximation as the deformation due to strain has only been accounted for on the left side of the equation while the right side is purely rigid body. Now that the equation has been established, they can be vectorized and solve for the $3\times3$ variables in $R$ using least square curve fit. The Moore-Penrose inverse was used to achieve this.

Euler Angles
Ansys uses the Z-X'-Y'' sequence to define the coordinate system (previous post). To avoid ill-conditioned matrix, the selected nodes or elements used for curve-fitting cannot all lie on a geometrical plane. The math has some difficulty here.

Secondly, be aware of Gimbal Lock. As $\alpha$ approaches $90^o$, there is a loss of a degree of freedom. The solution around here is incorrect. If this is an issue for your case, look into quaternions.

Lastly, the rotation matrix is unique though the angles may not be. The script solves for the rotation matrix and the angles are derived from the matrix. For example, a $0^o - 0^o - 0^o$ sequence is the same as $180^o - 180^o - 180^o$.

Workbench Example
As the rotations are on successive axis, a pseudo-robot arm seems to be appropriate. The model was set up such that there are 3 successive rotations of revolute joints with known angles and a pressure to slightly deform the body in question.

Figure 2: Model Setup

By inserting the snippet and modifying the component name to match, the results are 'close' to the original input angles. They are not exact because of the slight deformation due to the pressure of 3Pa and inevitable errors from least-square curve fit. As shown below, the results are as expected.

Figure 3: Results at the Details of the Command Snippet

A few housekeeping notes:
1. Large Deformation has to be turned ON.
2. Save MAPDL db was set to YES before solution

Example Files Location
Archived Ansys Workbench v18.2 File with Results: Link