开发者

Space Physics for missiles, spaceships - Learning Calculus edition

开发者 https://www.devze.com 2023-04-05 01:36 出处:网络
Supposing we have Missile A, with a position vector and velocity magnitude (ignoring acceleration, as many games do) and Spaceship B, with position and velocity vectors. Now,开发者_运维技巧 this missi

Supposing we have Missile A, with a position vector and velocity magnitude (ignoring acceleration, as many games do) and Spaceship B, with position and velocity vectors. Now,开发者_运维技巧 this missile, being a Nasty Missile of Seeking, will try to find the best intercept for Spaceship B.

Missile A has two advantages: It knows calculus and it can calculate the roots of polynomials. However, the missile, or to abstract, the programmer, is still learning calculus and wants to know if he has the right equation. (Polynomial roots will be solved by a nice fellow called Jenkins-Traub Code Implemented From Netlib)

To wit:

  • mp = Missile Position

  • mv = Missile Velocity

  • sp = Spaceship Position

  • sv = Spaceship Velocity

  • t = Time

According to the programmer's best guess, the equation for intercept is: tspsv + tspmv - tmpsv - tmpmv

Except I'm pretty sure I'm headed down the wrong track entirely, as there should probably be some exponents in that mess; this being an attempt at solving: (sp-mp)(sv-mv)(t)

My other option is differentiating (sp-mp)(sv-mv)^2, but I wanted to get feedback first, partly because, unless I'm mistaken, '(sp-mp)' resolves to '1'. And that seems...Odd. OTOH, the rate at which that function is changing might be what I'm looking for.

So - What have I gotten wrong, where and why?

Thanks.

Potentially-useful link to first thread.

Edit:

Summing the equations:

(a+bx) + (c+ex)

(a+1bx^0) + (c+1ex^0)

(a+1) + (c+1)

Non-viable.

Product of the equations:

(a+bx)(c+ex)

ac+aex+cbx+bex^2

