% CYLINDER: A function to draw a N-sided cylinder based on the % generator curve in the vector R. % % Usage: [X, Y, Z] = cylinder(R, N) % % Arguments: R - The vector of radii used to define the radius of % the different segments of the cylinder. % N - The number of points around the circumference. % % Returns: X - The x-coordinates of each facet in the cylinder. % Y - The y-coordinates of each facet in the cylinder. % Z - The z-coordinates of each facet in the cylinder. % % Author: Luigi Barone % Date: 9 September 2001 % Modified: Per Sundqvist July 2004 function [X, Y, Z] = cylinder2P(R, N,r1,r2) % The parametric surface will consist of a series of N-sided % polygons with successive radii given by the array R. % Z increases in equal sized steps from 0 to 1. % Set up an array of angles for the polygon. theta = linspace(0,2*pi,N); m = length(R); % Number of radius values % supplied. if m == 1 % Only one radius value supplied. R = [R; R]; % Add a duplicate radius to make m = 2; % a cylinder. end X = zeros(m, N); % Preallocate memory. Y = zeros(m, N); Z = zeros(m, N); v=(r2-r1)/sqrt((r2-r1)*(r2-r1)'); %Normalized vector; %cylinder axis described by: r(t)=r1+v*t for 0