
-----------------------------------
TerranceN
Tue May 25, 2010 8:16 pm

Question : Finding the closest intersection point for two moving objects
-----------------------------------
Since this is not language specific I figured I would put this here.


Explanation of Question

For my geometry wars clone, I am trying to create an enemy that can cut the player off instead of just following the player. Here is a diagram of the problem:

http://img686.imageshack.us/img686/4710/diagram2.png

P is the position of the player
Vp is the velocity of the player
&#937; is the angle the player is moving in standard position (this is why I drew the horizontal lines)

E is the position of the enemy
Ve is the velocity of the enemy
&#920; is the angle the enemy is moving in standard position

I is where the interception will occur
t is the time it takes for the enemy to intercept the player

Things I know:
P
Vp
&#937;
E
Ve

Things I don't know:
&#920;
I
t

My question is how would I go about finding any of the unknowns (once I know one it is easy to plug that in to the equations I know (see below)).


What I Have Tried

I started off with some equations that I know are true (note that I split 2d points into their x and y components):
http://img293.imageshack.us/img293/3760/baseequations.png

The next thing I did is try to remove an unknown by isolating t in two different equations (I'm only showing one cause the other is the same rearranging but it is y instead of x and sine instead of cosine):
http://img710.imageshack.us/img710/4388/solvedfort.png

then I set the two equations equal to each other:
http://img109.imageshack.us/img109/8505/stillmissingthetaunsolv.png

Then I tried to solve for &#920; http://img37.imageshack.us/img37/8030/solvedfortheta.png
http://img80.imageshack.us/img80/2526/stillmissingtunsolvable.png

But once again this is unsolvable.

I don't know what to do from here, and this problem has stumped my MSIP teacher (who is a math teacher), any help will be rewarded with bits and a solution (or something that directly leads me to one) will be rewarded with karma.

-----------------------------------
The_Bean
Tue May 25, 2010 10:50 pm

Re: Question : Finding the closest intersection point for two moving objects
-----------------------------------
Potentially found a solution for the unknown angle. 
Everything else should be simple after that.

Starting with this diagram (messed up one variable from yours)
http://lh6.ggpht.com/_8GyRohGyNhU/S_yWltKbzZI/AAAAAAAAAG0/o3SN0II55eQ/diagram.png

Using the sin law, t can be easily removed
http://lh4.ggpht.com/_8GyRohGyNhU/S_yWlRr68eI/AAAAAAAAAGo/BShOoSoOATk/form1.png

where
http://lh5.ggpht.com/_8GyRohGyNhU/S_yWle_z0AI/AAAAAAAAAGs/BC88zSWhg-o/form2.png

finally
http://lh3.ggpht.com/_8GyRohGyNhU/S_yWlobMirI/AAAAAAAAAGw/qg0CkX6DCSg/form3.PNG

tan inverse has to be modified for quadrents.

and heres a very basic example in turing.
(black=player , red=enemy)


type player :
    record
        x, y : real
        v : real
        a : real
    end record

var p, e : player

function setAngle (x, y : real) : real
    if x = 0 and y = 0 then
        result 0
    elsif x = 0 and y > 0 then
        result 90
    elsif x = 0 and y < 0 then
        result 270
    elsif y = 0 and x > 0 then
        result 0
    elsif y = 0 and x < 0 then
        result 180
    elsif x > 0 and y > 0 then
        result arctand (y / x)
    elsif x < 0 and y > 0 then
        result 180 + arctand (y / x)
    elsif x > 0 and y < 0 then
        result 360 + arctand (y / x)
    elsif x < 0 and y < 0 then
        result 180 + arctand (y / x)
    else
        result 0
    end if
end setAngle

for j : 1 .. 5
    p.x := Rand.Int(50,maxx-50)
    p.y := Rand.Int(50,maxy-50)
    p.v := 1
    p.a := Rand.Int(0,360)

    e.x := Rand.Int(50,maxx-50)
    e.y := Rand.Int(50,maxy-50)
    e.v := 1.5
    var beta := setAngle (e.x - p.x, e.y - p.y) - p.a
    e.a := setAngle (p.x - e.x, p.y - e.y) + arcsind (sind (beta) * p.v / e.v)


    for i : 1 .. 200
        Draw.FillOval (round (p.x), round (p.y), 1, 1, 7)
        Draw.FillOval (round (e.x), round (e.y), 1, 1, 12)
        p.x += (cosd (p.a) * p.v)
        p.y += (sind (p.a) * p.v)

        e.x += (cosd (e.a) * e.v)
        e.y += (sind (e.a) * e.v)
        delay (10)
    end for
end for




-----------------------------------
TerranceN
Wed May 26, 2010 6:18 am

RE:Question : Finding the closest intersection point for two moving objects
-----------------------------------
Thanks! I will try this solution today, but from what I have read in your post and seen in your example it is exactly what I was looking for. +1 Karma +100 Bits
