M
M
Maxim Grechushnikov2017-01-10 17:20:39
Algorithms
Maxim Grechushnikov, 2017-01-10 17:20:39

How to calculate point and time of intersection of 2 objects?

There are 2 objects on the map. one moves from left to right, the other from top to bottom. The speed and time of the start of the journey are known.
1. How do you know if two objects intersect?
2. How can I find out the time and place of the crossing?
3. The same, but on the map. one from Moscow to ECB, the other from St. Petersburg to Chelyabinsk. Where and when will they cross?
Interested in the search vector for the answer to the question. I don't even know where to dig. Question 3, I suspect, can be solved by knowing the sum of the path segments, therefore, in fact, it will turn out to be a special case of the first two questions.
You can't transfer to the frontend. The calculations must be on the server.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GavriKos, 2017-01-10
@GavriKos

Option on the forehead, but without 3 points.
You have a starting point and a direction vector. Based on this, you build a line passing through the starting point and coinciding (not sure about the term) with the vector. You get the natural equation of a straight line. Do the same for the second point. Next, find the point of intersection of these two lines (this is easy, knowing their equations). Great, there is an intersection. And it is the only one (if it exists, the lines can be parallel). Next, count the distance from the first point to the intersection point, and from the second to the intersection point. You take the speeds of the objects (they must be known - otherwise it is unsolvable), and calculate how much it will take for everyone to overcome the path from the starting point to the intersection point. If the time coincides, they will intersect.

D
Dmitry Alexandrov, 2017-01-10
@jamakasi666

Because in the game tags, for example, let's start from updates.
Let's assume that your game logic is updated 60 times per second.
We know the starting points, direction and acceleration of both points ("A" and "B").
Suppose that you also update the movements along with the log 60 times per second (it's just that they usually knit in their own way and it can be not 60, but less, or vice versa more).
Knowing all of the above, you do everything step by step again for an example and understanding:
1) Find an abstract point of intersection without taking into account the time "C". If such a point does not exist, then the rest of the points are skipped.
2) In the most common cycle, subtract how long it will take point "A" to reach the intersection point "C", taking into account speed and direction.
3) Repeat point (2) for point "B".
4) Compare the results obtained in step (2) and (3) and if they are equal, then the points will intersect.

G
GreatRash, 2017-01-10
@GreatRash

https://code.tutsplus.com/tutorials/predicting-col... You
need flash to see the examples.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question