how to create a semiellipsoid around the plotted points?

5 ビュー (過去 30 日間)
Varsha Radhakrishnan
Varsha Radhakrishnan 2021 年 6 月 2 日
回答済み: Jaswanth 2024 年 2 月 16 日
Hi,
I tried to create semi ellipsoid around each of the clustered points as in figure using the formula below.
a,b,c= something;
[theta,phi] = ndgrid(linspace(0,pi/2,50),linspace(0,2*pi,50));
x = a*sin(theta).*cos(phi);
y = b*sin(theta).*sin(phi);
z = c*cos(theta);
surf(x,y,z,'facecolor','blue','facealpha',.2,'edgecolor','none');
But there is axis issues between the plotted points and ellipsoid. Could someone help me please?

回答 (1 件)

Jaswanth
Jaswanth 2024 年 2 月 16 日
Hi,
It appears that you are working on plotting semi-ellipsoids around clustered points in a 3D space. Based on the provided information, possible reasons for the axis issues could be incorrect centering ofsemi-ellipsoids with respect to cluster points and unequal scaling on axes. Additionally, there may be instances where parts of the ellipsoids are cut off, or the plot is zoomed too far in or out.
Please go through the following steps that can help in addressing the axis issues you have mentioned:
  • Iterate over each cluster point to plot the semi-ellipsoids. Use the center coordinates (xc, yc, zc) of each semi-ellipsoid to translate it from the origin to the appropriate position.
Please go through the following example code snippet, which includes a for loop that iterates over the cluster points and, uses their coordinates to center the semi-ellipsoid:
for i = 1:size(cluster_points, 1)
% Coordinates of the current cluster point
xc = cluster_points(i, 1);
yc = cluster_points(i, 2);
zc = cluster_points(i, 3);
% Equations for the semi-ellipsoid centered at the cluster point
x = a*sin(theta).*cos(phi) + xc;
y = b*sin(theta).*sin(phi) + yc;
z = c*cos(theta) + zc;
% Plot the semi-ellipsoid
surf(x, y, z, 'FaceColor', 'blue', 'FaceAlpha', 0.2, 'EdgeColor', 'none');
end
  • Ensure consistent scaling across axes with ‘axis equal’; to maintain the correct aspect ratio.
  • Adjust the axes limits to accommodate all semi-ellipsoids and points based on the positions of the cluster points and the dimensions of the semi-ellipsoids.
Please go through following example code snippet to set the axes limits:
% Set equal scaling for the axes
axis equal;
% Enhance the visualization by setting the axes limits
xlim([min(cluster_points(:,1))-a, max(cluster_points(:,1))+a]);
ylim([min(cluster_points(:,2))-b, max(cluster_points(:,2))+b]);
zlim([min(cluster_points(:,3)), max(cluster_points(:,3))+c]);
By Implementing these suggestions, you can successfully plot the semi-ellipsoids around each cluster point as shown in the image attached below.
I hope the information provided above is helpful in resolving your issue.

カテゴリ

Help Center および File ExchangeData Exploration についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by