lib/sphere/positions.js
function centroid(buf, b, ...p) {

  var n = p.length / 2;

  var sum_x = 0,
      sum_z = 0,
      sum_y = 0;

  for (let i = 0; i < n; i += 1) {

    let i_φ = p[2 * i + 0],
        i_λ = p[2 * i + 1];

    sum_x += cos(i_φ) * cos(i_λ);
    sum_z += cos(i_φ) * sin(i_λ);
    sum_y += sin(i_φ);

  }

  var x = sum_x / n,
      z = sum_z / n,
      y = sum_y / n;

  var r = sqrt(
    x * x + z * z + y * y
  );

  var φ = asin(y / r),
      λ = atan2(z, x);

  buf[b + 0] = φ;
  buf[b + 1] = λ;

}
function centroid(buf, b, ...p) {

  var n = p.length / 2;

  var sum_x = 0,
      sum_z = 0,
      sum_y = 0;

  for (let i = 0; i < n; i += 1) {

    let i_φ = p[2 * i + 0],
        i_λ = p[2 * i + 1];

    sum_x += cos(i_φ) * cos(i_λ);
    sum_z += cos(i_φ) * sin(i_λ);
    sum_y += sin(i_φ);

  }

  var x = sum_x / n,
      z = sum_z / n,
      y = sum_y / n;

  var r = sqrt(
    x * x + z * z + y * y
  );

  var φ = asin(y / r),
      λ = atan2(z, x);

  buf[b + 0] = φ;
  buf[b + 1] = λ;

}
Populates buffer `buf` from offset `b` with the center point of positions provided

@param buf - buffer in which to store the result
@param b - offset in `buf` from which to begin storing the result
@param p - an even number of remaining arguments as pairs of coordinates for each position