plotting multiple 2D point data in 3D
6 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I made my code to slice a 3D mesh and plot the sliced plane in 2D using mapshow(). So I have many slices planes as point set and would like to plot all plane in a 3D plot at once. Could you give me an idea?
0 件のコメント
回答 (1 件)
Praveen Reddy
2023 年 8 月 29 日
Hi Minyoung,
I understand that you want to plot planes in a 3D plot. You can use the “surf” function to plot the planes. Below is an example where I have generated 2 planes and plotted them using the “surf” function.
% Generate sample 2D point data for the planes
x1 = randn(100, 1);
y1 = randn(100, 1);
z1 = zeros(size(x1));
x2 = randn(100, 1);
y2 = randn(100, 1);
z2 = ones(size(x2));
% Fit planes to the 2D point data
plane1 = fit([x1, y1], z1, 'poly11');
plane2 = fit([x2, y2], z2, 'poly11');
% Define the range of x and y values to plot the planes
[X, Y] = meshgrid(linspace(min([x1; x2]), max([x1; x2]), 10), ...
linspace(min([y1; y2]), max([y1; y2]), 10));
% Evaluate the plane equations at each point on the grid
Z1 = plane1(X(:), Y(:));
Z2 = plane2(X(:), Y(:));
% Reshape the Z values to match the grid size
Z1 = reshape(Z1, size(X));
Z2 = reshape(Z2, size(X));
% Plot the planes
figure;
surf(X, Y, Z1, 'FaceAlpha', 0.5);
hold on;
surf(X, Y, Z2, 'FaceAlpha', 0.5);
% Set labels and title
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Plane Fitting with 2D Point Data');
view(3);
axis equal;
Please refer to the following MATLAB documentation page to know more about the “surf” function:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Interpolation についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!