我需要通过在由两条曲线形成的形状的y轴上旋转来创建表面。我已经有了这两条曲线的等式。 Here is the shape
我已经创建了曲面,但是对于由此曲线之一形成的simetric cone,这是我的脚本:
h=20;
rw=1;
hw=5;
L=25;
r=linspace(rw,L,50);
theta=linspace(0,2*pi,25);
[r,theta] = meshgrid(r,theta);
xx=r.*cos(theta);
yy=r.*sin(theta);
z=sqrt(log(r/rw)*(h^2-hw^2)/log(L/rw)+hw^2); %Fuction of curve
surf(xx,yy,z)
在另一条曲线中是相同的函数(z),但改变r,h,L
感谢您的帮助,
答案 0 :(得分:2)
你应该使用参数网格而不是标量:
% parameters
h=[20 25];
rw=1;
hw=5;
L=[25 30];
nr = 50;
nt = 25;
theta=linspace(0,2*pi,nt);
rmax = linspace(L(1),L(2),floor((nt+1)/2));
% generating **grids** for all parameters
l = [linspace(L(1),L(2),floor((nt+1)/2)) linspace(L(2),L(1),floor((nt)/2))];
hh = [linspace(h(1),h(2),floor((nt+1)/2)) linspace(h(2),h(1),floor((nt)/2))];
[~,thetaGrid] = meshgrid(1:nr,theta);
[~,lGrid] = meshgrid(1:nr,l);
[~,hGrid] = meshgrid(1:nr,hh);
rGrid = zeros(size(thetaGrid));
for ii = 1:floor((nt+1)/2)
rGrid(ii,:) = linspace(rw,rmax(ii),nr);
end
rGrid(ceil((nt+1)/2):end,:) = rGrid(floor((nt+1)/2):-1:1,:);
% set coordinate grids
xx=rGrid.*cos(thetaGrid);
yy=rGrid.*sin(thetaGrid);
z=sqrt(log(rGrid./rw).*(hGrid.^2-hw^2)./log(lGrid./rw)+hw.^2); %Fuction of curve
% plot
surf(xx,yy,z)