Help on transforming a 2D structure into 3D
1 view (last 30 days)
Show older comments
Hello, i got this structure that draws something. I did in 2D as it is the only way I know, but I have to transform it into 3D so that it looks like a uphead crane. Something like this but in 3D . How do I do that? Thank you
clc
close all
x=2;
y=2;
r=0.5;
t=0:0.1:2*pi;
x=r*cos(t)+x;
y=r*sin(t)+y;
a=[1,x];
b=[1,y];
for k=1:length(t)
clf;
a=[1,x(k)];
b=[1,y(k)];
plot(x(k),y(k),'go')
hold on
plot(x(1:k),y(1:k),'k')
axis([0 4 0 4])
hold on;
plot(a,b,'k')
xlabel("x");
ylabel("y");
zlabel("z");
view(31,34);
drawnow
end
0 Comments
Answers (1)
Santosh Fatale
on 9 Nov 2022
Hi Spulber,
I checked the code provided by you, and it is my understanding that by providing the proper (x, y, z) triplet for each of the points and using the plot3 function instead of plot, you can transform your 2D plot into a 3D plot.
The modified sample code where I used plot3 in place of plot is as follows:
clc
close all
x=2;
y=2;
r=0.5;
t=0:0.1:2*pi;
x=r*cos(t)+x;
y=r*sin(t)+y;
a=[1,x];
b=[1,y];
for k=1:length(t)
clf;
a=[1,x(k)];
b=[1,y(k)];
plot3(x(k),y(k),1,'go','LineWidth',2)
hold on
plot3(x(1:k),y(1:k), ones(k,1),'k','LineWidth',1.5)
axis([0 4 0 4])
hold on;
plot3(a,b,[4 1],'r')
xlabel("x");
ylabel("y");
zlabel("z");
drawnow
end
0 Comments
See Also
Categories
Find more on Startup and Shutdown 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!