Skip to content
Prev 24263 / 29559 Next

Drawing the maximum-area rectangle in a non-convex polygon

I've implemented this as a package now. Its on my gitlab account:

https://gitlab.com/b-rowlingson/maxrectangle

and you can install it with devtools.

And here's the example

Create a new JS context:

##' ctx = initjs()

Make a polygon:

##' th = seq(0,2*pi,len=11)[-11]
##' r = runif(10)
##' xy = cbind(r*cos(th), r*sin(th))
##' xy = rbind(xy, xy[1,])

Plot it:

##' plot(xy, type="l")

Call the JS:

##' lr = find_lr(ctx, xy)

Convert the return value and plot:

##' pp = plotrect(lr[[1]])
##' lines(pp)

At the moment the options to the JS, which sets things like number of
iterations and thresholds for deciding its found the biggest
rectangle, are ignored. So often you'll get a rectangle and go "Hey,
it could be a bit bigger!" which you might not get if you could tweak
the options a bit. If anyone wants to write code to pass the options
into the JS, pull requests are welcome.

I'm not sure what the license on the coffee script code is, I think
its BSD, which means its okay to use this like this. Will investigate.

Incidentally, the V8 package is a very slick interface to JS from R. Impressed.



Barry


On Wed, Apr 13, 2016 at 12:51 PM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote: