R/centroid.R

Defines functions centroid

Documented in centroid

#' Calculate the centroid of 3D points
#'
#' @description
#' Calculates the centroid for a given set of XYZ coordinates.
#'
#' @param data A data frame with x, y, and z coordinates.
#'
#' @return The coordinates of the centroid.
#' @export
#'
#' @examples
#' data <- mesh_to_points(mcap)
#' centroid(data)

centroid <- function(data) {
  xmean <- mean(data[,1])
  ymean <- mean(data[,2])
  zmean <- mean(data[,3])
  return(c(xmean, ymean, zmean))
}

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.