本代码实现了,由两点和半径绘制空间任意圆柱

function [Cylinder EndPlate1 EndPlate2] = cylinder3(X1,X2,r,n,cyl_color,closed,lines)

%

% This function constructs a cylinder connecting two center points

%

% Usage :

% [Cylinder EndPlate1 EndPlate2] = cylinder3(X1+20,X2,r,n,'r',closed,lines)

%

% Cylinder-------Handle of the cylinder

% 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

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

% n=20;

% cyl_color='b';

% closed=1;

%

%see more information please go to www.matlabsky.cn

% NOTE: There is a MATLAB function "cylinder" to revolve a curve about an

% axis. This "Cylinder" provides more customization like direction and etc

% Calculating the length of the cylinder

length_cyl=norm(X2-X1);

% Creating a circle in the YZ plane

t=linspace(0,2*pi,n)';

x2=r*cos(t);

x3=r*sin(t);

% Creating the points in the X-Direction

x1=[0 length_cyl];

% Creating (Extruding) the cylinder points in the X-Directions

xx1=repmat(x1,length(x2),1);

xx2=repmat(x2,1,2);

xx3=repmat(x3,1,2);

% Drawing two filled cirlces to close the cylinder

if closed==1

hold on

EndPlate1=fill3(xx1(:,1),xx2(:,1),xx3(:,1),'r');

EndPlate2=fill3(xx1(:,2),xx2(:,2),xx3(:,2),'r');

end

% Plotting the cylinder along the X-Direction with required length starting

% from Origin

Cylinder=mesh(xx1,xx2,xx3);

% Defining Unit vector along the X-direction

unit_Vx=[1 0 0];

% Calulating the angle between the x direction and the required direction

% of cylinder through dot product

angle_X1X2=acos( dot( unit_Vx,(X2-X1) )/( norm(unit_Vx)*norm(X2-X1)) )*180/pi;

% Finding the axis of rotation (single rotation) to roate the cylinder in

% X-direction to the required arbitrary direction through cross product

axis_rot=cross([1 0 0],(X2-X1) );

% Rotating the plotted cylinder and the end plate circles to the required

% angles

if angle_X1X2~=0 % Rotation is not needed if required direction is along X

rotate(Cylinder,axis_rot,angle_X1X2,[0 0 0])

if closed==1

rotate(EndPlate1,axis_rot,angle_X1X2,[0 0 0])

rotate(EndPlate2,axis_rot,angle_X1X2,[0 0 0])

end

end

% Till now cylinder has only been aligned with the required direction, but

% position starts from the origin. so it will now be shifted to the right

% position

if closed==1

set(EndPlate1,'XData',get(EndPlate1,'XData')+X1(1))

set(EndPlate1,'YData',get(EndPlate1,'YData')+X1(2))

set(EndPlate1,'ZData',get(EndPlate1,'ZData')+X1(3))

set(EndPlate2,'XData',get(EndPlate2,'XData')+X1(1))

set(EndPlate2,'YData',get(EndPlate2,'YData')+X1(2))

set(EndPlate2,'ZData',get(EndPlate2,'ZData')+X1(3))

end

set(Cylinder,'XData',get(Cylinder,'XData')+X1(1))

set(Cylinder,'YData',get(Cylinder,'YData')+X1(2))

set(Cylinder,'ZData',get(Cylinder,'ZData')+X1(3))

% Setting the color to the cylinder and the end plates

set(Cylinder,'FaceColor',cyl_color)

if closed==1

set([EndPlate1 EndPlate2],'FaceColor',cyl_color)

else

EndPlate1=[];

EndPlate2=[];

end

% If lines are not needed making it disapear

if lines==0

set(Cylinder,'EdgeAlpha',0)

end

