R/scale_volume.R

Defines functions scale_volume

Documented in scale_volume

#' Re-scale mesh based on a fixed volume of 1
#'
#' @param mesh A triangular mesh of class mesh3d.
#'
#' @return A mesh with volume = 1.
#' @export
#'
#' @examples
#' Rvcg::vcgVolume(mcap)
#' mcap_scaled <- scale_volume(mcap)
#' Rvcg::vcgVolume(mcap_scaled)

scale_volume <- function(mesh){
  vol <- suppressWarnings(Rvcg::vcgVolume(mesh))
  XYZCoords <- t(mesh$vb[1:3,])
  XYZCoordsTwo <- XYZCoords/(vol^(1/3))
  mesh_scaled <- mesh
  mesh_scaled$vb[1:3,] <- t(XYZCoordsTwo)
  return(mesh_scaled)
}

Try the habtools package in your browser

Any scripts or data that you put into this service are public.

habtools documentation built on May 29, 2024, 7:30 a.m.