The collision engine which is developed in this study is based on collision detection using the GJK algorithm [21]. To calculate the approximate amount of force during the collision of the lower tip of a haptic wand and a virtual object, we developed MATLAB code which calculates the force based on equation (1) [11]. An overview of the methodology is shown in (Figure A4) and described in further detail as follows:
1) 3D objects
Three 3D objects were imported into SolidWorks and saved in STL (stereolithography) format. To compare results between flat and curved surfaces of objects imported into the collision engine, STL files of the following objects were imported into MATLAB and Simulink (see Figure A5):
- A human hand reconstructed from a CT scan [22];
- A cylinder with a 0.025 m radius and a 0.1 m height; and
- A cuboid measuring 0.1 × 0.1 × 0.2 m3.
2) Conversion from STL to X3D format
Using Blender (v. 2.49), we converted the STL files to X3D format, which is the required format for Quanser 3D Viewer. The converted human hand model in X3D format is shown in Figure A6. Considering that visualization and force calculation are two parallel and separate processes (Figure A4), a transformation matrix between MATLAB and Blender coordinate systems was used to calculate applied forces from object positions.
3) Import into 3D Viewer
The 3D Viewer was used for visualization of an avatar of the wand’s tip and the three objects imported into the virtual environment. Objects represented in X3D format were imported into 3D Viewer. The wand and an object in X3D format in the virtual environment are shown in Figure A7.
4) Convert STL files to object vertices
Using a variation of MATLAB code [23], we converted STL files to object vertices (see Figure 1a, Figure 2a, and Figure 3a). Vertices of an object were used as inputs for the GJK algorithm. These vertices form an n × 3 matrix, n- number of vertices, and 3 coordinates, which define the object in the X, Y, and Z planes. The cuboid, cylinder, and human hand were represented by 36, 456, and 3660 vertices, respectively.
5) GJK algorithm in Simulink and MATLAB
Vertices of the imported objects produced in the previous step, as well as stiffness and damping ratios of each object and real time position vectors of the haptic interface, were used as inputs for the main MATLAB [23]. For all objects, stiffness in the X, Y and Z directions was manually set to (160, 160, 160) N∙s/m, and damping factors were set to (0.8, 0.8, 0.8) N∙s/rad, respectively.
The position of the haptic interface is a 1 × 3 vector. “1” is the indicator a single point (haptic interface), and “3” is the X, Y, and Z coordinates of this point. Real time position vector is output of a specific QUARC block called “Haptic 5 DOF Wand Cartesian Plane” (Figure A5).
The center of mass of each object was set to (0, 0, -0.075). We simplified the wand to be comprised of a single point with one vertex and three degrees of freedom. Initial position of the wand was set at (0, 0, 0).
6) Simulating and generating haptic force feedback
A “CollisionFlag” was deployed so that when a collision was detected, the flag went to “1”; otherwise, it stayed at “0”. If “CollisionFlag” was “1”, the code calculated the force based on equation (1). The 5-DOF haptic wand generated force feedback when the wand collided with an object in the virtual environment.
Three virtual experiments were conducted to assess the accuracy of the collision engine: dorsal aspect of the human hand, curved surface of a cylinder, and flat surface of a cuboid. In these experiments, the wand collided with the surface of the virtual object over a 10-second period. Distance between the wand and the virtual object was recorded, and contact forces between the virtual objects and the wand were measured by the collision engine based on equation (1) in X, Y and Z directions.