# grid_metrics3d

##### Voxelize the space and compute metrics for each voxel

This is a 3D version of grid_metrics. It creates a 3D matrix of voxels with a given resolution. It creates a voxel from the cloud of points if there is at least one point in the voxel. For each voxel the function allows computation of one or several derived metrics in the same way as the grid_metrics functions. The function will dispatch the LiDAR data for each voxel in the user's function (see grid_metrics).

##### Usage

`grid_metrics3d(las, func, res = 1)`

##### Arguments

- las
An object of class

`LAS`

.- func
expression. The function to be applied to each voxel (see also grid_metrics).

- res
numeric. The resolution of the voxels.

`res = 1`

for a 1x1x1 cubic voxels. Optionally`res = c(1,2)`

for non-cubic voxels (1x1x2 cuboid voxel).

##### Value

It returns a `data.table`

containing the metrics for each voxel. The table
has the class `lasmetrics3d`

enabling easier plotting.

##### Examples

```
# NOT RUN {
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las = readLAS(LASfile)
# Cloud of points is voxelized with a 3-meter resolution and in each voxel
# the number of points is computed.
grid_metrics3d(las, length(Z), 3)
# Cloud of points is voxelized with a 3-meter resolution and in each voxel
# the mean scan angle of points is computed.
grid_metrics3d(las, mean(ScanAngle), 3)
# }
# NOT RUN {
# Define your own metric function
myMetrics = function(i, angle)
{
ret = list(
npoints = length(i),
angle = mean(angle),
imean = mean(i)
)
return(ret)
}
voxels = grid_metrics3d(las, myMetrics(Intensity, ScanAngle), 3)
plot(voxels, color = "angle")
plot(voxels, color = "imean")
#etc.
# }
```

*Documentation reproduced from package lidR, version 2.0.0, License: GPL-3*