Main Content


Create 3-D occupancy map


The occupancyMap3D class stores a 3-D map and map information. The map is stored as probabilistic values in an octree data structure. The class handles arbitrary environments and expands its size dynamically based on observation inputs. You can add observations as point clouds or as specific xyz locations. These observations update the probability values. Probabilistic values represent the occupancy of locations. The octree data structure trims data appropriately to remain efficient both in memory and on disk.



omap = occupancyMap3D creates an empty 3-D occupancy map with no observations and default property values.


omap = occupancyMap3D(res) specifies a map resolution in cells/meter and sets the Resolution property.

omap = occupancyMap3D(res,Name,Value) creates an object with additional options specified by one or more Name,Value pair arguments. For example, 'FreeThreshold',0.25 sets the threshold to consider cells obstacle-free as a probability value of 0.25. Enclose each property name in quotes.


expand all

Grid resolution in cells per meter, specified as a scalar. Specify resolution on construction. Inserting observations with precisions higher than this value are rounded down and applied at this resolution.

Threshold to consider cells as obstacle-free, specified as a positive scalar. Probability values below this threshold are considered obstacle-free.

Threshold to consider cells as occupied, specified as a positive scalar. Probability values above this threshold are considered occupied.

Saturation limits on probability values, specified as a [min max] vector. Values above or below these saturation values are set to the min or max values. This property reduces oversaturating of cells when incorporating multiple observations.

Object Functions

checkOccupancyCheck if locations are free or occupied
getOccupancyGet occupancy probability of locations
inflateInflate map
insertPointCloudInsert 3-D points or point cloud observation into map
rayIntersectionFind intersection points of rays and occupied map cells
setOccupancySet occupancy probability of locations
showShow occupancy map
updateOccupancyUpdate occupancy probability at locations


collapse all

The occupancyMap3D object stores obstacles in 3-D space, using sensor observations to map an environment. Create a map and add points from a point cloud to identify obstacles. Then inflate the obstacles in the map to ensure safe operating space around obstacles.

Create an occupancyMap3D object with a map resolution of 10 cells/meter.

map3D = occupancyMap3D(10);

Define a set of 3-D points as an observation from a pose [x y z qw qx qy qz]. This pose is for the sensor that observes these points and is centered on the origin. Define two sets of points to insert multiple observations.

pose = [ 0 0 0 1 0 0 0];

points = repmat((0:0.25:2)', 1, 3);
points2 = [(0:0.25:2)' (2:-0.25:0)' (0:0.25:2)'];
maxRange = 5;

Insert the first set of points using insertPointCloud. The function uses the sensor pose and the given points to insert observations into the map. The colors displayed correlate to the height of the point only for illustrative purposes.


Figure contains an axes. The axes with title Occupancy Map contains an object of type patch.

Insert the second set of points. The ray between the sensor pose (origin) and these points overlap points from the previous insertion. Therefore, the free space between the sensor and the new points are updated and marked as free space.


Figure contains an axes. The axes with title Occupancy Map contains an object of type patch.

Inflate the map to add a buffer zone for safe operation around obstacles. Define the vehicle radius and safety distance and use the sum of these values to define the inflation radius for the map.

vehicleRadius = 0.2;
safetyRadius = 0.3;
inflationRadius = vehicleRadius + safetyRadius;
inflate(map3D, inflationRadius);


Figure contains an axes. The axes with title Occupancy Map contains an object of type patch.


expand all


[1] Hornung, Armin, Kai M. Wurm, Maren Bennewitz, Cyrill Stachniss, and Wolfram Burgard. "OctoMap: an efficient probabilistic 3D mapping framework based on octrees." Autonomous Robots, Vol. 34, No. 3, 2013, pp. 189–206.. doi:10.1007/s10514-012-9321-0.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2019b