Skip to content

Instantly share code, notes, and snippets.

@pontikos
Last active January 4, 2016 07:19
Show Gist options
  • Select an option

  • Save pontikos/dc0d405ae0c2fa830960 to your computer and use it in GitHub Desktop.

Select an option

Save pontikos/dc0d405ae0c2fa830960 to your computer and use it in GitHub Desktop.
Draw convex hull around points
testpts <- structure(list(x = c(4.9, 4.2, 4, 4.1, 4.4, 5.8, 5.8, 5.8, 5.8,
5.5, 4.9, 3.2, 3.2, 3.3, 5.4, 5.4, 5.7, 6.4, 6.7, 6.7, 6, 4.8,
3.6, 2.8, 3.5, 4.4, 5.1, 4, 3.7, 4.5, 4.9, 5.7), y = c(6.9, 6.2,
5.3, 4.1, 3.1, 2.9, 2.9, 3.5, 4.2, 4.9, 5.1, 4.9, 4.9, 5.2, 6.9,
6.9, 5.3, 3.8, 4.2, 5.6, 6.9, 5.8, 1.2, 2.5, 5.3, 6.4, 6.8, 7.6,
6.9, 5.4, 4.8, 4.4)), .Names = c("x", "y"))
x <- do.call('cbind',testpts)
ch<-chull(x)
plot(x,pch=20)
points(x[ch,],pch=20,col='red')
lines(x[c(ch,ch[1]),],lwd=.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment