Create a 3-D occupancy map.
Specify 25 random coordinates in the occupancy map as occupied.
Create a collision sphere and a collision cylinder object.
Visualize the occupancy map and collision geometry in the same figure.
Perform only the broad-phase collision check for both the sphere and cylinder by setting the CheckNarrowPhase
property of an occupancyMap3DCollisionOptions
object to false
. Return voxel information and the distance to the nearest occupied voxels.
Check the voxel distances for the collision geometries. Note that, because the cylinder is in collision with voxels, the distance values are NaN
. Because the sphere is not in collision with any voxels, its distance results are non-NaN
values.
bpWitnessptsCylinder = 3×2
NaN NaN
NaN NaN
NaN NaN
Because the cylinder is in collision with the voxels, the distance results contain NaN
values. Since the sphere is not in collision with the voxels, the distance results consist of non-NaN
values.
bpWitnessptsSphere = 3×2
3.0000 5.1000
-6.0000 -5.0000
-7.5000 -7.5000
Plot a line between the sphere and the closest voxel to it using its witness points.
Now perform a narrow-phase check, by using an occupancyMap3DCollisionOptions
object with the CheckNarrowPhase
property set to true
.
Return the voxel distance and witness point coordinates for the sphere. The distance and witness points are slightly more accurate this time, because the narrow phase uses the distance between the primitive and the voxel, whereas the broad phase before uses the distance between the axis-aligned bounding box (AABB) of the collision object and the voxel.
npWitnesspts = 3×2
3.0000 5.2596
-6.0000 -4.5419
-7.5000 -7.5000
Visualize the occupancy map again and plot line showing the shortest distance between the voxel and sphere. The line between the witness points visually appears accurate after performing the narrow-phase check.