Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Question : Finding the closest intersection point for two moving objects
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TerranceN




PostPosted: Tue May 25, 2010 8:16 pm   Post subject: 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:

Posted Image, might have been reduced in size. Click Image to view fullscreen.

P is the position of the player
Vp is the velocity of the player
Ω 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
Θ 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
Ω
E
Ve

Things I don't know:
Θ
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):
Posted Image, might have been reduced in size. Click Image to view fullscreen.

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):
Posted Image, might have been reduced in size. Click Image to view fullscreen.

then I set the two equations equal to each other:
Posted Image, might have been reduced in size. Click Image to view fullscreen.

Then I tried to solve for Θ using this equation solver, but it told me that it is not solvable.

I then tried the same precess, but isolating Θ in two different equations and trying to solve for t:
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Posted Image, might have been reduced in size. Click Image to view fullscreen.

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.
Sponsor
Sponsor
Sponsor
sponsor
The_Bean




PostPosted: Tue May 25, 2010 10:50 pm   Post subject: 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)
Posted Image, might have been reduced in size. Click Image to view fullscreen.

Using the sin law, t can be easily removed
Posted Image, might have been reduced in size. Click Image to view fullscreen.

where
Posted Image, might have been reduced in size. Click Image to view fullscreen.

finally
Posted Image, might have been reduced in size. Click Image to view fullscreen.

tan inverse has to be modified for quadrents.

and heres a very basic example in turing.
(black=player , red=enemy)

Turing:

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




PostPosted: Wed May 26, 2010 6:18 am   Post subject: 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
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: