This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Glotz659's profile picture

[Math] Calculating Icbm-Missiles

Started by Glotz659, 01 August 2013 - 06:48 AM
Glotz659 #1
Posted 01 August 2013 - 08:48 AM
I am trying to get the length of an icbm missile's flight path in order to calculate the flight time:


The missile starts at the launcher position and follows the actual flight path in order to hit the black box (hit point). I have a rather circumstancial function to get the target point in order to hit the hit point (it does not work to aim for the hit point directly because the launchers seem to ignore y-coordinates)

the formula for the above parabola is y = (3 * x * (a + 58) * (a - x)) / (a ^ 2)

to get the arc length, i found the following formula:



but i have absolutely no clue how i would do this in lua

i have a function which returns the flight time for a certain distance so if i had the arc length of both the actual flight path (highlighted green) and the entire parabola, i could just do


local flightTime = (actualPath / fullPath) * getFlightTime( dist )

and for my function: it basically tries to find the a value for a given y by

a = distance

while targetY > parabola(distance, a) do

  a = a+1

end

an then some fancy math to get targetX and targetY

(full code at http://pastebin.com/UJHXXC60 )

i think this could be done better, but again, i have on clue how i would do it
Engineer #2
Posted 01 August 2013 - 09:23 AM
I can help you a little bit with this. As you can see you need to take root and differentiate. In lua, you can take rook like so:

local outcome = math.sqrt( number )
That is not a problem at all, but the trouble comes when we are trying to differentiate. If you have just one formula for the parabola, you can do it manually but to do it automatically can cause problems.
This is the formula:

y = (3x(a + 58)(a - x)) / (a ^ 2)

Note that you cant run this code because this is the mathmathical syntax. Now lets differentiate.. (Im bad at this :P/> )


(3x(a + 58)(a - x)) / a2
(3x(a2 + 58a - ax - 58x )) / a2
(3a2x + 174ax - 3ax2 - 174x2) / a2
(6a + 174 - 6x - 348x) / 2a
(6a + 174 - 354x) / 2a


If you are still with me, that is some calculating to do this automatically. Im not even sure if I have done this right.
Isnt there really another way to do this? :S

Edit: If you are wondering why you need to differentiate, it is because of the f'(x), a normal formula is just f(x). The accent says that you have to differentiate
Glotz659 #3
Posted 01 August 2013 - 10:13 AM
thanks! Using http://www.wolframalpha.com/, i could get the function i needed for getting the arc length.
besides, i do know what differentiation and integration (not sure if it's the right english word) is, but i did'nt know how to do it in lua :P/>

it should be

[ x - ( 3 * (a + 58)^2 * (a - 2 * x)^3) / (2 * a^4) ] from 0 to dist

anyway, the function for finding the a value is still very circumstancial, and i'm not sure how to get the a without the while-loop