Using plot3 to draw cones in MATLAB

I am looking for a way to draw a cone in a specific place on a 3D plot. Would it also be possible for the cone to be 50% transparent?

Now I am drawing a basic 3d environment using the surf function. I am trying to use the plot3 function to draw a cone with specific sizes in a specific place.

+2
user-interface matlab plot draw
source share
2 answers

The following code creates a cone by clamping a cylinder between zero and one with t=[0;1] . The alpha function fan (...) is then used to set the transparency. To move the cylinder, you must add a value to x, y or z or perform a rotation (outside the scope of this answer).

 t = [0;1]; [X,Y,Z] = cylinder(t); figure; clf; surf(X,Y,Z); alpha(.5) hold all surf(X+1,Y,Z); alpha(.5); axis equal 

Them cylinders

+4
source share

I found that this function works exactly the way I need it:

http://www.mathworks.com/matlabcentral/fileexchange/21951-cone/content//Cone.m

  function [Cone,EndPlate1,EndPlate2] = Cone(X1,X2,R,n,cyl_color,closed,lines) % % This function constructs a cylinder connecting two center points % % Usage : % [Cone,EndPlate1,EndPlate2] = Cone(X1,X2,R,n,cyl_color,closed,lines) % % Cone-------Handle of the cone % EndPlate1------Handle of the Starting End plate % EndPlate2------Handle of the Ending End plate % X1 and X2 are the 3x1 vectors of the two points % R is the radius of the cylinder/cone R(1) = start radius, R(2) = end radius % n is the no. of elements on the cylinder circumference (more--> refined) % cyl_color is the color definition like 'r','b',[0.52 0.52 0.52] % closed=1 for closed cylinder or 0 for hollow open cylinder % lines=1 for displaying the line segments on the cylinder 0 for only % surface % % Typical Inputs % X1=[10 10 10]; % X2=[35 20 40]; % r=[1 5]; % n=20; % cyl_color='b'; % closed=1; % % NOTE: There is a MATLAB function "cylinder" to revolve a curve about an % axis. This "Cylinder" provides more customization like direction and etc 

This is how I ended up using the function ...

Given the center point c and the unit vector uv , and the cylinder height h and radius r , here is the end use:

 Cone(c,c+uv*h,[0,r],20,'r',0,0); 

The last four parameters: 20 faces, color red, not closed at the end and does not draw lines.

UPDATE: example with pictures

random cones in matlab

 clearvars close all format compact C = {'k','b','r','g','y',[.5 .6 .7],[.8 .2 .6]}; % Cell array of colros. % rng(17);% set a seed num_faces = 20; closed = 0; draw_edges = 1; figure hold on axis equal set(gca, 'Projection', 'orthographic'); for i = 1:5 radius = rand(1); % get two end points end_pts = rand(2,3); % draw the cone Cone(end_pts(1,:), end_pts(2,:),[0, radius], ... 20, C{mod(i,7)+1},closed, draw_edges) alpha(0.3) end 

The Cone function is a variation of the Cylinder function that someone also posted on file sharing:

http://www.mathworks.com/matlabcentral/fileexchange/13995-cylinder/content/Cylinder.m

Hope this helps.

+3
source share

All Articles