76 次查看(过去 30 天)
显示 更早的评论
taetae 2024-7-18,5:11
评论: taetae 2024-7-19,2:00
采纳的回答: Anagha Mittal
I can show my meshgrid and stl model. but can't merge two thing...
I want the ship to belong to the meshgrid by value.
I can let you know if I need any information.
0 个评论 显示 -2更早的评论隐藏 -2更早的评论
显示 -2更早的评论隐藏 -2更早的评论
请先登录,再进行评论。
请先登录,再回答此问题。
采纳的回答
Anagha Mittal 2024-7-18,6:54
Hi,
To merge meshgrid with an STL model, you may import the STL model using the "importGeometry" function and then combine the meshgrid data with STL geometry and plot them together. Refer to the following documentation link for information and usage of "importGeometry" function:
Below is an example script that shows the steps to achieve the same:
% Step 1: Import the STL Model
model = createpde();
gm = importGeometry(model, 'yourModel.stl');
% Step 2: Create the Meshgrid (You may use the meshgrid you have created)
[x, y, z] = meshgrid(-10:1:10, -10:1:10, -10:1:10);
% Step 3: Combine and Visualize
figure;
pdegplot(gm, 'FaceAlpha', 0.5); % Plot the STL model
hold on;
scatter3(x(:), y(:), z(:), 'r.'); % Plot the meshgrid points
hold off;
axis equal;
Here, "hold on" and "hold off" functions will ensure that they are plotted together. Refer to the following documentation link for more information on these functions:
Hope this helps!
1 个评论 显示 -1更早的评论隐藏 -1更早的评论
显示 -1更早的评论隐藏 -1更早的评论
taetae 2024-7-19,2:00
此评论的直接链接
https://ww2.mathworks.cn/matlabcentral/answers/2138322-how-to-megre-meshgrid-and-stl-file#comment_3215316
I don't think that's the way to go... I've been suffering from this for 3 days now...
请先登录,再进行评论。
更多回答(1 个)
Zinea 2024-7-18,10:00
Hi taetae,
Here is a demonstration on how to merge a ‘meshgrid’ with an ‘STL model’ in MATLAB R2022b. A dummy STL model which is a simple cube is used as an example here. The ‘STL model’ and ‘meshgrid’ are plotted separately, as well as merged in a 3D plot.
NOTE:
- The ‘hold on’ command is used for plotting multiple graphical objects on the same axes without overwriting each other. After plotting both the ‘STL model’ and the ‘meshgrid’, we use ‘hold off’ to stop adding to the current plot.
- The ‘surf’ function is used to add a surface plot to a 3D plot. This is done in conjunction with the patch function, which is used to display an STL model.
Here is the complete script for reference:
% Define the vertices of the cube
vertices = [
0 0 0;
1 0 0;
1 1 0;
0 1 0;
0 0 1;
1 0 1;
1 1 1;
0 1 1
];
% Define the faces of the cube
faces = [
1 2 3; 1 3 4; % Bottom face
5 6 7; 5 7 8; % Top face
1 2 6; 1 6 5; % Front face
2 3 7; 2 7 6; % Right face
3 4 8; 3 8 7; % Back face
4 1 5; 4 5 8 % Left face
];
% Create a triangulation object
cube = triangulation(faces, vertices);
% Save the triangulation object as an STL file
stlwrite(cube, 'dummy_cube.stl');
disp('Dummy STL model created and saved as dummy_cube.stl');
Dummy STL model created and saved as dummy_cube.stl
% Load the STL file
fv = stlread('dummy_cube.stl');
% Extract vertices and faces from the loaded STL structure
vertices = fv.Points;
faces = fv.ConnectivityList;
% Create a meshgrid
[x, y] = meshgrid(linspace(min(vertices(:,1)), max(vertices(:,1)), 50), ...
linspace(min(vertices(:,2)), max(vertices(:,2)), 50));
% Define the function for the meshgrid. Here we use a simple sine function.
z = sin(sqrt(x.^2 + y.^2));
% Plot the STL model and meshgrid separately and together
figure;
% Subplot 1: STL model
subplot(1, 3, 1);
patch('Faces', faces, 'Vertices', vertices, ...
'FaceColor', [0.8 0.8 1.0], 'EdgeColor', 'none', 'FaceAlpha', 0.5);
view(3);
axis equal;
xlabel('X');
ylabel('Y');
zlabel('Z');
title('STL Model');
% Subplot 2: Meshgrid
subplot(1, 3, 2);
surf(x, y, z, 'FaceAlpha', 0.5, 'EdgeColor', 'none');
view(3);
axis equal;
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Meshgrid');
% Subplot 3: Combined
subplot(1, 3, 3);
hold on;
patch('Faces', faces, 'Vertices', vertices, ...
'FaceColor', [0.8 0.8 1.0], 'EdgeColor', 'none', 'FaceAlpha', 0.5);
surf(x, y, z, 'FaceAlpha', 0.5, 'EdgeColor', 'none');
view(3);
axis equal;
hold off;
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Combined STL Model and Meshgrid');
% Set the overall figure title
sgtitle('STL Model and Meshgrid Plots');
You may refer to the following documentation links for more information about the functions used in the above code snippet:
Hope this resolves your query!
Zinea
1 个评论 显示 -1更早的评论隐藏 -1更早的评论
显示 -1更早的评论隐藏 -1更早的评论
taetae 2024-7-19,2:00
此评论的直接链接
https://ww2.mathworks.cn/matlabcentral/answers/2138322-how-to-megre-meshgrid-and-stl-file#comment_3215311
I don't think that's the way to go... I've been suffering from this for 3 days now...
请先登录,再进行评论。
请先登录,再回答此问题。
另请参阅
类别
MATLABGraphics2-D and 3-D PlotsSurfaces, Volumes, and PolygonsSurface and Mesh Plots
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 简体中文Chinese
- English
- 日本Japanese (日本語)
- 한국Korean (한국어)
联系您当地的办事处