How do I create a sphere without sphere function that will inflate like a balloon utilizing the getframe function?

7 次查看(过去 30 天)
I have a basic code set for movement of a string that I would like to follow suit with a sphere inflating from an arbitrary initial radius (R_0) to an end radius (R_F):
clear String u x
c = 1.0; % wave equation constant
k = 0.5; % maximum initial string deflection
L = 1.0; % length of string
N = 3; % number of Fourier sine terms
M = 501; % number of movie frames, each corresponding to a specific time
TT = 5.0; % total time
x = [0.000:0.01:1.00]';
hold off
for T = 1:1:M
t = (T - 1) * (TT / (M - 1));
u = zeros(size(x));
for n = 1:1:N
lambdan = c * n * pi / L;
bn = (8 * k / (n^2 * pi^2)) * sin(n * pi / 2);
u = u + bn * cos(lambdan * t) * sin(n * pi * x / L);
end
plot(x,u,'LineWidth',6,'Color','green')
xlim([0.0 1.0])
ylim([-0.5 0.5])
String(:,T) = getframe;
end
movie(String,1,60)
How can I set this coding above to suit my purposes for a sphere? Again, not utilzing the Sphere function that exists in matlab.
Thank you

回答(1 个)

darova
darova 2019-11-12
Use surf to create a 3D surface
rr = linspace(0,0.5,20);
tt = linspace(0,2*pi,40);
[R,T] = meshgrid(rr,tt);
[X,Y] = pol2cart(T,R);
for
% ...
z = interp1(x-0.5,u,rr);
[Z,~] = meshgrid(z,tt);
surf(X,Y,Z)
pause(0.05)
end
  4 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by