#' move the centroid of a mesh to a given coordinate
#'
#' move the centroid of a mesh to a given coordinate
#' @param x triangular mesh of class 'mesh3d'
#' @param center coordinate where to translate the mesh, if center=NULL the centroid will be moved to the origin
#'
#' @return returns the translated mesh
#' @examples
#'
#' require(Rvcg)
#' data(humface)
#' \dontrun{
#' require(rgl)
#' wire3d(humface, col=3)
#' }
#' humcenter <- centermesh3d(humface)
#' #view translated mesh
#' \dontrun{
#' require(rgl)
#' wire3d(humcenter, col=2)
#' }
#' @export centermesh3d
centermesh3d <- function(x,center=NULL)
{
bary <- apply(vert2points(x),2,mean)
if (is.null(center))
center <- c(0,0,0)
x$vb[1:3,] <- x$vb[1:3,]- (bary-center)
invisible(x)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.