Create convex mesh collision geometry
collisionMesh to create a collision geometry as a convex
Vertices — Vertices
3-D real-valued array
Vertices of a mesh, specified as an N-by-3 array, where
N is the number of vertices. Each row of
Vertices represents the coordinates of a point in 3-D space. Note
that some of the points can be inside the constructed convex mesh.
Pose — Pose
eye(4) (default) | real-valued matrix
Pose of the collision geometry relative to the world frame, specified as a 4-by-4 homogeneous matrix. You can change the pose after you create the collision geometry.
|Show collision geometry|
Create and Visualize Mesh Collision Geometry
Create an array consisting of the coordinates of ten points randomly chosen on the unit sphere. For reproducibility, set the random seed to the default value.
rng default n = 10; pts = zeros(n,3); for k = 1:n ph = 2*pi*rand(1); th = pi*rand(1); pts(k,:) = [cos(th)*sin(ph) sin(th)*sin(ph) cos(ph)]; end
Create a convex mesh collision geometry from the array. Visualize the collision geometry.
m = collisionMesh(pts); show(m)
Create a second array similar to the first, but this time consisting of 1000 points randomly chosen on the unit sphere.
n = 1000; pts2 = zeros(n,3); for k = 1:n ph = 2*pi*rand(1); th = pi*rand(1); pts2(k,:) = [cos(th)*sin(ph) sin(th)*sin(ph) cos(ph)]; end
Create and visualize a mesh collision geometry from the array. Observe that choosing more points on the sphere results in a sphere-like mesh.
m2 = collisionMesh(pts2); show(m2)
Create an array consisting of the coordinates of the eight corners of a cube. The cube is centered at the origin and has side length 4.
cubeCorners = [-2 -2 -2 ; -2 2 -2 ; 2 -2 -2 ; 2 2 -2 ;... -2 -2 2 ; -2 2 2 ; 2 -2 2 ; 2 2 2]
cubeCorners = 8×3 -2 -2 -2 -2 2 -2 2 -2 -2 2 2 -2 -2 -2 2 -2 2 2 2 -2 2 2 2 2
pts2. Create and visualize the mesh collision geometry from the new array. Because the cube contains the sphere, the sphere points that are interior to the cube are disregarded when creating the geometry.
pts3 = [pts2;cubeCorners]; m3 = collisionMesh(pts3); show(m3)