필터 지우기
필터 지우기

How to plot a function on a cylinder surface

조회 수: 15 (최근 30일)
Sabrina Sewer
Sabrina Sewer 2018년 6월 11일
댓글: Anton Semechko 2018년 6월 12일
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에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by