I tried many options but I can't get a 3d closed cylinder. I only get hollow cylinder.
Trying to get something like this:
But getting this:
Can someone please help me.
My code:
[x1 y1] = GetCircle(1, 0, 0, 0, 2*pi);
z1 = zeros(1, length(x));
z2 = ones(1, length(x));
x = [x1;x1];
y = [y1;y1];
z = [z1;z2];
surf(x,y,z);
where GetCircle() is:
function [x y] = GetCircle(r, h, k, a, b)
t = linspace(a, b, 50);
x = r*cos(t) + h;
y = r*sin(t) + k;
end

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 10일

1 개 추천

To do this you could use cylinder function
r=2
[X,Y,Z] = cylinder(r)
h=mesh(X,Y,Z,'facecolor',[1 0 0])
For what you are looking for, if you have a VRML tool box, you can get the same cylinder. Can you tell what this cylinder is for?

댓글 수: 5

Maor Levy
Maor Levy 2013년 2월 10일
편집: Maor Levy 2013년 2월 10일
Thanks Azzi,
But the code you gave still produce hollow cylinder.
I'm taking intro to graphics class and we need to construct a model of the Pantheon (Rome).
So I'm trying to do the columns.
Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 10일
Look at Simulink 3D animation, you will find a VRML language which allows to create 3D object, and even animate them in simulink.
Maor Levy
Maor Levy 2013년 2월 10일
Yes, but it's the first lab and the professor doesn't want us to use Simulink.
Let's say, I don't mind it will be hollow, since I'm plotting on top of it. How can I produce in a loop cylinders, one next to each other(to crate the columns)?
r=0.5
[X,Y,Z] = cylinder(r)
for k=1:5
h=mesh(X,Y,Z,'facecolor',[0 1 1])
hold on
X=X+1
end
Maor Levy
Maor Levy 2013년 2월 10일
Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (4개)

Sharanya Srinivas
Sharanya Srinivas 2018년 3월 16일

2 개 추천

To create an illusion of a solid cylinder, you have to fill in the floor and ceil of the cylinder. You can do so using
r = 2; n = 100;
[X,Y,Z] = cylinder(r,n);
figure;
surf(X,Y,Z,'facecolor','r','LineStyle','none');
hold on
fill3(X(1,:),Y(1,:),Z(1:),'r')
fill3(X(2,:),Y(2,:),Z(2,:),'r')
Md Mohinoddin
Md Mohinoddin 2017년 10월 24일

0 개 추천

r=0.5 [X,Y,Z] = cylinder(r) for k=1:5 h=mesh(X,Y,Z,'facecolor',[0 1 1]) hold on X=X+1 end
Md Mohinoddin
Md Mohinoddin 2017년 10월 24일

0 개 추천

[x1 y1] = GetCircle(1, 0, 0, 0, 2*pi); z1 = zeros(1, length(x)); z2 = ones(1, length(x)); x = [x1;x1]; y = [y1;y1]; z = [z1;z2]; surf(x,y,z);
Kimberly Nowak
Kimberly Nowak 2021년 5월 26일
편집: Kimberly Nowak 2021년 5월 26일

0 개 추천

Habt ihr eine idee wo der fehler liegt?
Aufgabe ist folgende:
Kreise zeichnen (3.27) Schreiben Sie eine Funktion [x,y]=getCircle(mittelpunkt, radius), die Ihnen die x- und y-Koordinante eines Kreises mit dem genannten Mittelpunkt und Radius zurückgibt. Verwenden Sie hierfür die folgende Transformation:
x=r*cos(t)+xm
y=r*sin(t)+ym
mit t[0,2*pi]
function [x,y] = getCircle(mittelpunkt, radius)
numPunkt = 1000;
t = linspace(0,2*pi,numPunkt);
x = radius*cos(t)' + mittelpunkt(1);
y = radius*sin(t)' + mittelpunkt(2);
end

댓글 수: 1

The function does work the way you are expecting. It might have to do with how you are calling it.
clear; close all;
mittelpunkt = [5,5] ;
radius = 5 ;
[x,y] = getCircle(mittelpunkt, radius);
figure;
plot(x,y,'r')
hold on; plot(mittelpunkt(1),mittelpunkt(2),'b*')
xlabel('x'); ylabel('y')
title('Circle')

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 View and Analyze Simulation Results에 대해 자세히 알아보기

질문:

2013년 2월 10일

댓글:

2021년 5월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by