## 3 Algorithm of System
### Rehabilitation Content
#### 3.3.2 3D Model 6 DoF Acquisition  
HoloLens2 is placed in the XR environment by automatically setting up an image processing 6 DoF Unity. The 6 DoF actual application formula of the 3D model for the user is as follows. First, Equation (2) is the rotation value of 6 DoF. The equations for pitch, roll, and yaw are matrix values and are defined as the rotation matrix of the \(x\)-axis. The \(y\)-axis in Equation (3) rotation and the \(z\)-axis in Equation (4) are defined as follows:  
\[R_{x}(\psi)= \begin{bmatrix}1&0&0\\ 0&cos\psi&-sin\psi\\ 0&sin\psi&cos\psi\end{bmatrix} , \tag{2}\]  
\[R_{y}(\theta)= \begin{bmatrix}cos\theta&0&sin\theta\\ 0&1&0\\ -sin\theta&0&cos\theta\end{bmatrix} , \tag{3}\]  
\[R_{z}(\phi)= \begin{bmatrix}cos\phi&-sin\phi&0\\ sin\phi&cos\phi&0\\ 0&0&1\end{bmatrix} , \tag{4}\]  
\(\psi\), \(\theta\) and \(\phi\) are Euler angles, and by combining these equations, the coordinate movement amount of rotation, which is one of the 6 DoF coordinates, can be obtained. The matrix shown in Equation (5) can be considered as the order of three rotations about each \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Joint** & **Max. (Unit: m)** & **Min. (Unit: m)** & **Fluctuation Range (Unit: m)** \\ \hline \multirow{4}{*}{Ankle Left} & X: \(-\)0.21 & X: \(-\)0.23 & X: 0.04 \\  & Y: 0.32 & Y: 0.27 & Y: 0.06 \\  & Z: 1.20 & Z: 1.18 & Z: 0.02 \\  & X: \(-\)0.07 & X: \(-\)0.14 & X: 0.03 \\ Ankle Right & Y: 0.22 & Y: 0.19 & Y: 0.06 \\  & Z: 1.43 & Z: 1.40 & Z: 0.03 \\  & X: \(-\)0.27 & X: \(-\)0.36 & X: 0.11 \\ Foot Left & Y: 0.28 & Y: 0.16 & Y: 0.10 \\  & Z: 1.09 & Z: 1.05 & Z: 0.04 \\  & X: \(-\)0.20 & X: \(-\)0.28 & X: 0.13 \\ Foot Right & Y: 0.28 & Y: 0.16 & Y: 0.12 \\  & Z: 1.37 & Z: 1.33 & Z: 0.04 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Coordinate Movement Figures for Each Joint. circular axis. It first rotates around the \(x\)-axis of the model's local coordinates, and then around the \(y\)-axis. When rotating around the \(z\)-axis, the rotation then appears as a series of rotation matrix products. \[R=R_{z}(\phi)R_{y}(\theta)R_{x}(\psi) \tag{5}\] \[= \left[ \begin{array}{cccc}cos\theta cos\phi&sin\psi sin\phi cos\phi -cos\psi sin\phi&cos\psi sin\theta cos\phi+sin\psi sin\phi\\ cos\theta sin\phi&sin\psi sin\phi sin\phi+cos\phi cos\phi&cos\psi sin\theta sin\phi -sin\psi cos\phi\\ -sin\theta&sin\psi cos\theta&cos\psi cos\theta\end{array} \right]\]  
Given a rotation matrix R, equalize each element and the corresponding element of the matrix product \(R_{z}(\phi)\), \(R_{y}(\theta)\) and \(R_{x}(\psi)\) to calculate the Euler angle, \(\phi\), \(\theta\), and \(\psi\) to determine the position of the prosthetic leg. This formula was used to find the Euler angle and determine the virtual prosthetic position instantiated in Hololens2. The rehabilitation training process before wearing the robotic prosthesis was designed as a simple ankle movement repetition process for all rehabilitation simulations. The amputee selects one of the rehabilitation simulation methods. Raise the feet in a sitting position and perform ankle exercises corresponding to the number of assessments. During the exercise, the patient attaches the EMG sensor to the amputation of the lower extremity and then continues with the movement. In addition, we measure joint vertex movement counts through Azure Kinect for the general public. The numerical values are subdivided and standardized for the rehabilitation of motion animation and motion classification. Figure 7 below shows the rehabilitation process. The movements of the amputee patient shown in Figure 7 consist of 'ankle up' and 'ankle down'. During the simulation, the signal obtained from the EMG sensor is transmitted to the Raspberry Pi, and signal processing continues. Since the EMG signal generates a lot of noise during acquisition, it is used to interpret the signal as motion or no motion. The captured EMG signal is transmitted to the Unity 3D Rendering Engine.