MomX / Momocs

:dove: Morphometrics using R
http://momx.github.io/Momocs/
51 stars 18 forks source link

coo_length #206

Closed bischrob closed 5 years ago

bischrob commented 5 years ago

I can't figure out how the length of this outline is calculated. The length should be 30.9, but coo_length shows it as 33.4. Most of the outlines I've checked are correct. Here's a reproducible example.

library(Momocs)
# simplified outline
d <- structure(list(coo = list(shp1 = structure(c
  (-4.82513792201646, 
  -5.10056165083002, -6.73191758303341, -8.70225656608426, -9.8675108033724, 
  -10.2064938542199, -10.2700531762538, -11.371748091508, -11.6683582609995, 
  -12.3039514813385, -12.4734430067622, -12.007341311847, -10.4183582609995, 
  -10.3971718203215, -10.1853074135419, -8.91412097286392, -8.70225656608426, 
  -8.51157859998257, -8.15140910845714, -7.62174809150799, -7.60056165083002, 
  -7.21920571862663, -6.47768029489782, -6.09632436269443, -2.21920571862663, 
  -1.0539514813385, 1.19181123052591, 2.14520106103438, 5.09011631527167, 
  5.28079428137337, 5.42909936611913, 6.06469258645811, 6.34011631527167, 
  6.91215021357676, 8.03503156950896, 8.14096377289879, 8.16215021357676, 
  8.43757394239032, 8.43757394239032, 8.79774343391574, 8.8189298745937, 
  9.53926885764455, 9.87825190849201, 10.6409637728988, 10.7468959762886, 
  9.87825190849201, 9.49689597628862, 6.25537055255981, 4.26384512883099, 
  0.958760383068282, 0.508474576271185, 0.48728813559322, 0.360169491525424, 
  0.0423728813559308, 0.10593220338983, 0.0423728813559308, 0.0423728813559308, 
  0.0635593220338979, 0.0847457627118633, 0.466101694915254, 0.826271186440676, 
  4.68220338983051, 8.05084745762712, 8.34745762711864, 9.40677966101695, 
  11.2923728813559, 12.1610169491525, 13.5169491525424, 14.1313559322034, 
  14.9152542372881, 14.9364406779661, 15.5720338983051, 16.8008474576271, 
  17.2457627118644, 24.4915254237288, 26.228813559322, 30.2118644067797, 
  30.9533898305085, 26.1016949152542, 24.1101694915254, 23.1567796610169, 
  21.7584745762712, 20.8050847457627, 19.6610169491525, 17.2245762711864, 
  16.3983050847458, 16.1016949152542, 13.7923728813559, 13.7076271186441, 
  10.2542372881356, 10.1059322033898, 6.77966101694915, 5.59322033898305, 
  3.05084745762712, 2.5, 1.3135593220339, 0.932203389830507, 0.572033898305085, 
  0.381355932203389, 0.444915254237287),
  .Dim = c(50L, 2L))), fac = structure(list(),
  .Names = character(0), row.names = integer(0),
  class = c("tbl_df", 
  "tbl", "data.frame")), ldk = list()), class = c("Out", "Coo"))
d  %>% coo_length()
# this is how it seems coo_length is calculated, but the output is different
d <- apply(d[1], 2, range)
abs(d[2, ] - d[1, ])
vbonhomme commented 5 years ago

from Momocs:::coo_length.default that leads to Momocs:::coo_lw.default you can see that there is an align step and this may lead to the confusion here? What is returned by coo_length/coo_lw is actually "measured" using range on this shape:

image

which may be troublesome with bilateral shapes. Perhaps you may want to try ?coo_calliper, or set landmarks and then use ?d

bischrob commented 5 years ago

Thank you for your response. I didn't see the align step in the underlying code, and I was trying to get the length as I had oriented the object.