From: Abhinav Pande on 6 Jul 2010 19:27 Hi, Is there a simple way of generating a solid 3D cylinder with given radius 'r' and height 'h' . I want to build the cylinder and then orient it in 5 different orientations by tilting the axis at different angles. (say 0, 30,45,60,90). Abhinav
From: neil on 6 Jul 2010 23:53 "Abhinav Pande" <pandeak(a)mail.uc.edu> wrote in message <i10e49$if2$1(a)fred.mathworks.com>... > Hi, > Is there a simple way of generating a solid 3D cylinder with given radius 'r' and height 'h' . I want to build the cylinder and then orient it in 5 different orientations by tilting the axis at different angles. (say 0, 30,45,60,90). > > Abhinav Hi Abhinav It is not all that easy. I find the best method is to use patches and express my data points mathematically. Patches can be a little tricky to use, the face and vertex properties can hurt your head. If you have a really complex geometry try create it in a CAD package save it as an STL file and import it into MATLAB. There is STL file import code somewhere on the file exchange. Anyways here is my attempt at your problem %% Setup the intial values noPoints = 100; theta = linspace(0,2*pi,noPoints); radius = 10; height = 50; %% Create the X and Y vectorrs x = radius.*cos(theta); y = radius.*sin(theta); %% create matrix of bottom and top points bottom = [x',y',zeros(noPoints,1)]; top = [x',y',repmat(height,noPoints,1)]; %% Create faces and vertices matrix %create the vertices matrix vertices = [bottom;top]; %Create the faces matrix; %Add the 'Top' triangles faces = [(1:noPoints)',(noPoints+1:2*noPoints)',((noPoints+1:2*noPoints)+1)']; %replace the last to one since it is out of bounds faces(end,3) = 1; %Add the 'Bottom Triangles' faces = [faces;... (1:noPoints)',(2:noPoints+1)',((noPoints+1:2*noPoints)+1)']; %replace the last to one since it is wrong faces(end,2) = 1; faces(end,3) = noPoints+1; %% Use patch to plot p1 = patch('faces',faces,'vertice',vertices,'facecolor',[0 0 1],'edgecolor',[0 0 1]); %% move the axis around axis('equal') view(0,0); pause(0.1); view(0,30); pause(0.1); view(0,45); pause(0.1); view(0,60); pause(0.1); view(0,90);
From: abhinav pande on 7 Jul 2010 13:50 Neil, Thanks a lot for the simple code. However, there seems to be a couple of issues here. 1) the cylinder doesn't seem to be closed at the top and bottom. 2) More importantly, the axis of the cylinder doesn't seem to be rotating about the abgles specified. It shows only one orientation i.e. axis along Z-axis. Could you please verify this? Thanks Abhinav
From: Doug Hull on 7 Jul 2010 15:32 Look into HGTRANSFORM. http://www.mathworks.com/access/helpdesk/help/techdoc/ref/hgtransform.html Doug
From: neil on 7 Jul 2010 18:56 "abhinav pande" <pandeak(a)mail.uc.edu> wrote in message <i12eos$60h$1(a)fred.mathworks.com>... > Neil, > Thanks a lot for the simple code. > However, there seems to be a couple of issues here. > 1) the cylinder doesn't seem to be closed at the top and bottom. > 2) More importantly, the axis of the cylinder doesn't seem to be rotating about the abgles specified. It shows only one orientation i.e. axis along Z-axis. > > Could you please verify this? > > Thanks > Abhinav 1) No it doesn't, All you need to do is create two new patches for the top and bottom. 2) No it isn't, Recode the coordinate system into one you want. You HGTRANSFORM or use the camera toolbar functions. They can be tricky.
|
Next
|
Last
Pages: 1 2 Prev: semi-transparent image or scatterplot Next: Diagonal matrix recognition |