Help on transforming a 2D structure into 3D

3 次查看(过去 30 天)
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

回答(1 个)

Santosh Fatale
Santosh Fatale 2022-11-9
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
For more information about plot3 function, you can check out the following link.

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by