ShapeRotator: An R tool for standardized rigid rotations of articulated three‐dimensional structures with application for geometric morphometrics

Abstract The quantification of complex morphological patterns typically involves comprehensive shape and size analyses, usually obtained by gathering morphological data from all the structures that capture the phenotypic diversity of an organism or object. Articulated structures are a critical component of overall phenotypic diversity, but data gathered from these structures are difficult to incorporate into modern analyses because of the complexities associated with jointly quantifying 3D shape in multiple structures. While there are existing methods for analyzing shape variation in articulated structures in two‐dimensional (2D) space, these methods do not work in 3D, a rapidly growing area of capability and research. Here, we describe a simple geometric rigid rotation approach that removes the effect of random translation and rotation, enabling the morphological analysis of 3D articulated structures. Our method is based on Cartesian coordinates in 3D space, so it can be applied to any morphometric problem that also uses 3D coordinates (e.g., spherical harmonics). We demonstrate the method by applying it to a landmark‐based dataset for analyzing shape variation using geometric morphometrics. We have developed an R tool (ShapeRotator) so that the method can be easily implemented in the commonly used R package geomorph and MorphoJ software. This method will be a valuable tool for 3D morphological analyses in articulated structures by allowing an exhaustive examination of shape and size diversity.

Similarly, collectively evaluating different modules in the limbs, especially when correlated to locomotion, or considering several structures across the whole body, could improve our understanding of the effect of environmental conditions on morphological evolution (Vidal-García & Keogh, 2017).
Unfortunately, nonrigid structures, such as articulated structures, will inevitably suffer the effects of natural or free rotation or translation events and be different in each individual and structure (Adams, 1999). These events could obstruct the correct quantification of shape variation by adding rotation artifacts to GM analyses (Adams, Rohlf, & Slice, 2004). Thus, orientation of these structures needs to be corrected and standardized prior to performing shape analyses. Several approaches for shape analysis of landmark data in articulated structures already have previously been proposed (Adams, 1999;Bookstein, 1991). However, even though these approaches can be used in 2D and also in 3D data with further modifications, currently, it has only been implemented in the two-dimensional space, such as in geomorph's function fixed.angle() (Adams et al., 2017).
Here, we present the R tool ShapeRotator: a simple geometric rigid rotation approach to study three-dimensional (3D) shape of articulated structures, or independent structures, within an organism. We describe a method that removes shape variation due to the effect of translation between independent structures and rotation generated by movement in an articulation, among others. Thus, our approach translates and rotates articulated (or even independent) structures in order to obtain a comparable dataset with all effects of random movement and rotations removed.
We apply this method to two landmark-based datasets for analyzing shape variation using geometric morphometrics: (A) two F I G U R E 1 Two structures in a simple-point articulation and a doublepoint articulation being rotated using simple.rotation() and double.rotation(), respectively. The structures depicted are a frog humerus and radioulna for the single-point articulation and a skull and a detached mandible for the double-point articulation simple.rotation() double.rotation() F I G U R E 2 (a) Application of a translation -translate()-and the 3D rigid rotation method simple.rotation() in a simple-point articulation (e.g., humerus and radioulna) for three different "specimens," by rotating articulated structures to a standardized position relative to each other. (b) Application of the translation -translate()-and the 3D rigid rotation method double.rotation() in a double-point articulation for three different "specimens" (e.g., skull and mandibles). (c) Rotation method exemplified for simple.rotation() by depicting the plane spanned by the already translated point p 0 and A. Please note that p 0 depicts the origin point (0, 0, 0). The rotated resulting point p M , landmarks B, C, D, E, and F, and angle θ T (desired angle between the two structures) are also depicted. (d) Rotation method exemplified for double.rotation(). Please note that as both structures are not attached for the double-point articulation example, they are both translated to p 0 , which depicts the origin point (0, 0, 0). The rotated resulting point p M , landmarks A, B, C, D, E, F, G, and H, and angles θ 1 , θ 2 , and θ T (desired angle between the two structures) are also depicted substructures in a single-point articulation and (B) two substructures in a double-point articulation (Figures 1 and 2a,b). We also provide the example dataset used in ShapeRotator (available in GitHub) to execute these two kinds of rigid rotations, which then allows geometric morphometric analyses to be performed in the two most commonly used 3D GM analytical software packages: geomorph (Adams et al., 2017) and MorphoJ (Klingenberg, 2011).
This method also will allow exporting of the rotated coordinates for posterior analyses in other software platforms, even outside of the field of geometric morphometrics. As the basis of this method lies upon rigidly spinning any structure defined by 3D coordinates, it could be used in any other shape analyses that use coordinate data, such as continuous surface meshes used in spherical harmonics (Shen, Farid, & McPeek, 2009). Our method is a convenient addition to the rapidly evolving tool kit of geometric morphometrics because it allows a more comprehensive exploration of morphological diversity through the gathering of shape data from complex 3D structures.

