# Is this formula correct for simulate 3D Water rocket

3 views (last 30 days)
Le Long on 28 Jun 2021
Commented: Alan Stevens on 29 Jun 2021
I want to simulate 3D Water Rocket only use Acceleration data collected from Sensor GY86
But after I run
The results gave me have a lot of line and isn't correct
I don't know if i use this Calculation is correct or enough or i am missing some steps in formula
I have tried this
function Water_rocket_simulator
clc
close all
clear all
%% CONSTANTS
g = 9.81;
%% INPUT DATA
x = 0;
y = 0;
z = 0;
v0 = 30;
alpha = 90;
t = 0;
dt = 0.01;
%% FIGURE
figure('name','Water Rocket','color','white','numbertitle','off');
hold on
fig_rocket = plot3(x,y,z,'ro','MarkerSize',10,'markerfacecolor','r');
ht = title(sprintf('t = %0.2f s',t));
xlabel('X axis Latitude');
ylabel('Y axis Longtitude');
zlabel('Z axis heights');
grid on
axis equal
axis([1 300 1 300 1 300]);
%% CALCULATION
alpha = alpha/180*pi;
vx = v0*cos(alpha);
vy = v0*cos(alpha);
vz = v0*sin(alpha);
while z>-0.01
t = t+dt;
ax = AccelerationX(:,1)/1000;
ay = AccelerationY(:,1)/1000;
az = AccelerationZ(:,1)/1000;
vx = vx+ax*dt;
vy = vy+ay*dt;
vz = vz+az*dt;
x = x+vx*dt+0.5*ax*dt.^2;
y = y+vy*dt+0.5*ay*dt.^2;
z = z+vz*dt+0.5*az*dt.^2;
plot3(x,y,z,'o','markersize',1,'color','k');
xlabel('X axis Latitude');
ylabel('Y axis Longtitude');
zlabel('Z axis Heights');
grid on
set(fig_rocket,'xdata',x,'ydata',y,'zdata',z);
set(ht,'string',sprintf('t = %0.2f s',t));
pause(0.002);
end
end
Alan Stevens on 29 Jun 2021
Perhaps you need something like
for i = 2:numel(AccelerationX)
t(i) = t(i-1) + dt;
ax(i) = Acceleration(i,1)/1000;
% similarly for ay and az
vx(i) = vx(i-1)+ax(i)*dt;
% ...etc
x(i) = x(i-1) + vx(i)*dt +0.5*ax(i)*dt^2;
% ...etc
end

Alan Stevens on 28 Jun 2021
Probably
vy = v0*cos(alpha);
should be more like
vy = v0*cos(alpha)*cos(beta);
where beta is an angle that will point the rocket out of the x-z plane.
Le Long on 29 Jun 2021
This is the first result i try
I think may be i missing some formula when calculate v and x

R2016a

### Community Treasure Hunt

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

Start Hunting!

Translated by