Using a vector to plot a cylinder

조회 수: 8 (최근 30일)
Thallon Pitchure
Thallon Pitchure 2019년 7월 25일
댓글: darova 2021년 3월 28일
Good day,
I am trying to create a cylinder using the 6 data point in the figure provided. The current code is listed below. I am not certain if I am using the correct cylinder syntax. If you could please provided any assistance it would be greatly appreciated. Thank you.
[Z,X,Y] = cylinder(0.0191/2, 100);
rodLen = norm(rodPoints(6,:)-rodPoints(1,:));
surf(X,rodLen*Y,Z,...
'EdgeColor', 'none',...
'FaceColor', [0.7 0.7 0.7],...
'FaceAlpha', 0.2)
  댓글 수: 2
Javier Coves Toral
Javier Coves Toral 2021년 3월 27일
편집: darova 2021년 3월 28일
Probably I arrive late, but I think I was trying to do something similar to you and I found this question. Finally I managed to do what I was triying so I am leaving my code here in case it is helpful to anyone :)
This creates a cylinder centered at (0,0,0), with its direction being the one of the vector "cyl_vect", with its radious being "R", and with its length being "l".
cyl_vect = [1,3,2];
R = 6378.137;
l = 100000;
[x,y,z] = cylinder(R);
th = atand(cyl_vect(3)/sqrt(cyl_vect(1)^2 + cyl_vect(2)^2));
if cyl_vect(1)>=0
phi = atand(cyl_vect(2)/cyl_vect(1));
else
phi = 180 + atand(cyl_vect(2)/cyl_vect(1));
end
surf(l*z*cosd(th)*cosd(phi)-x*sind(phi)-y*sind(th)*cosd(phi),l*z*cosd(th)*sind(phi)+x*cosd(phi)-y*sind(th)*sind(phi),l*z*sind(th)+y*cosd(th));
darova
darova 2021년 3월 28일
See rotate function

댓글을 달려면 로그인하십시오.

답변 (1개)

Hari Krishna Ravuri
Hari Krishna Ravuri 2019년 7월 31일
I understand that you are trying to make a surface plot of a cylinder. One of the ways in which you can use cylinder() is
[X,Y,Z] = cylinder(r,n)
This returns x,y,z coordinates of a cylinder based on the parameters. In you script, I observed that, the cylinder’s x,y,z coordinates are being stored in z,x,y . You are trying to modify the y coordinates of the cylinder, which changes the shape of it. Please refer https://www.mathworks.com/help/matlab/ref/cylinder.html

카테고리

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