How to plot a function on a cylinder surface
24 ビュー (過去 30 日間)
古いコメントを表示
Hi everybody
I want to plot level curves of a function on a cylinder surface. It should look similar like this:
Forget about the cats, just want to get the lines on the cylidner.
The function for the lines would be H(p,q) = 0.5*p^2-cos(q)-const. for const= 1:10 for example.
Since I don't have any clue of the code (also after doing some researches) unfortunately i cannot present my ideas.
I would be delighted getting some hints!
Thank you
Sabrina
0 件のコメント
採用された回答
Anton Semechko
2018 年 6 月 11 日
Here is an example:
% Right cylinder parameters
z_min=0; % lower cut-off point
z_max=4; % upper cut-off point
r=1; % radius
% Grid resolution
Nz=51; % number of faces along z-axis = Nz-1
Nt=ceil((2*pi*r)/(z_max-z_min)*Nz); % number of faces along perimeter
% Grid points (i.e., vertices)
z=linspace(z_min,z_max,Nz);
t=linspace(0,2*pi,Nt+1); t(end)=0;
[T,Z]=meshgrid(t,z);
siz=size(T);
V=[r*cos(T(:)) r*sin(T(:)) Z(:)]; % vertex coordinates
% Face-vertex connectivity list
N=size(V,1); % total number of vertices
id=reshape(1:N,siz); % vertex indices
F1=id(1:(siz(1)-1),1:(siz(2)-1));
F2=id(2:(siz(1)-0),1:(siz(2)-1));
F3=id(2:(siz(1)-0),2:(siz(2)-0));
F4=id(1:(siz(1)-1),2:(siz(2)-0));
F=[F1(:) F2(:) F3(:) F4(:)];
% Visualize cylinder
figure('color','w')
axis equal
h=patch('Faces',F,'Vertices',V);
set(h,'FaceColor',0.75*[1 1 1],'FaceAlpha',0.8,'EdgeColor','k')
view([20 20])
xlabel('X','FontSize',20,'FontWeight','bold')
ylabel('Y','FontSize',20,'FontWeight','bold')
zlabel('Z','FontSize',20,'FontWeight','bold')
% Evaluate scalar function G at grid points
G=cos(V(:,3).*V(:,1))+sin(3*V(:,2));
% Visualize G
figure('color','w')
axis equal
h=patch('Faces',F,'Vertices',V,'FaceVertexCData',G,'FaceColor','interp');
set(h,'FaceAlpha',0.95,'EdgeColor','none')
view([20 20])
xlabel('X','FontSize',20,'FontWeight','bold')
ylabel('Y','FontSize',20,'FontWeight','bold')
zlabel('Z','FontSize',20,'FontWeight','bold')
camlight('headlight'), lighting phong
1 件のコメント
Anton Semechko
2018 年 6 月 11 日
% Plot level-set curves using 'IsoContour' function (see attached)
Tri=[F(:,[1 2 3]);F(:,[3 4 1])];
[~]=IsoContour({Tri V},G,10,gca);
その他の回答 (1 件)
Sabrina Sewer
2018 年 6 月 12 日
1 件のコメント
Anton Semechko
2018 年 6 月 12 日
This was an example of how to plot scalar functions on a cylinder. You can substitute G with any other function you want.
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!