Skip to content

Instantly share code, notes, and snippets.

@sandeepraju
Created January 2, 2015 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandeepraju/7b3b8c79e0331bbf5834 to your computer and use it in GitHub Desktop.
Save sandeepraju/7b3b8c79e0331bbf5834 to your computer and use it in GitHub Desktop.
Average distance travel to access the dustbin
# author - @edbidangi
# https://twitter.com/edbidangi/status/550997127074045952
library(rgl)
dist <- function(x1, y1, x2, y2) {
return(sqrt( (x2 - x1)**2 + (y2 - y1)**2 ))
}
width = 20
height = 20
distances = matrix(nrow = height, ncol = width)
x <- 1:width
y <- 1:height
z <- c()
for(selectedX in x) {
for(selectedY in y) {
sum = 0
for(varX in x) {
for(varY in y) {
sum <- sum + dist(varX, varY, selectedX, selectedY)
}
}
z <- c(z, sum)
}
}
persp3d(x, y, z, col="skyblue")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment