r - Divide 3D space into smaller cubes -
i have set of points in 3d. want split entire volume occupied points 128x128x128 number of cubes. , want count number of points in each cube. can suggest how in r?
i have tried rgb , scatterplot3d packages did not find solution there. also, need color these cubes in accordance numbers. please suggest how go it.
although not influence solution, info not symmetrically spread in directions. split quantity: max(x,y,z) 128 border length of each cube.
thank you.
if sure want do, here's attempt.
dat <- as.data.frame(replicate(3, runif(10000))) # toy info n <- 3 # set 128, number of cubes in each direction cut_dat <- lapply(dat, cut, breaks = seq(0, 1, l = n + 1)) # break cubes do.call(table, cut_dat) # cross tabulate count #, , v3 = (0,0.333] # # v2 #v1 (0,0.333] (0.333,0.667] (0.667,1] # (0,0.333] 383 361 379 # (0.333,0.667] 362 382 371 # (0.667,1] 389 358 370 # #, , v3 = (0.333,0.667] # # v2 #v1 (0,0.333] (0.333,0.667] (0.667,1] # (0,0.333] 345 383 372 # (0.333,0.667] 374 388 381 # (0.667,1] 383 368 373 # #, , v3 = (0.667,1] # # v2 #v1 (0,0.333] (0.333,0.667] (0.667,1] # (0,0.333] 342 355 360 # (0.333,0.667] 386 386 374 # (0.667,1] 346 372 357
so 3d array counts. have reduced number of cubes 3 in each direction display concept.
edit: gavin kelly's suggestion can done here
table(cut_dat[[1]]:cut_dat[[2]]:cut_dat[[3]])
to info representation.
or more human readable:
tab2 <- expand.grid(lapply(cut_dat, levels)) tab2$freq <- table(cut_dat[[1]]:cut_dat[[2]]:cut_dat[[3]]) head(tab, n = 4) # v1 v2 v3 freq #1 (0,0.333] (0,0.333] (0,0.333] 374 #2 (0.333,0.667] (0,0.333] (0,0.333] 379 #3 (0.667,1] (0,0.333] (0,0.333] 384 #4 (0,0.333] (0.333,0.667] (0,0.333] 377
r 3d
No comments:
Post a Comment