




全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
用Matlab画圆柱圆台圆锥自己建一个M文件,命名任意,如tu.m在命令窗口输入:tu%以下为tu.m文件clcclear all%圆柱X,Y,Z=cylinder(15.7,20);h=1.22*Z;surf(X,Y,h);hold on%圆台a=25/180*pi;%可修改b=12.06/180*pi;%可修改r=3.2;%可修改h1=r*sin(a+b)/sin(a-b)*sin(a);%h1=0.66;X1=0 0 1.22;%底面中心坐标X2=0 0 1.22+h1;%顶面中心坐标L2=15.7-2.6/tan(a);r=15.7 L2;n=20;cyl_color=b;closed=1;lines=1;cone,EndPlate1,EndPlate2 = Cone(X1,X2,r,n,cyl_color,closed,lines)%调用圆台的函数%圆锥X2,Y2,Z2=cylinder(L2:-0.2:0);h2=1.5;%可修改Z2=h2*Z2;Z2=Z2+ones(size(Z2)*(1.22+h1);surf(X2,Y2,Z2);grid on%r=0:0.1:3.2;R=0:0.1:15.7;%alpha=0:pi/20:2*pi;%角度0,2*pi%x=R*cos(alpha);%y=R*sin(alpha);%a=39.0;b=12.06;%h=1.22+R.*tan(b)+r.*sin(a);%x,y=meshgrid(-4:0.5:4);%surf(h)新建一个M文件,如下命名为Cone.Mfunction Cone,EndPlate1,EndPlate2 = Cone(X1,X2,R,n,cyl_color,closed,lines)% This function constructs a cylinder connecting two center points % % Usage :% Cone,EndPlate1,EndPlate2 = Cone(X1,X2,R,n,cyl_color,closed,lines)% % Cone-Handle of the cone% 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/cone R(1) = start radius, R(2) = end radius% 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 5;% n=20;% cyl_color=b;% closed=1;% % NOTE: There is a MATLAB function cylinder to revolve a curve about an% axis. This Cylinder provides more customization like direction and etc%圆台的函数,文件名为Cone.m% Calculating the length of the Conelength_cyl=norm(X2-X1);% Creating 2 circles in the YZ planet=linspace(0,2*pi,n);xa2=R(1)*cos(t);xa3=R(1)*sin(t);xb2=R(2)*cos(t);xb3=R(2)*sin(t);% Creating the points in the X-Directionx1=0 length_cyl;% Creating (Extruding) the cylinder points in the X-Directionsxx1=repmat(x1,length(xa2),1);xx2=xa2 xb2;%xx2=repmat(x2,1,2);xx3=xa3 xb3;%xx3=repmat(x3,1,2);% Drawing two filled cirlces to close the cylinderif 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 OriginCone=mesh(xx1,xx2,xx3);% Defining Unit vector along the X-directionunit_Vx=1 0 0;% Calulating the angle between the x direction and the required direction% of Cone through dot productangle_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 Cone in% X-direction to the required arbitrary direction through cross productaxis_rot=cross(1 0 0,(X2-X1) );% Rotating the plotted Cone and the end plate circles to the required% anglesif angle_X1X2=0 % Rotation is not needed if required direction is along X rotate(Cone,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) endend% Till now Cone has only been aligned with the required direction, but% position starts from the origin. so it will now be shifted to the right% positionif 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)endset(Cone,XData,get(Cone,XData)+X1(1)set(Cone,YData,get(Cone,YData)+X1(2)set(Cone,ZData,get(Cone,ZData)+X1(3)% Setting the color to the Cone and the end platesset(Cone,AmbientStrength,1,FaceColor,cyl_color,FaceLighting,gouraud);%,EdgeColor,none)if closed=1 set(EndPlate1 EndPlate2,AmbientStrength,1,FaceColor,cyl_color,FaceLighting,gouraud);%,EdgeColor,none)else EndPlate1=; EndPlate2=;end% If lines are not needed making it disapearif lines=0 set(Cone,EdgeAlpha,0)end%shading faceted % faceted flat interp;%camlight; %light;%lighting gouraud; %flat g
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024-2025学年河南省郑州市八十八中八年级(下)期中数学试卷(含答案)
- 养殖小区出租合同范本
- 房东日常收租合同范本
- 公共平台转让合同范本
- 夫妻买房的合同范本
- 空房公寓出租合同范本
- 自家车队维修合同范本
- 车位分期还款合同范本
- 定制制服服装合同范本
- 农业种植西红柿合同范本
- 外研版高一到高三单词表
- 2025年度智慧社区租赁意向协议书
- 《园林绿化工程施工方案》知识培训
- 《鼻内镜上颌窦开放》课件
- 2025版商业综合体物业服务合同招标文件3篇
- 建设工程降低成本、提高经济效益措施
- 课程思政融合深度学习的“实变函数与泛函分析”课程教学体系构建
- 助听器与辅听设备基本性能及使用建议的专家共识
- 2025年日历表( 每2个月一张打印版)
- 四年级下册数学200道竖式计算
- 中职班主任管理培训
评论
0/150
提交评论