[R-sig-Geo] Help to find a way to which voxel a point in space lies inside

Marcelino de la Cruz marcelino.delacruz at upm.es
Thu Jul 12 16:13:40 CEST 2012


Hi Gianni,

I don't know if I this is what you want but maybe would be based in 
something like this:

myPointsc <- apply(myPoints,2,cut, breaks=0:10, labels=paste("v", 
1:10, sep=""))
myPointsc <- apply(myPointsc,1,paste, collapse="")
 > myPoints[myPointsc=="v1v1v1",]
           [,1]      [,2]      [,3]
[1,] 0.8250876 0.9355083 0.1332186
[2,] 0.3455816 0.8866431 0.6895027
 > myPoints[myPointsc=="v1v1v2",]
      [,1] [,2] [,3]
 > myPoints[myPointsc=="v1v1v3",]
[1] 0.6749106 0.5506732 2.5559303
 >
etc


Cheers,

Marcelino





At 15:45 12/07/2012, gianni lavaredo wrote:
>Dear R users,
>I am trying to write a code that could efficiently determine which voxel a
>point in space lies inside. For example, I have a matix with x,y,z values:
>
>library(rgl)
>
>x = runif(500, 0, 10)
>y = runif(500, 0, 10)
>z = runif(500, 0, 10)
>
>myPoints <- matrix(c(x,y,z), ncol=3)
>plot3d(myPoints)
>
>
>Supposing I have a 3 dimensional cube in space (ex: 10 by 10 ), that is
>segmented into 1 by 1 smaller voxels.
>
>My3D <- array(0,dim=c(10,10,3))
>
>I would really appreciate suggestions to writing a very efficient code to
>determine which voxel index each of these points lie inside, especially in
>an optics to do a chunk-by-chunk analysis.
>
>Thanks for any help
>Gianni
>
>         [[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