3
x = r*cos(t) + ur*cos(t)    
y = r*sin(t) + ur*sin(t)
z = zeros(length(x))   

Cylinder length is along the z direction from 0 to 10.

The variable ur changes with each value of z. It represents a variable thickness of the cylinder.

I tried plot3() by making z a matrix but it creates a circle, not a cylinder.

Dev-iL
  • 23,742
  • 7
  • 57
  • 99
Raza Mehdi
  • 35
  • 7
  • your `z` is just zero (in fact, it is a square matrix with zeros depending on the length of `t`). So there is 3rd dimension and `plot3()` will give you just a cricle – max Dec 29 '19 at 15:53

2 Answers2

1

z = ones(1,numel(x))'*(0:10)

would do the trick to get the values to make a cylinder with athe z from 0 to 10.

MarkP
  • 21
  • 4
1

This code may help, instead of using pol2cart instruction, you can use your own equations, the resultant shape depends on the range specified in meshgrid at beginning, also I added Rotation option, of course you can comment that to ignore that option if you do like.

%===========================
% Close and Clear
%===========================
clc
close all
clear all
%===========================
% making a cylinder
%===========================
[theta, r, h] = meshgrid(0:.1:6.28,0:0.1:1, 0:.2:4); 
%====================================
% transforming the coordinate system
%====================================
[x, y, z] = pol2cart(theta, r, h); 
%====================================================
% rotating the data points around x axis by 60 degree
%====================================================
P = (rotx(60) * [x(:), y(:), z(:)]')';
%P = [x(:), y(:), z(:)];
%=======================================
%=======================================
% Drawing The Cloud Points
%=======================================
figure('Name','Cylinder Point Cloud','NumberTitle','off');
scatter3(P(:, 1), P(:, 2), P(:, 3)); % plots a circles around sample points
title('Cylinder Point Cloud');
axis equal
%===============================================
Bilal
  • 3,191
  • 4
  • 21
  • 49
  • 1
    Your code will generate a cylinder of uniform thickness but my question is related to variable radius/thickness – Raza Mehdi Jan 01 '20 at 01:52