matlab - 如何绘制圆柱体的可变横截面?
问题描述
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
一个矩阵,但它创建了一个圆圈,而不是一个圆柱体。
解决方案
此代码可能会有所帮助,而不是使用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
%===============================================
推荐阅读
- powershell - 如何在 Powershell 中从 $pattern 中删除多行文本块
- azure-ad-b2c - 关于文化的问题:RFC5646 和 ContentDefinitions
- python - 合并两个复杂的 JSON 对象
- mysql - MySQL在重复值中选择一个字段
- docker - 如何在生产环境中发布在 docker 容器中运行的网站?
- android - 房间无法弄清楚如何将此字段保存到数据库中
- angular - 如何使用 JWT 有效负载存储会话用户数据?
- javascript - 获取 puppeteer 页面的默认超时设置
- python - 有没有办法按日期显示视图?
- php - 如何在控制器 Zend Framework 3 中使用 2 表模型