geom2struct
Syntax
Description
converts a cell array of collision geometries into a structure array.meshStruct
= geom2struct(geom
)
specifies identifiers for the specified collision geometries.meshStruct
= geom2struct(geom
,id
)
specifies local offsets as 3-D homogeneous transformation matrices to apply to the vertices
of corresponding geometries.meshStruct
= geom2struct(___,LocalOffsetPose=poseOffset
)
Examples
Add Meshes to Mesh TSDF Manager
Create two collision boxes and one collision sphere. The collision boxes represent a static environment and the sphere represents a dynamic obstacle with a pose that could change at any time.
box1 = collisionBox(0.5,1,0.1);
box2 = collisionBox(0.5,0.1,0.2,Pose=trvec2tform([0 -0.45 0.15]));
sph = collisionSphere(0.125,Pose=trvec2tform([-0.1 0.25 0.75]));
showCollisionArray({box1,box2,sph});
title("Static Environment and Dynamic Obstacle")
v = [110 10];
view(v);
Create a mesh TSDF manager with a resolution of 25 cells per meter.
tsdfs = meshtsdf(Resolution=25);
To improve the efficiency of signed distance field computation, combine meshes that represent the static environment.
staticMeshes = geom2struct({box1,box2}); staticEnv = staticMeshes(1); staticEnv.Pose = eye(4); staticEnv.Vertices = []; staticEnv.Faces = []; for i = 1:numel(staticMeshes) H = staticMeshes(i).Pose; V = staticMeshes(i).Vertices*H(1:3,1:3)'+ H(1:3,end)'; nVert = size(staticEnv.Vertices,1); staticEnv.Vertices = [staticEnv.Vertices; V]; staticEnv.Faces = [staticEnv.Faces; staticMeshes(i).Faces+nVert]; end staticEnv.ID = 1;
Add the static environment mesh to the TSDF manager.
addMesh(tsdfs,staticEnv);
Convert the sphere collision geometry into a structure for the mesh TSDF manager. Assign it an ID of 2 and add it to the mesh TSDF manager.
obstacleID = 2; dynamicObstacle = geom2struct(sph,obstacleID); addMesh(tsdfs,dynamicObstacle); show(tsdfs) view(v) axis equal title("Mesh TSDFs of Static Environment and Dynamic Obstacle")
Update the pose of the dynamic obstacle in the mesh TSDF manager by changing Pose
property of the object handle of the obstacle. Then use the updatePose
function to update the pose of the mesh in the TSDF manager.
dynamicObstacle.Pose = trvec2tform([0.2 0.25 0.2]); updatePose(tsdfs,dynamicObstacle)
ans = 1
show(tsdfs) view(v) axis equal title("Updated Dynamic Obstacle Pose")
Input Arguments
geom
— Collision geometry objects
collisionBox
| collisionCapsule
| collisionCylinder
| collisionMesh
| collisionSphere
| N-element cell array of collision geometry objects
Collision geometry object, specified as collision geometry object or as an N-element cell array of collision geometry objects. N is the number of collision objects in the cell array. A collision object must be one of these objects:
id
— Geometry structure ID
positive integer | N-element vector of positive integers
Geometry structure ID, specified as a positive integer or an
N-element vector of positive integers. N is the
number of collision objects in geom
.
If id
is a N-element vector of positive
integers, then each ID in id
must be unique.
If id
is not specified, then the ID of the structure is set to
1:N
. For example,
geom2struct({geom1,geom2,geom3})
creates three structures
corresponding to geom1
, geom2
, and
geom3
with IDs set to 1
, 2
,
and 3
, respectively.
poseOffset
— Local pose offset
4-by-4 homogeneous transformation matrix | 4-by-4-by-N array of homogeneous transformation matrices | se3
object | N-element array of se3
objects
Output Arguments
meshStruct
— Geometry mesh structure
structure | N-element structure array
Geometry mesh structure, returned as a structure or an N-element
structure array. N is the number of collision objects in
geom
.
Each structure contains these fields:
ID
— ID of the geometry structure stored as a positive integer. By default, the ID of each structure corresponds to the index of the structure inmeshStruct
. For example, ifmeshStruct
contains five mesh structures, the first mesh structure at index 1 has anID
of1
, and the last mesh structure at index 5 has anID
of5
.Vertices
— Vertices of the geometry, stored as an M-by-3 matrix. Each row represents a vertex in the form [x y z] with respect to the reference frame defined byPose
. M is the number of vertices needed to represent the convex hull of the mesh.Faces
— Faces of the geometry, stored as an M-by-3 matrix. Each row contains three indices corresponding to vertices inVertices
that define a triangle faces of the geometry. M is the number of vertices inVertices
.Pose
— Pose of the geometry as a 4-by-4 homogeneous transformation matrix specifying a transformation from the world frame to the frame in which the vertices are defined.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version History
Introduced in R2024a
See Also
meshtsdf
(Navigation Toolbox) | collisionBox
| collisionCapsule
| collisionCylinder
| collisionMesh
| collisionSphere
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)