Hello MATLAB Community!
I'm having some difficulties in rendering a cylinder. I only want to visualize the lateral surface and since the cylinder is slighty asymmetric I can't apply the standard cylinder function and therefore follow an elliptical approach. There must be a mistake in the line where the patch-function is applied but I can't figure it out. I was trying to define a polygon by tracing both circles. Thank you in advance!
%% Some random parameters
a_fit=1000;b_fit=1010;%% create samples and apply to the ellipcital equation
samples=1000;samp_theta=linspace(0,2*pi,samples);samp_r=sqrt(1./((cos(samp_theta')).^2./a_fit.^2+(sin(samp_theta')).^2./b_fit.^2));[samp_X,samp_Y] = pol2cart(samp_theta',samp_r);samp_Z_1=repmat(-3,samples,1);samp_Z_2=repmat(3,samples,1);%% visualize
figure(1);hold onplot3(samp_X,samp_Y,samp_Z_1,'Color',[0.8500, 0.3250, 0.0980]);plot3(samp_X,samp_Y,samp_Z_2,'Color',[0.8500, 0.3250, 0.0980]);p=patch([samp_X;fliplr(samp_X)], [samp_Y;fliplr(samp_Y)], [samp_Z_1;samp_Z_2],'r')hold offxlabel('X / mm');ylabel('Y / mm');zlabel('Z / mm');
Best Answer