- Convert the x and y ‘sym’ vectors into double vector
Frame increase in comet function
5 次查看(过去 30 天)
显示 更早的评论
Im trying to make an animation of a point following a set path described by 2 functions, but despite having 6.2K numbers in my x and y arrays, when I use the comet function, it only takes 11 of them leading to a very choppy animation, any way to fix this?. Here is my code, it includes some other calculations I had to do.
syms t
theta = (2/pi)*sin(pi*t);
r = 25/(t+4);
vr = diff(r,t);
vth = r*diff(theta,t);
v_1_segundo = double(sqrt(((subs(vr,t,1))^2)+((subs(vth,t,1))^2)))
ar = diff(r,t,2)-r*(diff(theta,t)^2);
ath = r*diff(theta,t,2)+2*diff(r,t)*diff(theta,t);
a_1_segundo = double(sqrt(((subs(ar,t,1))^2)+((subs(ath,t,1))^2)))
a_relativa = subs((diff(r,t,2)),t,1)
theta = theta-(pi/2);
at = 0:0.001:2*pi;
theta = subs(theta,t,at);
r = subs(r,t,at);
x = cos(theta).*r;
y = sin(theta).*r;
comet(x,y)
0 个评论
采纳的回答
Sachin
2023-3-23
Hi
I understand that you are having an issue with your animation values. The ‘Comet’ function is using all the values of the x and y vector.
I suggest you try these workarounds to understand the animation plot better:
x_double = double(x)
y_double = double(y)
2. Find the minimum and maximum of the converted double vectors. These values match the plots minimum and maximum values.
min(x_double)
max(x_double)
min(y_double)
max(y_double)
更多回答(1 个)
Jack
2023-3-23
The comet function in MATLAB creates a smooth animation by connecting a small number of data points with curves. By default, it uses only a small subset of the data points to create the animation, which can result in a choppy animation if the number of data points is very large.
To increase the number of data points used by comet, you can use the comet3 function instead, which allows you to specify the x, y, and z coordinates of the data points. Since your path is two-dimensional, you can simply set the z coordinates to zero. Here's an example:
% Generate path data
at = 0:0.001:2*pi;
theta = subs(theta,t,at);
r = subs(r,t,at);
x = cos(theta).*r;
y = sin(theta).*r;
% Create animation
comet3(x, y, zeros(size(x)));
This should create a smoother animation by using more data points to interpolate the path. You can adjust the step size in the at array to control the density of the data points and the smoothness of the animation.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!