How do I change the form of a value from patch to double?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
수현 박
il 29 Apr 2022
Modificato: Cameron Stabile
il 5 Mag 2022
I want to create a 3D map like the example below
But my obstacles are very big, and they're not parallel to the x-axis or the y-axis.
So I thought I couldn't use 'meshgrid' as in the example. So I drew the obstacle using 'patch' as below.
face = [1 2 3 4;
1 2 7 8;
5 6 7 8;
4 5 6 3;
1 4 5 8;
2 3 6 7];
for i=1:length(obstacle)
Obstacle_3D= patch('Vertices',obstacle{1,i},'faces',face,'Facecolor',[0.5 0.5 0.5])
hold on
end
However, I couldn't use 'updateOccupancy(map3D,Obstacle_3D,obs);' because I formed the obstacle as above.
Please let me know if anyone knows how to make a hollow rectangular parallelepiped using meshgrid or if they know how to change the patch to double
0 Commenti
Risposta accettata
Cameron Stabile
il 5 Mag 2022
Modificato: Cameron Stabile
il 5 Mag 2022
Looking to the documentation, you'll see that the second and third inputs for updateOccupancy need to be a set of XYZ points and their corresponding observation value(s), respectively. Therefore, converting your patch handle to a double would not give you the expected results.
To your question, I'm not aware of any end-to-end tools in MATLAB for sampling patch (or mesh) object surfaces, though the Computational Geometry documentation does show how one can use the delaunayTriangulation object to perform linear interpolation. Unfortunately the query points need to lie in-plane with at least one triangle, which somewhat limits the usefulness to your application.
For your particular use-case, however, there are simple ways of creating the outline of this shape. Here's an example:
clear all
close all
% Define outline based on some separation distance
maxSepDist = 0.5;
% Define length, width, height of cuboid
L = 20;
W = 10;
H = 5;
% Define horizontal layers
fLin = @(vMin,vMax)linspace(vMin,vMax,ceil((vMax-vMin)/maxSepDist));
[xH,yH] = ndgrid(fLin(0,L),fLin(0,W));
vTopBottom = [repmat(xH(:),2,1) repmat(yH(:),2,1) repelem([0;H],numel(xH),1)];
% Define middle layers
[xL,yL,zL] = ndgrid(xH(:,1),[0 W],fLin(0,H));
[xW,yW,zW] = ndgrid([0 L],yH(1,:),fLin(0,H));
zSz = size(zL);
% Combine all points
XYZ = vertcat(vTopBottom, [xL(:) yL(:) zL(:)], [xW(:) yW(:) zW(:)]);
% Create occupancyMap3D
map1 = occupancyMap3D(1);
% Add cuboid to map
updateOccupancy(map1, XYZ, 1);
% Display results
figure(1);
subplot(1,2,1)
plot3(XYZ(:,1),XYZ(:,2),XYZ(:,3),'.');
axis equal
subplot(1,2,2);
show(map1)
%% Convert to arbitrary parallelpiped
% Create an affine transformation which translates, rotates, and shears the
% rectilinear cuboid into a parallelpiped
t = [1;2;3];
R = quat2rotm(randrot);
shearValues = [.2 .2 0];
xShear = eye(3); xShear(1,[2 3]) = shearValues([2 3]);
yShear = eye(3); yShear(2,[1 3]) = shearValues([1 3]);
zShear = eye(3); zShear(end,[1 2]) = shearValues([1 2]);
H = [R.*zShear*yShear*xShear t; 0 0 0 1];
pXYZ = (H*[XYZ ones(size(XYZ,1),1)]')';
% Add sheared points to the map
map2 = occupancyMap3D(1);
updateOccupancy(map2,pXYZ(:,1:3),1);
figure(2);
subplot(1,2,1);
plot3(pXYZ(:,1),pXYZ(:,2),pXYZ(:,3),'.');
axis equal
subplot(1,2,2);
show(map2)
My last suggestion would be to browse FileExchange, which often contains useful tools. One such tool that might help is Jesus P. Mena-Chalco's Linear Subdivision.
Hope this helps,
Cameron
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Polygons in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!