首页 > 解决方案 > 如何绘制圆柱体的可变横截面?

问题描述

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

圆柱体长度沿z从 0 到 10 的方向。

变量ur随 的每个值而变化z。它表示圆柱体的可变厚度。

我尝试plot3()制作z一个矩阵,但它创建了一个圆圈,而不是一个圆柱体。

标签: matlabmatlab-figureparametric-equations

解决方案


此代码可能会有所帮助,而不是使用pol2cart指令,您可以使用自己的方程式,结果形状取决于meshgrid开始时指定的范围,我还添加了 Rotation 选项,当然如果您愿意,您可以评论忽略该选项。

%===========================
% 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
%===============================================

推荐阅读