CANNON PARTICLE !!!
so yeah once in a time i was kinda bored to i decided to make a cannon program in the about:blank page using only javascript, it worked and now i want to share it with yall in this new revamped version, to use just:
1. select your prefered initial velocity(positive), angle(from 0 to 90 degrees) and gravity
2.click the FIRE button
3. optional: with the cancel button u can stop the bullet at a moment
have fun with it!
you can also find this animation-less version, but be careful as to not make distance of travel too far!
how does this work????
quite simple, the process for how i made this thingy was kinda like this:
we have a particle with starting velocity:
(vx, vy)
now, at a moment in time t , the velocity of the particle will be:
v(t) = (vx, vy - gt)
by doing an integral to get the position we obtain:
∫ v(t) dt = ∫ (vx, vy - gt) dt
p(t) = (t vx, t vy - g t 2 2 )
now, how can we make this a function? well, notice how the x conmponent is on a linear form t vx , so if we define t' = t vx , then:
p(t') =(t', vy vx t - g2 vx 2 t 2 )
look at that! it has got the structure of a function (x, f(x)), with this we got a function that we can evaluate:
f(x) = vy vx x - g2 vx 2 x 2
this function is now then evaluated from x=0 to the value where our particle will hit the floor
and how u got the data??
quite simple, we just need to solve three equations:
TRAVEL TIME
for travel time, we solve this equation:
vy - gt = -vy
which with some manipulations:
2vy = gt
t = 2 vy g
this is the time it takes for particle to hit ground again
DISTANCE OF TRAVEL
we just take the travel time, and multiply by horizontal component of velocity:
d = 2 vx vy g
HIGHEST ALTITUDE:
get distance of travel, divide by two, and the evaluate the result in the function constructed before:
d/2 = vx vy g
h = vy vx * vx vy g - g2 vx 2 ( vx vy g ) 2
with some cancelations, we obtain:
h = vy2 g - vy2 2g
h = vy2 2g
this is our height
made with amogus by ALonelyPhoenix (man, css is painful)