Public Group

# calcute a path to intercept an object along its own path

This topic is 2510 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Object A wants calculate an angle at which to Intercept Object B along its path of movement in an x,y system. Speed of A&B is known, as well as distance between the 2 and angle of movement of A&B. (and A can rotate freely)

Although this sounds rather simple to me, i have thought hard about it and couldnt come up with a solution so far. I thought the best solution would probably be to use a system of linear equasions, but i couldnt figure out how to do it right, as well as how to implement it in java. So the second best idea i had was to treat Time as a constant and use a recursive method that increments the time factor until a solution is found or until it would take too long.

3 vectors: (angles are absolute)
- direct line from A to B: length l, angle alpha
- line from target to contact point: length vB*Time, angle beta
- line from A to contact point: length vA*Time, angle gamma

Speed vA/B is 1 or 2 pixels per frame. (along the axis of movement, so the actual movement is cos/sin*v for either x or y)
Speed for Object A can be assumed to be 2 since it wants to actually catch B, speed for B can either be 1 or 2.
So i use 2 equations that add up the x,y components of the 2 first vectors to get to the third:

Since cosine and sine switch places depending on where the angle is facing the whole thing gets a little complicated.

(A->contact) = (A->B) + (B->contact)

X/Y: 2 * t * cos/sin(gamma) = l * cos/sin(alpha) + vB * t * cos/sin(beta)

--->cos/singamma:

X/Y: cos/sin(gamma) = (l * cos/sin(alpha)) / (2 * t) - vB * cos/sin(beta) / 2

At this point i have only constants on the right side of the equation and i can solve it. The problem that remains is, for alpha and beta i can easily find out whether to use sine or cosine for x/y, but for gamma i cant. So right now my method returns a [2]-array of sine of cosine, which i could use to find out the angle, but i dont know which is which. If either of the values is smaller than -1 or bigger than 1 the method calls itself again and increments t by 1, which i figured should work out for values of t that are too small to make contact possible.

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633765
• Total Posts
3013730
×