資源簡介
MATLAB畫三維圓柱體的源代碼,能夠自己改參數(shù)改變圓柱的形狀、大小
代碼片段和文件信息
function?[Cylinder?EndPlate1?EndPlate2]?=?cylinder3(X1X2rncyl_colorclosedlines)
%
%?This?function?constructs?a?cylinder?connecting?two?center?points?
%?
%?Usage?:
%?[Cylinder?EndPlate1?EndPlate2]?=?cylinder3(X1+20X2rn‘r‘closedlines)
%????
%?Cylinder-------Handle?of?the?cylinder
%?EndPlate1------Handle?of?the?Starting?End?plate
%?EndPlate2------Handle?of?the?Ending?End?plate
%?X1?and?X2?are?the?3x1?vectors?of?the?two?points
%?r?is?the?radius?of?the?cylinder
%?n?is?the?no.?of?elements?on?the?cylinder?circumference?(more-->?refined)
%?cyl_color?is?the?color?definition?like?‘r‘‘b‘[0.52?0.52?0.52]
%?closed=1?for?closed?cylinder?or?0?for?hollow?open?cylinder
%?lines=1?for?displaying?the?line?segments?on?the?cylinder?0?for?only
%?surface
%?
%?Typical?Inputs
%?X1=[10?10?10];
%?X2=[35?20?40];
%?r=1;
%?n=20;
%?cyl_color=‘b‘;
%?closed=1;
%
%see?more?information?please?go?to?www.matlabsky.cn
%?NOTE:?There?is?a?MATLAB?function?“cylinder“?to?revolve?a?curve?about?an
%?axis.?This?“Cylinder“?provides?more?customization?like?direction?and?etc
%?Calculating?the?length?of?the?cylinder
length_cyl=norm(X2-X1);
%?Creating?a?circle?in?the?YZ?plane
t=linspace(02*pin)‘;
x2=r*cos(t);
x3=r*sin(t);
%?Creating?the?points?in?the?X-Direction
x1=[0?length_cyl];
%?Creating?(Extruding)?the?cylinder?points?in?the?X-Directions
xx1=repmat(x1length(x2)1);
xx2=repmat(x212);
xx3=repmat(x312);
%?Drawing?two?filled?cirlces?to?close?the?cylinder
if?closed==1
????hold?on
????EndPlate1=fill3(xx1(:1)xx2(:1)xx3(:1)‘r‘);
????EndPlate2=fill3(xx1(:2)xx2(:2)xx3(:2)‘r‘);
end
%?Plotting?the?cylinder?along?the?X-Direction?with?required?length?starting
%?from?Origin
Cylinder=mesh(xx1xx2xx3);
%?Definin
- 上一篇:nc文件的讀取作圖
- 下一篇:圖像清晰度評價指標_Matlab
評論
共有 條評論