Dear Marcelino,

I find this solution. It's not elegant but works

library(rgl)

# create Random Points in x,y, and z
x = runif(1000, 0, 10)
y = runif(1000, 0, 10)
z = runif(1000, 0, 10)

myPoints <- matrix(c(x,y,z), ncol=3)
plot3d(myPoints)

# Empty array of 1000 voxels in total with of 1 by 1. Each array is a layer
of 10 x 10 x 1
MyVoxel3D <- array(0,dim=c(10,10,10))

MyVoxel3D[myPoints[1,1],myPoints[1,2],myPoints[1,3]] <- 1

for(i in 2:nrow(myPoints)){
    xp <- myPoints[i,1]
    yp <- myPoints[i,2]
    zp <- myPoints[i,3]

    if(sum(MyVoxel3D[xp,yp,zp]) >= 1 ){
        MyVoxel3D[xp,yp,zp] <- sum(MyVoxel3D[xp,yp,zp]) + 1

    } else {
        MyVoxel3D[xp,yp,zp] <- 1
    }
}

print(MyVoxel3D*)*

Now i need to find a function as

http://www.mathworks.com/matlabcentral/fileexchange/28497-plot-a-3d-array-using-patch

to plot my array

Gianni





On Thu, Jul 12, 2012 at 5:16 PM, Marcelino de la Cruz <
marcelino.delacruz@upm.es> wrote:

>
>
> And what about this? (inspired vby spatstat::quadratcount)
>
>
>
> set.seed(2012)
>
> x = runif(500, 0, 10)
> y = runif(500, 0, 10)
> z = runif(500, 0, 10)
>
>
> xbreaks <- ybreaks<- zbreaks <- 0:10
> xg <- cut(x, breaks = xbreaks, include.lowest = TRUE)
> yg <- cut(y, breaks = ybreaks, include.lowest = TRUE)
> zg <- cut(z, breaks = zbreaks, include.lowest = TRUE)
>
> sumz <- table(list(z=zg, y = yg, x = xg))
>
> sumz
>
> Cheers,
>
> Marcelino
>
>
>
> At 16:30 12/07/2012, gianni lavaredo wrote:
>
> Thanks Marcelino,
>
> I looking your solution, and it's smart. What i wish to do is divide my 10
> by 10 box in 10x10x10 bins (or voxels) and see the number of point drops in
> each voxel. In the end I wish to try to plot the voxel (transparent = empy,
> black = not empty, or grey scale in base of the number inside) because I
> wish to recreate the object in the space.
>
> (in words is easy) what i wish to do is create a voxel index and say how
> much points are inside in the voxel.
>
> Always thanks for your suggestions and really appreciate solution
> Gianni
>
>
>
>
> On Thu, Jul 12, 2012 at 4:13 PM, Marcelino de la Cruz <marcelino.delacruz@upm.es>
> wrote:
>  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@r-project.org
>  https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>

	[[alternative HTML version deleted]]

