Convex hull

Share:

Description

Plotting the convex hall for given 2D datasets.

Usage

1
2
	Plot_ConvexHull(xcoord, ycoord, lcolor)
	

Arguments

xcoord

coordinate for the horizontal axis.

ycoord

coordinate for the vertical axis.

lcolor

color of the convect hull.

Details

This function uses the base function chull(), which takes x,y coordinates of data and outputs a vector(hpts variable) of integers that indicate the points in dataset that comprise the convex hull around data. It then uses the base function lines to draw the convex hull using the x,y coordinates stored in hpts.

Value

The convex hull plot for a set of 2D points.

Author(s)

Ken Takagi

References

https://chitchatr.wordpress.com/2011/12/30/convex-hull-around-scatter-plot-in-r/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
	# Create a set of random data to plot convex hull around
	x<-rnorm(100,0.8,0.3)
	y<- rnorm(100,0.8,0.3)
	#get max and min of all x and y data for nice plotting
	xrange<-range(x)
	yrange<-range(y)
	#plot it up!
	plot(x,y,type="p",pch=1,col='black',xlim=c(xrange),ylim=c(yrange))
	Plot_ConvexHull(xcoord=x,ycoord=y,lcolor='red')