matlab如何用curve画圆,使用Matlab画出圆圆锥圆柱.doc

用Matlab画圆柱圆台圆锥

自己建一个M文件,命名任意,如tu.m

在命令窗口输入:tu

%以下为tu.m文件

clc

clear 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.M

function [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 Cone

length_cyl=norm(X2-X1);

% Creating 2 circles in the YZ plane

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值