How to draw an inclined cone with an ellipse base in the three-dimensional XYZ coordinate system?

조회 수: 8 (최근 30일)
Hello!
How can I draw an inclined cone with an ellipse base in the three-dimensional XYZ coordinate system so that the values in the coordinate system are also shown (so that it would be possible to take one point on the ellipse and get the XYZ values)? It is also necessary that the edges of the inclined cone, constructed from the points of the minor and major axes, be visible. Something similar to the cone in the photo, but so that the ellipse is at a certain angle that can be changed.
I will be grateful for your help.

답변 (1개)

Star Strider
Star Strider 2024년 4월 26일
편집: Star Strider 2024년 4월 26일
Start with the cylinder function, then modify it to create the sort of tilted cone you want.
Example —
r = [1 0]; % Radius
[X,Y,Z] = cylinder(r,25); % Generate 'cylinder'
X(1,:) = X(1,:)*1.50; % Shape Base 'X' To Create Ellipse
X(2,:) = X(2,:) + 1.5; % Shift 'X' Apex
Y(1,:) = Y(1,:)*0.75; % Shape Base 'Y' To Create Ellipse
Y(2,:) = Y(2,:) + 1.0; % Shift 'Y' Apex
figure
surfc(X, Y, Z, 'FaceAlpha',0.5) % Plot Tilted Cone With Semi-Transparent Sides & Contour To Show Result
colormap(turbo)
xlabel('X')
ylabel('Y')
zlabel('Z')
axis('equal')
axis([-2 2 -1 2 -0.5 1])
view(30,20)
Make appropriate changes to get the result you want.
EDIT — (26 Apr 2024 at 12:58)
Tweaked plot.
.
  댓글 수: 3
John D'Errico
John D'Errico 2024년 4월 26일
편집: John D'Errico 2024년 4월 26일
So where is the problem? Break a problem down into simple, small subproblems you can handle.
  1. Can you draw the ellipse? Pretty basic. You can find schemes for constructing an ellipse all over the internet, given the major and minor axes. Anyway, an ellipse is just a transformed circle. So, if you can generate points around a circle, you can then find the necessary transformation.
  2. Can you connect the ellipse perimeter, once known, to the vertex? Since the ellipse itself can be decribed by a set of points around the perimeter, then you need only connect each segment around the ellipse with the vertex. This just means you would create a set of triangles, easily drawn with patch.
As it is though, Star already gave you a good start.
Star Strider
Star Strider 2024년 4월 26일
편집: Star Strider 2024년 4월 29일
That was not what you originally stated in your initial post.
a = linspace(0, 2*pi*1.01, 100); % Angle Vector (Parameter)
r = [1; 1.5]; % Radius Vector
c = [2; 3]; % Ellipse Centre
p = pi/4; % Phase
e = r.*[cos(a+p); sin(a)] + c; % Ellipse Circumference [X,Y] Matrix
[~,smin] = mink(hypot(e(1,:)-c(1),e(2,:)-c(2)),2,2); % Semiminor Axis Index Points On Ellipse
xy_smin = [e(1,smin); e(2,smin)]; % Semiminor Points On Ellipse
[~,smaj] = maxk(hypot(e(1,:)-c(1),e(2,:)-c(2)),2,2); % Semimajor Axis Index Points On Ellipse
xy_smaj = [e(1,smaj); e(2,smaj)]; % Semimajor Points On Ellipse
S_point = [4 0 3]; % S-Point Coordinates
% xy_majq = [xy_smaj [0;0]]
minpts = [xy_smin(1,:); xy_smin(2,:); [0 0]].'; % Semiminor Axis (X,Y,Z) Points Matrix
majpts = [xy_smaj(1,:); xy_smaj(2,:); [0 0]].'; % Semimajor Axis (X,Y,Z) Points Matrix
figure
plot3(e(1,:), e(2,:), zeros(size(a))) % Plot Ellipse
hold on
plot3(xy_smin(1,:), xy_smin(2,:), zeros(2), '-rs') % Plot Semiminor Axis Points
plot3(xy_smaj(1,:), xy_smaj(2,:), zeros(2), '-rs') % Plot Semimajor Axis Points
for k = 1:2
plot3([minpts(k,1) S_point(1)], [minpts(k,2) S_point(2)], [minpts(k,3) S_point(3)], 'rs-') % Plot Lines From Semiminor Axis Points To 'S' Point
plot3([majpts(k,1) S_point(1)], [majpts(k,2) S_point(2)], [majpts(k,3) S_point(3)], 'rs-') % Plot Lines From Semiminor Axis Points To 'S' Point
end
plot3(S_point(1), S_point(2), S_point(3), 'pg', 'MarkerSize',10, 'MarkerFaceColor','g') % Plot 'S' Point
hold off
axis([0 5 0 5 0 3.5])
view(-130,30)
text(xy_smaj(1,:), xy_smaj(2,:), compose('$\\ (%.2f,%.2f)$',xy_smaj.'), 'Horiz','left', 'Interpreter','LaTeX')
text(xy_smin(1,:), xy_smin(2,:), compose('$\\ (%.2f,%.2f)$',xy_smin.'), 'Horiz','left', 'Interpreter','LaTeX')
text(S_point(1), S_point(2), S_point(3), sprintf('$S$\n$(%.1f,\\ %.1f,\\ %.1f)$', S_point), 'Interpreter','LaTeX', 'Horiz','center', 'Vert','bottom')
xlabel('X')
ylabel('Y')
zlabel('Z')
% axis('equal')
grid('on')
title('Ellipse With External Reference Point')
This took me longer than it should halve. Problems getting the lines to plot to the reference point.
Experiment to get the result you want. My codee should adapt to them.
EDIT — (29 Apr 2024 at 11:09)
Added comment documentation. Code unchanged
.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by