I want to draw an ellipsoide with one cercle and one ellipse inside it and have the axis of the cercle and the ellipse drawn too
조회 수: 2 (최근 30일)
이전 댓글 표시
I want to draw an ellipsoide with one cercle and one ellipse inside it and have the axis of the cercle and the ellipse drawn too,
i would like the ellipsoide be transparaent (grey light color ).
attached the figure in 2D, i want to make it in 3D.
please if anyone could help me on this issue
thank you very much for your help
댓글 수: 0
답변 (1개)
Kevin Holly
2021년 9월 25일
편집: Kevin Holly
2021년 9월 25일
Here is the ellipsoid and the circle. Did you want the ellipse to be at a particular angle?
% Parameters
% Center
xc = 0;
yc = 0;
zc = 0;
% Radius
xr = 0.5;
yr = 0.5;
zr = 1;
% Minor Axes Length
minor_length = min([xr,yr,zr]);
% Plot
figure
% Ellipsoid
ellipsoid(xc,yc,zc,xr,yr,zr)
axis equal
handle = gca; % get axes handle
handle.Children.EdgeColor = [.8 .8 .8];
handle.Children.FaceColor = [.8 .8 .8];
handle.Children.FaceAlpha = .5;
% Circle
viscircles([xc,yc], minor_length,'Color','r');
hold on
% Circle Axes
line([xc,xc],[-yr,yr],'Color','r')
line([-xr,xr],[yc,yc],'Color','r')
댓글 수: 4
Kevin Holly
2021년 9월 25일
편집: Kevin Holly
2021년 9월 25일
I made variables linethickness_red,linethickness_green, and linethickness_blue that you can adjust.
If you have an equation to calculate the major axis length and eccentricity value of the ellipse when rotated, you can automate the procress. You can easily make an App with a slider bar. If you need it for such purposes.
% Parameters
% Center
xc = 0;
yc = 0;
zc = 0;
% Radius
xr = 0.5;
yr = 0.5;
zr = 1;
% Rotation Angle
angle = 25;
% Minor Axes Length
minor_length = min([xr,yr,zr]);
linethickness_red = 2;
% Plot
figure
% Ellipsoid
[x, y, z] = ellipsoid(xc,yc,zc,xr,yr,zr);
h = surf(x, y, z);
axis equal
hold on
set(h, 'FaceColor',[.8 .8 .8], 'FaceAlpha', 0.2,'EdgeAlpha', 0.2)
% Circle
hc = viscircles([xc,yc], minor_length,'Color','r','LineWidth',linethickness_red);
hc.Children(2).Color = 'r';
hold on
lc1 = line([xc,xc],[-0.5 0.5],'Color','r','LineWidth',linethickness_red);
lc2 = line([-0.5 0.5],[yc,yc],'Color','r','LineWidth',linethickness_red);
% Rotate Ellipsoid and Circle with its Axes
rotate(h,[1 0 0],angle)
rotate(hc.Children(1),[1 0 0],angle)
rotate(hc.Children(2),[1 0 0],angle)
rotate(lc1,[1 0 0],angle)
rotate(lc2,[1 0 0],angle)
% Define parameters for blue ellipse
linethickness_blue = 2;
x1 = 0;
x2 = 0;
y1 = -.8; % value based on angle of 25 degrees
y2 = .8; % value based on angle of 25 degrees
eccentricity = .78;
numPoints = 300; % Less for a coarser ellipse, more for a finer resolution.
% Make equations:
a = (1/2) * sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2);
b = a * sqrt(1-eccentricity^2);
t = linspace(0, 2 * pi, numPoints); % Absolute angle parameter
X = a * cos(t);
Y = b * sin(t);
% Compute angles relative to (x1, y1).
angles = atan2(y2 - y1, x2 - x1);
x = (x1 + x2) / 2 + X * cos(angles) - Y * sin(angles);
y = (y1 + y2) / 2 + X * sin(angles) + Y * cos(angles);
hold on
plot3(x,zeros(size(y)),y,'-','Color','b', 'LineWidth', linethickness_blue);
plot3(x,zeros(size(y)),zeros(size(y)),'b-', 'LineWidth', linethickness_blue);
plot3(zeros(size(x)),zeros(size(y)),y,'b-', 'LineWidth', linethickness_blue);
view(-75,20)
% Define parameters of green ellipse
linethickness_green = 2;
x1 = 0;
x2 = 0;
y1 = -1;
y2 = 1;
eccentricity = .866;
numPoints = 300; % Less for a coarser ellipse, more for a finer resolution.
% Make equations:
a = (1/2) * sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2);
b = a * sqrt(1-eccentricity^2);
t = linspace(0, 2 * pi, numPoints); % Absolute angle parameter
X = a * cos(t);
Y = b * sin(t);
% Compute angles relative to (x1, y1).
angles = atan2(y2 - y1, x2 - x1);
x = (x1 + x2) / 2 + X * cos(angles) - Y * sin(angles);
y = (y1 + y2) / 2 + X * sin(angles) + Y * cos(angles);
hold on
green_ellipse_handle.ellipse = plot3(x,zeros(size(y)),y,'-','Color','g', 'LineWidth', linethickness_blue);
green_ellipse_handle.axis1 = plot3(x,zeros(size(y)),zeros(size(y)),'g-', 'LineWidth', linethickness_blue);
green_ellipse_handle.axis2 = plot3(zeros(size(x)),zeros(size(y)),y,'g-', 'LineWidth', linethickness_blue);
% Rotate Green Ellipse with its Axes
rotate(green_ellipse_handle.ellipse,[1 0 0],angle)
rotate(green_ellipse_handle.axis1,[1 0 0],angle)
rotate(green_ellipse_handle.axis2,[1 0 0],angle)
참고 항목
카테고리
Help Center 및 File Exchange에서 Point Cloud Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!