Intersection of two Moving Objects with Latitude/Longitude Coordinates

前端 未结 1 1966
礼貌的吻别
礼貌的吻别 2021-01-03 09:45

This issue I can\'t really solve till now although I read through several articles already - hope somebody can help here.

Facts (know variables):

  • Two m
相关标签:
1条回答
  • 2021-01-03 10:24

    If the distances are small and you convert the latitude/longitude coordinates to x,y coordinates on a flat plane as you suggest, using e.g. the answers to this question, then the math needed to solve this problem is quite straightforward.

    The image below shows the location of chaser and target at time 0 (red and blue dot), their velocity (the circles show their range after time 1, 2, 3...) and the trajectory of the target (blue ray).

    The green curve contains all locations where target and chaser could be at the same moment if they keep moving at their current velocity. The intersection of this curve with the target's trajectory is the interception point (pink dot).

    If the interception happens after time t, then the distance travelled by chaser and target is t.vc and t.vt. We also know the distance d between the chaser and target at time 0, and the angle α between the line segment connecting chaser and target and the target's trajectory. If we enter these into the cosine rule we get:

    (t . vc)2 = (t . vt)2 + d2 - 2 . d . t . vt . cos(α)

    Which transforms to this quadratic equation when we solve for time t:

    (vc2 - vt2) . t2 + (2 . d . vt . cos(α)) . t - d2 = 0

    If we solve this using the quadratic formula:

    t = (- b ± √(b2 - 4 . a . c)) / (2 . a)
    where:
    a = vc2 - vt2
    b = 2 . d . vt . cos(α)
    c = - d2

    a non-negative discriminant means interception is possible, and the root obtained by using addition in the quadratic formula is the first or only time of interception.

    As you can see in the image above, if the chaser is slower than the target, there are potentially two interception points if the target moves towards the chaser (blue ray intersects with green curve), but none if the target moves away from the chaser. Using addition in the quadratic formula gives the first interception point (using subtraction would give the second).

    We can then calculate the position of the target after time t, which is the interception point, and the direction from the chaser to this point.


    The JavaScript code snippet below demonstrates this method, with the values from both images. It uses angles in radians and the orientation: 0 = right, π/2 = up, π = left, -π/2 = down. The case where the chaser and target have equal velocity (and the curve is a straight line) is solved using the isosceles triangle theorem, because otherwise it would lead to a division by zero in the quadratic equation.

    function intercept(chaser, target) {
        var dist = distance(chaser, target);
        var dir = direction(chaser, target);
        var alpha = Math.PI + dir - target.dir;
        // EQUAL VELOCITY CASE: SOLVE BY ISOSCELES TRIANGLE THEOREM
        if (chaser.vel == target.vel) {
            if (Math.cos(alpha) < 0) return NaN;    // INTERCEPTION IMPOSSIBLE
            return (dir + alpha) % (Math.PI * 2);
        }
        // GENERAL CASE: SOLVE BY COSINE RULE AND QUADRATIC EQUATION
        var a = Math.pow(chaser.vel, 2) - Math.pow(target.vel, 2);
        var b = 2 * dist * target.vel * Math.cos(alpha);
        var c = -Math.pow(dist, 2);
        var disc = Math.pow(b, 2) - 4 * a * c;
        if (disc < 0) return NaN;                   // INTERCEPTION IMPOSSIBLE
        var time = (Math.sqrt(disc) - b) / (2 * a);
        var x = target.x + target.vel * time * Math.cos(target.dir);
        var y = target.y + target.vel * time * Math.sin(target.dir);
        return direction(chaser, {x: x, y: y});
    
        function distance(p, q) {
            return Math.sqrt(Math.pow(p.x - q.x, 2) + Math.pow(p.y - q.y, 2));
        }
        function direction(p, q) {
            return Math.atan2(q.y - p.y, q.x - p.x);
        }
    }
    var chaser = {x: 196, y: -45, vel: 100};
    var target = {x: 139, y: -312, vel: 75, dir: 0.1815142422};
    document.write(intercept(chaser, target) + "<br>"); // -1.015 rad = -58.17°
    var chaser = {x: 369, y: -235, vel: 37.5};
    var target = {x: 139, y: -376, vel: 75, dir: 0.1815142422};
    document.write(intercept(chaser, target) + "<br>"); // -1.787 rad = -102.4°

    other interception points

    The green curve effectively divides the 2D plane into a zone where the target will arrive first, and a zone where the chaser will arrive first. If you want the chaser and the target to move at constant speed and collide (imagine e.g. a torpedo being fired at a moving ship) then you'd aim for a point on the curve, where the two will arrive at the same time, as explained above.

    However, if the chaser can go to a point and wait there for the target to arrive (imagine e.g. a person trying to catch a bus), then every point on the target's trajectory that is within the "chaser's zone" could be the interception point.

    In the first image (slower target) the curve is a circle around the target, and once the target moves out of this circle (to the right of the interception point indicated in pink), the chaser could always get there first and wait for the target. This could be useful if you want a safety margin in case the chaser's or target's speed isn't constant.

    In the second image (faster target) the curve is a circle around the chaser, and every point on the target's trajectory inside this circle could be the interception point. The chaser could e.g. move perpendicular to the target's trajectory, in order to minimise the distance travelled, or aim at a point halfway between the first and last interception point to maximise the waiting time.

    0 讨论(0)
提交回复
热议问题