MATLAB Answers

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

5 views (last 30 days)
Zjuv9021
Zjuv9021 on 12 Nov 2019
Commented: darova on 20 Nov 2019
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

  0 Comments

Sign in to comment.

Answers (1)

darova
darova on 12 Nov 2019
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 Comments

Show 1 older comment

Sign in to comment.

Sign in to answer this question.

Tags