Not a polynomial (can't solve with Jenkins-Traub) and doesn't quite look right.

ac+1aex^0+1cbx^0+2bex^1

ac+ae+cb+2bex

And definitely not that, I think.


The 2D equations of motion for the missile are (assume starting at t=0)

[ mpx(t) = mpx(0) + mvx*t , mpy(t) = mpy(0) + mvy*t ]

the spaceship motion is

[ spx(t) = spx(0) + svx*t , spy(t) = spy(0) + svy*t ]

where mpx(0) mpy(0) spx(0) spy(0) are the initial position components

So to intersect you must have mpx(t)=spx(t) and mpy(t)=spy(t). Which is two equations to solve for two unknowns. One may be the time to intercept t, and the other the direction of the missile given by slope=mvy/mvx. Or it could be the initial position of the missle mpx(0) and mpy(0), or the velocity components given a target intercept time.

It is not clear from the question what you a looking for.


Instantaneous Solution

Position_Ship + t*Velocity_Ship = Position_Missile + t*Velocity_Missile

If they are set to intercept then you can trivially solve for t over either dimension.

If you want to determine Velocity_Missile we need one more constraint.

N = (Position_Missile - Position_Ship) ^ Velocity_Ship (cross-product)

N dot Velocity_Missle = 0

This will give you a pair or linear simultaneous equations.

Dynamic Solution

If the Velocity_Missile is initially given and we want to apply accelleration until we get within a limiting radius, then it becomes thorny. You can get an aesthetically pleasing solution using a simple curve of persuit, or we can get numerical...

Let Velocity_Missile' be the instantaneous solutions from above, derive the corresponding t', given the power of the motor you can calculate the time t'' taken to deliver that change in velocity. Add this t''*Ship_Velocity to get an updated target position. Iterate.


If you have mp, mv and sp, then to calculate sv and t:

mp+mv(t)=sp+sv(t) and |sv|=q (maxspeed)
mp+mv(t)-sp+sv(t)=0

mpx+mvx*t-spx+svx*t=0
mpy+mvy*t-spy+svy*t=0

svx^2+svy^2=q^2
svx^2+svy^2-q^2=0

Which we then can solve:

(mpx-spx)/t+mvx=svx
(mpy-spy)/t+mvy=svy

((mpx-spx)/t+mvx)^2+((mpy-spy)/t+mvy)^2=q^2
(mpx-spx)^2/t^2+2*mvx*(mpx-spx)/t+mvx^2+(mpy-spy)^2/t^2+2*mvy*(mpy-spy)/t+mvy^2=q^2
((mpx-spx)^2+(mpy-spy)^2)/t^2+(2*mvx*(mpx-spx)+2*mvy*(mpy-spy))/t+mvx^2+mvy^2-q^2=0
((mpx-spx)^2+(mpy-spy)^2)+(2*mvx*(mpx-spx)+2*mvy*(mpy-spy))*t+(mvx^2+mvy^2-q^2)*t^2=0
((mpx-spx)^2+(mpy-spy)^2)/(mvx^2+mvy^2-q^2)+(2*mvx*(mpx-spx)+2*mvy*(mpy-spy))/(mvx^2+mvy^2-q^2)*t+t^2=0

c = (mvx^2+mvy^2-q^2)
if   a = (2*mvx*(mpx-spx)+2*mvy*(mpy-spy))/c
and  b = ((mpx-spx)^2+(mpy-spy)^2)/c
then t = -a/2+-sqrt(a^2/4-b)

a/2 = (2*mvx*(mpx-spx)+2*mvy*(mpy-spy))/2c
a/2 = (mvx*(mpx-spx)+mvy*(mpy-spy))/c
a^2/4 = (mvx^2*(mpx-spx)^2+2*mvx*(mpx-spx)*mvy*(mpy-spy)+mvy^2*(mpy-spy)^2)/c^2

b/c^2=((mpx-spx)^2+(mpy-spy)^2)*c
b/c^2=((mpx-spx)^2+(mpy-spy)^2)*(mvx^2+mvy^2-q^2)
b/c^2=mvx^2(mpx-spx)^2+mvx^2(mpy-spy)^2+mvy^2(mpx-spx)^2+mvy^2(mpy-spy)^2-q^2(mpx-spx)^2-q^2(mpy-spy)^2

t = -(mvx*(mpx-spx)+mvy*(mpy-spy))/c +- sqrt((mvx^2*(mpx-spx)^2+2*mvx*(mpx-spx)*mvy*(mpy-spy)+mvy^2*(mpy-spy)^2)-(mvx^2(mpx-spx)^2+mvx^2(mpy-spy)^2+mvy^2(mpx-spx)^2+mvy^2(mpy-spy)^2-q^2(mpx-spx)^2-q^2(mpy-spy)^2))/c

t = -(mvx*(mpx-spx)+mvy*(mpy-spy))/c +- sqrt((2*mvx*(mpx-spx)*mvy*(mpy-spy))-(mvx^2(mpy-spy)^2+mvy^2(mpx-spx)^2)+q^2((mpx-spx)^2+(mpy-spy)^2)))/c

t = -(mvx*(mpx-spx)+mvy*(mpy-spy))/c +- sqrt(-(mvx(mpy-spy)-mvy(mpx-spx))^2+q^2((mpx-spx)^2+(mpy-spy)^2)))/c

t = -(mvx*(mpx-spx)+mvy*(mpy-spy))/c +- sqrt(-(mvx(mpy-spy)-mvy(mpx-spx))^2+q^2(c+q^2))/c
t = -(mvx*(mpx-spx)+mvy*(mpy-spy))/c +- sqrt(-(mvx(mpy-spy)-mvy(mpx-spx))^2+q^2(c+q^2))/c

t = -(mvx*(mpx-spx)+mvy*(mpy-spy))/c +- sqrt(-(mvx(mpy-spy)-mvy(mpx-spx))^2+q^2(c+q^2))/(mvx^2+mvy^2-q^2)

I don't have time to simplify further, but it can be done, or just evaluate it.

Then plug t back into:

svx=(mpx-spx)/t+mvx
svy=(mpy-spy)/t+mvy

To get the s vector.

Maybe I've done a mistake somewhere...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号