I would like to draw a hemisphere with slats as attached figures. 12 identical slits created in hemi
sphere, and width slit and width slat are equal.

댓글 수: 2

doc patch
viet le
viet le 2016년 9월 2일
could you explain more detail, plz?

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

 채택된 답변

Stephen23
Stephen23 2016년 9월 2일
편집: Stephen23 2016년 9월 2일

0 개 추천

There is no need to write ugly, slow code using loops. MATLAB code is much more beautiful than that! This should get you started:
n = 12;
p = 30;
%
tht = linspace(0,pi,1+p).';
ang = linspace(0,pi,2*n);
%
x = cos(tht)*ones(1,2*n);
y = sin(tht)*cos(ang);
z = sin(tht)*sin(ang);
%
V = [x(:),y(:),z(:)];
F = bsxfun(@plus,(1:p).',0:2*(p+1):size(V,1)-1);
F = F(:);
F(:,2:4) = [1+F,F+2+p,F+1+p];
%
patch('Faces',F, 'Vertices',V, 'FaceColor','green', 'EdgeColor','none')
view(3)
Creates this:

댓글 수: 3

viet le
viet le 2016년 9월 2일
편집: viet le 2016년 9월 2일
thanks. it is useful and simple.
KSSV
KSSV 2016년 9월 2일
편집: KSSV 2016년 9월 2일
Good one...I had lot to learn from the code...!
Stephen23
Stephen23 2016년 9월 2일
편집: Stephen23 2016년 9월 2일
@viet le: I hope that you find my code useful. if my answer resolved your question, then please accept it by clicking the accept button

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

추가 답변 (1개)

KSSV
KSSV 2016년 9월 1일

0 개 추천

clc; clear all ;
R = 1. ;
%
N1 = 100 ;
th1 = linspace(0,pi,N1) ;
x = R*cos(th1) ;
y = R*sin(th1) ;
z = zeros(size(x)) ;
%
N2 = 100 ;
th2 = linspace(0,pi,N2) ;
X = zeros(N1,N2) ;
Y = X ;
Z = X ;
for i = 1:N1
for j = 1:N2
Rot = [1 0 0 ; 0 cos(th2(j)) -sin(th2(j)) ; 0 sin(th2(j)) cos(th2(j))] ;
k = Rot*[x(i) ; y(i) ;z(i)] ;
X(i,j) = k(1) ;
Y(i,j) = k(2) ;
Z(i,j) = k(3) ;
end
end
figure
hold on
count = 0 ;
for i = 1:2:N1
count = count+1 ;
x = [X(:,i) ; flipud(X(:,1+1))] ;
y = [Y(:,i) ; flipud(Y(:,i+1))] ;
z = [Z(:,i) ; flipud(Z(:,1+1))] ;
if mod(count,2)
fill3(x,y,z,'g','edgecolor','none')
else
fill3(x,y,z,'w','edgecolor','none')
end
drawnow
end

댓글 수: 4

viet le
viet le 2016년 9월 2일
편집: viet le 2016년 9월 2일
thank.but do you think this figure is wrong.
KSSV
KSSV 2016년 9월 2일
Yes there is a problem with the filling color thing..it needs fine tune.
KSSV
KSSV 2016년 9월 2일
A small correction:
change the loop for i = 1:2:N1 to for i = 1:N1-1.
viet le
viet le 2016년 9월 2일
thank. it is very helpful.

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

카테고리

질문:

2016년 9월 1일

편집:

2016년 9월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by