Learn R Programming

contoureR (version 1.0.5)

convexHullAM: Convex Hull via Andrews Monotone, Rcpp Interface to C++ Routine

Description

This function is the R interface to the C++ implementation of Andrews Monotone, a well known algorithm for solving the convex hull in O(nlogn) time complexity.

Usage

convexHullAM_Indexes(x, y, includeColinear=FALSE,zeroBased = TRUE) convexHullAM_Points(x, y,includeColinear=FALSE)

Arguments

x
NumericVector of x values
y
NumericVector of y values
includeColinear
whether to inlude points that line ON the hull, by default this is set to FALSE, as this is the true definition of the convex hull.
zeroBased
Whether the return indexes should be zero based (true, for use in C++), or One-Based (false, for use in R).

Value

convexHullAM_Indexes returns an integer vector of the indexes of the points, whilst convexHullAM_Points returns an n x 2 matrix of the points themselves.

Examples

Run this code
library(contoureR)
library(ggplot2)
set.seed(1)
x  = runif(100)
y  = runif(100)
ch = convexHullAM_Indexes(x,y,includeColinear=FALSE,zeroBased = FALSE)
ggplot(data.frame(x,y),aes(x,y)) +
 geom_point() +
 geom_path(data=data.frame(x,y)[ch,],colour="red")

Run the code above in your browser using DataLab