Help on transforming a 2D structure into 3D
조회 수: 2 (최근 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
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!