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

采纳的回答

Anton Semechko
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
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
Sabrina Sewer 2018-6-12
Hi! Thank you so much for your functions! Just a little question: Evaluating my function H(p,q) = 0.5*p^2-cos(q)-const. for const= 1:10 at the grid points, how do i have to choose the coordinates?
% G=0.5.*(V(:,1).*V(:,2)).^2-cos(V(:,3));
..gives the plot attached. But that isn't the exact result as i want to have (s. picture in question). Where is my mistake?
Best
  1 个评论
Anton Semechko
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 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