matlab画圆柱体,Matlab中如何实现绘制任意圆柱相关推荐

  1. matlab画一个放大图中图

    matlab画一个放大图中图 1 magnify介绍 2 具体思路 3 具体步骤 4 参考 1 magnify介绍 magnify是个动态放大镜,固化后可以用tools>edit plot移动小 ...

  2. matlab三维圆柱体,matlab画三维圆柱体

    数学建模与数学实验 MATLAB作图 二维图形 三维图形 图形处理实例 特殊二.三维图形 作业 1.曲线图 MATLAB作图是通过描点.连线来实现的,故在 画一个曲线图形之前...... 二维图形 三 ...

  3. 用matlab画钥匙,Matlab在锁具装箱问题中的应用.ppt

    <Matlab在锁具装箱问题中的应用.ppt>由会员分享,可在线阅读,更多相关<Matlab在锁具装箱问题中的应用.ppt(10页珍藏版)>请在人人文库网上搜索. 1.Matl ...

  4. 用matlab画树叶,matlab画漂亮的树叶

    美丽的树叶 画叶子 1.构出大形 2.增加漂亮的花纹 3.添加环境 找一找你看到了哪些线条 线描树叶: 美丽的树叶 画叶子 1.构出大形 2.增加漂亮的花纹 3...... 方法和材料表现叶子. 叶子 ...

  5. 怎么用matlab画误差椭圆,matlab画误差椭圆

    一 图4椭圆抛物面 图5双曲抛物面 图6锥面 例如画螺旋曲线的图形,其参数方程设... 数学实验第二次实验报告--MATLAB基本图形绘制_理学_高等教育_教育专区.数... 实验作业 2 解: 代码 ...

  6. matlab画足球,Matlab画足球

    Matlab画足球 科普:足球表面是由12个正五边形和20个正六边形构成,每个正五边形相邻的是5个正六边形,共有60个顶点,90条棱,这些数据可以根据欧拉定理计算得出,不是这里要说明的重点. 思路:先 ...

  7. 如何用matlab画道路,MATLAB中如何将多条曲线画在一张图上

    在用MATLAB处理数据时,有时候,为了几组不同数据之间的对比,我们需要将几组数据对应的曲线画在一张图上,该怎么处理呢? 首先,我们随机产生三组范围不同的数据,数据量都为500,他们的边界分别为[10 ...

  8. matlab画点阵图,利用matplotlib+numpy绘制多种绘图的方法实例

    前言 matplotlib 是Python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地进行制图.本文将以例子的形式分析matplot中支持的,分析中常用的几种图.其中 ...

  9. 如何用matlab画烧杯,MATLAB在动力学实验数据处理中的应用

    · 68· 化 学 教 育(http://www.hxjy.org) 2015年第 2期 MATLAB在动力学实验数 据处理 中的应用 高锦红 (渭南 师范学 院化学与生命科学学院 陕西渭南 7140 ...

最新文章

  1. 深度学习进阶:多分类与TensorFlow
  2. python编写格斗游戏_Python文字小游戏:搏击比赛
  3. HDU 1372 Knight Moves
  4. WebAssembly 系列(五)为什么 WebAssembly 更快? 1
  5. matlab中打不开保存好的模糊控制器,(完整版)matlab模糊控制工具箱的使用
  6. LeetCode OJ - Convert Sorted List to Binary Search Tree
  7. php%3cimg src,XSS小游戏
  8. 怎么修改登录服务器的权限,远程登录服务器权限怎么设置
  9. 二叉树进阶之寻找一棵二叉树中的最大二叉搜索子树
  10. SQL的主键和外键详解!
  11. Premiere 五套特效转场插件合集 FilmImpact Transition Packs V3.6.11
  12. 新零售电商:订单管理系统设计
  13. eclipse格式化代码快捷键
  14. MBR+双硬盘(固态+机械)双系统(win+ubuntu21.04)装机教程
  15. 华硕路由器官改/梅林 设置外置USB-JFFS解救NAND
  16. 2015款Mac笔记本安装Windows10系统到外置移动硬盘教程
  17. 计算机教学管理,计算机教育教学管理论文
  18. 开源利器分享:BitBar 坐看今天你的项目涨了多少star
  19. Linux 运维工程师(一)
  20. redis key导出及删除

热门文章

  1. 大三数据库导论期末课程设计
  2. 深入理解 Java 虚拟机——走近 Java
  3. PyTorch实现的Inception-v3
  4. 如何让自己的手机变成鼠标?
  5. Kylin ext3/4 xfs手动扩容根分区
  6. 用命令窗口合并多个sql文件方法
  7. vue, H5 浏览器 播放器video 嵌入APP(andriod,IOS) 首次有声音自动播放 处理
  8. 创建模板只有从空白html文档开始创建,小陈半夜吃泡面,为什么一面吃,一面眼盯着表?...
  9. BarTender_食品物料标签制作案例
  10. 2021年中国辛醇行业现状、进出口、竞争格局及未来发展趋势分析,DOTP产量增长对辛醇需求形成拉动「图」