R/is.clockwise.R

is.clockwise = function(p) {
  # Uses the shoelace formula to determine whether or not the
  # vertices of a polygon are arranged clockwise
  area = 0
  for(i in 1:nrow(p)) {
    j = i %% nrow(p) + 1
    area = area + p[i,1]*p[j,2]
    area = area - p[j,1]*p[i,2]
  }
  return (area < 0)
}

Try the eggs package in your browser

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

eggs documentation built on May 2, 2019, 5:23 p.m.