| ME THODOLOGY
We begin with a set of points P = p 0 , … ,p M ⊂ ℝ 3 . which represents a 3D object and are ordered so that p 0 represents the base point and p M represents the end point, by which we mean that this object has an axis starting from p 0 and ending at p M . Our goal was to rotate these points via a rigid motion so that the axis on which these two points sit is either on the X, Y, or Z-axis in ℝ 3 . Rotation of vectors in ℝ 3 is a well-known and easily resolved problem, and various formalisms exist in geometry. Thus, we translate our set of points P so that p 0 maps to the origin (0, 0, 0). This is a simple transformation T defined by: where each of the generating vectors is unit.
Let us fix our desired axis to which we rotate the object to be Let us describe this setup slightly more generally. For two vectors u,v ∈ ℝ 3 , the axis to the plane spanned by these two vectors is determined by a unit normal to the plane (there are two choices due to orientation), which we denote by N (u, v): where × is the cross product. The angle between these vectors is then where · is the dot (scalar) product between vectors. The rotation matrix about an axis w ∈ ℝ 3 , where w = (w 1 , w 2 , w 3 ) is a unit vector, of angle θ radians is given by the well-known matrix: Thus, to obtain a rotation matrix which is the rigid motion rotating the vector u to v in the plane spanned by u and v, we obtain the expression: Getting back to our original problem, we set v = p M and u = a, and then we have the rotated points: where R (p M , a) p i is the action of the matrix R (p M , a) on the vector It may be necessary to introduce a further constraint in the rotation. For instance, suppose a = (0, 1, 0) and there is a point p I , now rotated to r I via the method we describe, which should lie in the Yaxis. That is, we need to further rotate r I to a point r � I = ( * , * ,0). To do this, we simply rotate in the axis a, by an angle θ Y (r I ) = arctan ((r I ) 3 / (r I ) 1 ), where r I = ((r I ) 1 , (r I ) 2 , (r I ) 3 ). That is,

| Overview of the ShapeRotator package
Here, we illustrate the functions available within the ShapeRotator R tool and the basic steps required in order to successfully implement the rotation on a dataset of 3D coordinates. ShapeRotator allows the rigid rotation of sets of both landmarks and semilandmarks used in geometric morphometric analyses, enabling morphometric analyses of complex objects, articulated structures, or multiple parts within an object or specimen. This tutorial uses two example datasets: (A) two neighboring bones of the arm in a frog (humerus and radioulna), representing a single-point articulation example and (B) a skull and a mandible, representing a two-point articulation example (Figure 1).
The main steps required are as follows: (1)

| Importing a dataset
In the first example dataset (example A), we use two geometric morphometric datasets containing both landmarks and semilandmarks for two neighboring and articulated bones (humerus and radioulna) from a group of several species of frogs (details in Appendix S1), in tps format. We first import the datasets using the R package geomorph (Adams et al., 2017): library (devtools) install _ github("marta-vidalgarcia/ShapeRotator") library(geomorph) radioulna <-readland.tps("radioulna.tps", specID = "ID", readcurves = F) humerus <-readland.tps("humerus.tps", specID = "ID", readcurves = F) These two GM datasets (radioulna and humerus) will be rotated on different rotation axes in order to conform the aimed angle between them. This process is not exclusive to two neighboring structures, and thus, it could be performed for as many independent subunits as desired by choosing the different angles among different rotation axes and all the translation processes.
For more help on importing the GM datasets, please see Adams et al., (2017) and the associated help files. Please note that this method also works for semilandmarks as long as they have been equidistantly positioned prior to the translation and the rigid rotation. The same process is needed for the second example dataset (example B).

