[R-sig-Geo] Minimum bounding circle from cluster of points (Tina Cormier)

Robert J. Hijmans r.hijmans at gmail.com
Sun Jul 10 21:50:56 CEST 2016


Here is a solution using optimization

library(raster)
library(rgeos)

set.seed(7)
n <- 4
xy <- cbind(runif(n), runif(n))

f <- function(p) { max(pointDistance(rbind(p), xy, lonlat=FALSE)) }
p <- optim(colMeans(xy), f)
cc <- buffer(SpatialPoints(rbind(p$par)), width=p$value, quadsegs=45)

plot(cc)
points(xy, pch=20, cex=1.5)
points(rbind(p$par), pch='*', col='red', cex=3)
lines(rbind(p$par, c(p$par[1]+p$value, p$par[2])), col='blue', lwd=2, lty=2)
text(p$par[1]+0.5*p$value, p$par[2], paste("radius =", round(p$value,
2)), pos=3, cex=.85)
text(p$par[1], p$par[2], labels=paste0("(",paste(round(p$par, 2),
collapse=", "), ")"), pos=1, cex=.75)

Best, Robert

On Sun, Jul 10, 2016 at 6:01 AM, Michael Sumner <mdsumner at gmail.com> wrote:
> I also have a (much more simplistic) use of CGAL here, for a different
> algorithm but may help for seeing how to leverage it:
>
> https://github.com/mdsumner/cgalgris
>
> I've abandoned that now in favour of RTriangle, but still very interested
> in uses of CGAL with R if anyone knows any more.
>
> Cheers, Mike
>
> On Sun, Jul 10, 2016, 22:44 chris english <englishchristophera at gmail.com>
> wrote:
>
>> Mel,
>>
>> Not a full implementation, but indicator of how one might do,
>> https://rforge.net/rcgal/git.html, that Simon Urbanek styles : rcgal - R
>> interface to a (small) subset of CGAL,
>> and has inside (function) that takes arbitrary shape files and x/y to say
>> inside or not.
>>
>> CGAL is a darn fine library and I guess you'd pick and choose which parts
>> you'd wrap for your purposes.
>>
>> Chris
>>
>> On Sun, Jul 10, 2016 at 3:50 AM, Bacou, Melanie <mel at mbacou.com> wrote:
>>
>> > Interesting problem, it seems the exact approach is given by Fischer,
>> 2003
>> > and is implemented in a C++ CGAL package (see
>> >
>> http://stackoverflow.com/questions/9063453/how-to-compute-the-smallest-bounding-sphere-enclosing-other-bounding-spheres
>> > ).
>> >
>> > I haven't found any binding for R, but there's an implementation in
>> > PostGIS `ST_MinimumBoundingCircle()` (see
>> > http://postgis.net/docs/ST_MinimumBoundingCircle.html).
>> >
>> > Others might be more up to date.
>> > --Mel.
>> >
>> >
>> >
>> > On 7/9/2016 6:38 AM, Adrian Baddeley wrote:
>> >
>> >> Tina Cormier <TinaACormier at gmail.com> wrote:
>> >>
>> >> I'd like to create a circle around each cluster that is
>> >>> the smallest circle that would encompass all 4 points.
>> >>>
>> >> The circumcircle.
>> >>
>> >> Try the following:
>> >>
>> >> <https://dl.dropboxusercontent.com/u/72421241/test_subplotsToPlots.zip
>> ><
>> >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo>library(spatstat)
>> >>
>> >> circumcircle <- function(x, ...) {   UseMethod("circumcircle") }
>> >>
>> >> circumcircle.owin <- function(x, ...) {
>> >>    d2 <- fardist(x, ..., squared=TRUE)
>> >>    z <- where.min(d2)
>> >>    r <- sqrt(min(d2))
>> >>    w <- disc(centre=z, radius=r)
>> >>    return(w)
>> >> }
>> >>
>> >> circumcircle.ppp <- function(x, ...) {
>> >>    circumcircle(convexhull(x))
>> >> }
>> >>
>> >>
>> >> Adrian Baddeley
>> >>
>> >>         [[alternative HTML version deleted]]
>> >>
>> >> _______________________________________________
>> >> R-sig-Geo mailing list
>> >> R-sig-Geo at r-project.org
>> >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> >>
>> >
>> > _______________________________________________
>> > R-sig-Geo mailing list
>> > R-sig-Geo at r-project.org
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> >
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
> --
> Dr. Michael Sumner
> Software and Database Engineer
> Australian Antarctic Division
> 203 Channel Highway
> Kingston Tasmania 7050 Australia
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list