Implicit surface plot of a finite cylinder

조회 수: 3 (최근 30일)
Matt J
Matt J 2021년 2월 14일
답변: Matt J 2021년 2월 14일
Using fimplicit3, I can plot an infinite cylinder, like so:
args={'EdgeColor','none','FaceColor','c','FaceAlpha',0.3};
fimplicit3(@(x,y,z) x.^2+y.^2-1, args{:} ); axis([-3,+3,-3,+3,-3,+3])
However, what I would really like is for the cylinder to be of finite length, say 4. My first idea for how to do this was the following. This does produce a finite cylinder of the correct length, but it is closed at both ends, which I do not want.
fimplicit3(@(x,y,z) x.^2+y.^2-1 + (abs(z)>2), args{:} ); axis([-3,+3,-3,+3,-3,+3])
I believe I know why this is happening. There is a discontinuous jump from negative values to 1 at the end caps, and so the fimplicit3 algorithm assumes there are roots there. However, I wonder if there is a way to trick fimplicit3 somehow so that I get a cylinder with open ends. Any ideas?

채택된 답변

Matt J
Matt J 2021년 2월 14일
The solution, as it turns out, was fairly simple:
args={'EdgeColor','none','FaceColor','c','FaceAlpha',0.3};
fimplicit3(@fun, args{:} ); axis([-3,+3,-3,+3,-3,+3])
function val=fun(x,y,z)
val=x.^2+y.^2-1;
val(abs(z)>2)=nan;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by