| Translating
During this step, each structure will be translated to the point of origin so that p 0 = (0,0,0); thus, the distance from the coordinates of landmark_a (A x , A y , A z ) is substracted from all the landmarks in all specimens, for example (N

| Fixing the rotation axis
In order to fix a rotation axis in a structure, we first need to select in our dataset two suitable landmarks for each structure which the rotation axis will go through landmarks A and B (for the first structure), and landmarks D and E (for the other structure). In the radi- to remove all articulation-related variation, including torsional rotations and mirroring artefacts, we need an extra landmark in each structure that shares at least one of their coordinates (but ideally two) with the distal landmark (e.g., y A = y B for the first structure, and z D = z E for the second). This extra landmark is needed for the simple reason that there is not enough information about the orientation of the structure with only two landmarks per structure, so even though the rigid rotation will work properly, it could position this structure in the wrong "mirroring" orientation ( Figure 2c). This orientation issue is corrected by adding landmark C. In this example, landmark C is the 17th landmark, while landmark F is the 107th landmark in the humerus dataset. We need to know which landmarks will be selected in both structures prior to the rotation process in order to insure that the rotation process will work properly.
Setting up landmarks that will be used in the rotation process of example B is very similar to example A, but it needs four landmarks for each structure instead of three, as it is a more complex articulation that requires two separate rotations per structure (Figure 2d).
Even though each of these rotations are calculated internally (only the four landmarks per structure and the desired angle between them need to be provided), it will be beneficial to choose landmarks that are spatially arranged in a way that facilitates the rotation process, and results in the rotating multistructure being placed in a biologically relevant angle between each substructure.
ShapeRotator will give a warning message if the landmarks chosen are not optimal.

| Rotating
In the rotation step, we will use the function simple.rotation ()

| Exporting
After the rotation process, we could either use the joined GM array in further analyses, visualize the resulting joined structure through geomorph (Adams et al., 2017), or we could also export it and save it in order to use it in another software, such as MorphoJ (Klingenberg, 2011). In this step, we will be using the function writeland.tps() in the R package geomorph (Adams et al., 2017) in order to save a tps file from the joined GM array: writeland.tps(A="joined _ arm", file = "joined _ arm. tps", scale = NULL)

| Other applications
Our method is an important addition to the tool kit of the geometric morphometrics field. It will facilitate the analyses of compound 3D morphological datasets in geometric morphometrics analyses but will also be useful outside of this field as it can be applied to any could be used to examine shape and size variation in different organisms' growth due to different nutritional treatments or to examine how different structures respond to injuries or surgery. It would be useful in paleontology or archeology when trying to quantify shape of different objects or organisms that might have been preserved in disarticulated pieces. Finally, we would like to include a word of caution on how the angle chosen between different substructures could produce different results. As common sense would suggest, the angle chosen should always be within the range of angles possible for that complex object, but in some cases, it might be necessary to perform the GM analysis on more than one angle to be sure that the results do not differ. In other cases, it might even be better to analyse substructures separately.

ACK N OWLED G M ENTS
We are grateful to two anonymous reviewers, Tom Semple, Zoe Reynolds, and Amit Kumar, for their helpful comments on the manuscript. JSK thank the Australian Research Council for ongoing support. LB was supported by the Knut and Alice Wallenberg foundation, KAW 2013.0322 postdoctoral program in Mathematics for researchers from outside Sweden, and from SPP2026 from the German Research Foundation (DFG). This was part of the PhD thesis of MVG.

CO N FLI C T O F I NTE R E S T
None declared.