## ShapeRotator - an R tool for standardised rotations of 3D structures

Welcome to the ShapeRotator Wiki!

In this Wiki I 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.

In this Wiki I 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.

**Citation: M. Vidal-García, L. Bandara and J.S. Keogh. ShapeRotator: An R tool for standardized rigid rotations of articulated three-dimensional structures with application for geometric morphometrics. Ecology and Evolution.**

*In press.*DOI: 10.1002/ece3.4018

You can download the ShapeRotator R file from the right, and then call:

**ShapeRotator R code:**You can download the ShapeRotator R file from the right, and then call:

**source('ShapeRotator.R')** shaperotator.r | |

File Size: | 22 kb |

File Type: | r |

You can also download an example file for

**and***simple.rotation()**double.rotation()* example_simple_rotation.r | |

File Size: | 0 kb |

File Type: | r |

example_double_rotation.r | |

File Size: | 3 kb |

File Type: | r |

Alternatively, you can install the ShapeRotator R-tool from Github using devtools:

**install.packages("devtools")**

library(devtools)

install _ github(“marta-vidalgarcia/ShapeRotator”)

library(devtools)

install _ github(“marta-vidalgarcia/ShapeRotator”)

**Importing a dataset:**

We first import the two datasets to joing using the R package

*geomorph:*

**library(geomorph)**

For example, if we wanted to import a tps file we would do the following:

**data_1 <- readland.tps(“data_1.tps”, specID = “ID”, readcurves = F)**

data_2 <- readland.tps(“data_2.tps”, specID = “ID”, readcurves = F)

data_2 <- readland.tps(“data_2.tps”, specID = “ID”, readcurves = F)

For more help on importing the GM datasets, please see Adams et al. (2017) and the associated help files in

*geomorph*. Please note that this method also works for semilandmarks.

**Selecting landmarks and rotation axes:**

You will need to select different number of landmarks and the associated rotation axes depending on whether you would like to perform a simple.rotation() OR a double.rotation()

For simple.rotation() each structure needs to have three selected landmarks: landmarks A, B, C for data_1 and landmarks D, E, F for data_2. For double.rotation() we will need an extra landmark (landmarks A, B, C, D for data_1 and landmarks E, F, G, H for data_2).

**Translating:**

During this step, each structure will be translated to the point of origin so that ̃p0 =(0,0,0); thus, the distance from the coordinates of landmark A (Ax, Ay, Az) is substracted from all the landmarks in all specimens, for example (Nx − Ax, Ny – Ay, Nz – Az) for landmark N. This translation is made with the function

*translate*().

__Translation for a single-point articulated structure__:For the first dataset:

**data.1_t <- translate (T = data_1, landmark = landmark_A)**

For the second dataset:

**data.2_t <- translate (T = data_2, landmark = landmark_D)**for the

*simple.rotation()*

__Translation for a double-point articulated structure__:For the first dataset:

**data.1_t <- translate (T = data_1, landmark = landmark_A)**

For the second dataset:

**data.2_t <- translate (T=data_2, landmark = landmark_E)**for the

*double.rotation()*

Please note that the default is to set the origin point to, but this can be changed to another origin point. For example, to the point c(1, 3, 5):

**data.1 _ t <- translate (T=data _ 1, landmark=landmarkA, origin = c(1,3,5))**

data.2 _ t <- translate (T=data _ 2, landmark=landmarkD, origin = c(1,3,5))

data.2 _ t <- translate (T=data _ 2, landmark=landmarkD, origin = c(1,3,5))

**Rotating the translated datasets**

**Simple rotation**Rotation method exemplified for simple.rotation() by depicting the plane spanned by the already translated point p0 and A. Please note that p0 depicts the origin point (0, 0, 0). The rotated resulting point pM, landmarks B, C, D, E, and F, and angle θT (desired angle between the two structures) are also depicted:

In the rotation step, we will use the function simple.rotation() in order to rigidly rotate the two structures of example A to the desired angle (in degrees), as it follows:

**joined_dataset <- simple.rotation(data.1 = data.1_t, data.2 = data.2_t, land.a = 10, land.b=1, land.c=17, land.d=52, land.e=19, land.f=107, angle = 90)**

The input datasets data.1 and data.2 correspond to the two translated datasets. We then use the selected landmarks as explained in the previous section. Finally, we include the angle (in degrees) that we would like to use to position the two structures to one another.

**Double rotation***in prep*

**Exporting the rotated (and joined) datasets**

*in prep*