How can i rotate a 2d line graph to 3d graph?
5 views (last 30 days)
Show older comments
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 Comments
Walter Roberson
about 11 hours ago
I think people are missing the point.
The point is to form a "solid of revolution"
Answers (1)
Jacob Mathew
about 13 hours ago
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 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!