Nonconvexity, and playing indoor paintball
[This article was first published on Freakonometrics - Tag - R-english, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Following the two previous posts (here and there), on the number of people that don’t get wet while playing with water pistols, consider now an indoor version, in a non-convex room (i.e. player behind wall are now, somehow, protected). In the previous posts, players where playing on a square field, and I briefly mentioned that if the field was a disk, results would have been (roughly) the same: so far, the shape of the field was not an issue. But what if the field is no longer convex,
library(sp) plot(0:2,0:2,col="white",xlab="",ylab="") MAP=Polygon(cbind(c(0,0,1,1,2,2,0), c(0,2,2,1,1,0,0))) polygon(MAP@coords,col="light blue")
Once again, it is possible to look more closely are those supposed-to-be “safe zones”, i.e. by looking at the distribution of the location of players that were dry at the end of the game. With 11 players, we obtain
What about the distribution of the number of dry players, over a game ?
touch=function(x1,y1,x2,y2,n=251){ X=seq(x1,x2,length=n) Y=seq(y1,y2,length=n) sum(point.in.polygon(X,Y,MAP@coords[,1], MAP@coords[,2], mode.checked=FALSE)==0)==0 } NOTWETnc=function(n,p){ sx=runif(50)*2;sy=runif(50)*2 IN=which(point.in.polygon(sx,sy,MAP@coords[,1], MAP@coords[,2], mode.checked=FALSE)==1) Sx=sx[IN];Sy=sy[IN] Sx=Sx[1:n];Sy=Sy[1:n] IN=IN[1:n] MI=matrix(NA,n,n) for(i in 1:(n-1)){ for(j in (i+1):(n)){ MI[j,i]=MI[i,j]=touch(Sx[i],Sy[i],Sx[j],Sy[j]) }} (d=as.matrix(dist(cbind(Sx,Sy), method = "euclidean",upper=TRUE))) diag(d)=999999 dpossible=d dpossible[MI==FALSE]=999999 dmin=apply(dpossible,2,which.min) #whonotwet=( (1:n) %notin% names(table(dmin)) ) notwet=n-length(table(dmin)) return(notwet)} NOTWET=function(n){ x=runif(n) y=runif(n) (d=as.matrix(dist(cbind(x,y), method = "euclidean",upper=TRUE))) diag(d)=999999 dmin=apply(d,2,which.min) notwet=n-length(table(dmin)) return(notwet)} NSim=10000 Nnc=Vectorize(NOTWETnc)(n=rep(11,NSim)) Nc=Vectorize(NOTWET)(n=rep(11,NSim)) T=table(Nc) Tn=table(Nnc) plot(as.numeric(names(Tn)), Tn/NSim,type="b",col="blue") lines(as.numeric(names(T)), T/NSim,type="b",col="red",pch=4)
On 11 players, we have the same distribution as the one on a square field. So convexity is not a key issue here…
Strange isn’t it. And with an odd number of player, not only there is at least one dry player, but at least, half of the players (maybe minus one) have to be wet…
To leave a comment for the author, please follow the link and comment on their blog: Freakonometrics - Tag - R-english.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.