How can i rotate a 2d line graph to 3d graph?
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello friends, i have a line plot (x-axis and y-axis), i want to rotate it 360 degree about the origin and create it like 3D graph. Kindly help me.
댓글 수: 4
Walter Roberson
2024년 12월 4일
I think people are missing the point.
The point is to form a "solid of revolution"
답변 (1개)
Jacob Mathew
2024년 12월 4일
Hi Aravindan,
I assume you want to show the plot in 3 dimension. You can use the plot3 method to plot the points in 3 dimensional space. You can then change the perspective by manually clicking and dragging on the graph. Or you can use the view method within a for loop to have an animated view from a 360 degree perspective. Here is an example code:
% Vertical parabola in 3D space
x = linspace(-5, 5, 100);
y = zeros(size(x));
z = x.^2;
% Create the 3D plot
figure;
h = plot3(x, y, z, 'LineWidth', 2);
axis equal;
grid on;
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('3D Parabola Animation');
% Animation loop
% NOTE: The animation does not render if you run here
for angle = 1:360
% Rotate the plot around the axis passing through the parabola's minimum
% Here, the axis is the y-axis, so we rotate around it
view([angle, 30]);
drawnow;
pause(0.05); % Adjust the pause for speed of rotation
end
You can refer to the documentation for plot3 and view functions in the links below:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Animation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!