2

I'm trying to use the answer provided here: Intersection of two Moving Objects with Latitude/Longitude Coordinates

But I have some questions..

What is this angle:

var angle = Math.PI + dir - target.dir

I was thinking that the angle that should be used in the law of cosines is already "alpha or target.dir".. What is that line doing? Also in these two steps:

 var x = target.x + target.vel * time * Math.cos(target.dir); 
 var y = target.y + target.vel * time * Math.sin(target.dir);  

Shouldn't the code be using the angle between x- or y-axis and the target velocity vector? Why is the author using alpha here?

enter image description here

isso11
  • 23
  • 5

1 Answers1

1

What is this angle:

var angle = Math.PI + dir - target.dir

The variable named angle is indeed the angle alpha. Because the direction dir is the direction from chaser to target, and we need it the other way round for this calculation, we add π to it before we subtract target.dir.

Maybe using the word angle as a variable name was a bit vague; I'll change it to alpha, the name I used for this angle in the images.

Shouldn't the code be using the angle between x- or y-axis and the target velocity vector? Why is the author using alpha here?

var x = target.x + target.vel * time * Math.cos(target.dir);  
var y = target.y + target.vel * time * Math.sin(target.dir);  

We are indeed using target.dir, which is the direction of the target, i.e. the angle between the x-axis and the target vector, to calculate the coordinates of the interception point, and not the angle alpha.

  • Thank you for your reply.. First, I thought, as many of the readers I guess, that the given target.dir is already alpha as it's shown in the graphs. I think you may need to declare that target.dir is the angle between the x-axis and the target velocity vector, and also include it in the graphs for calcification.. (I have attached a graph for suggested edits.) Second, based on the graphs I see that alpha just equals dir - target.dir.. I have checked the law of cosines again and it just uses alpha, I cannot get in why you want it the other way round by adding a pi ? – isso11 Sep 02 '19 at 09:15
  • 1
    @isso11 As described in the original answer, the directions use the JavaScript convention with 0 = right and Pi/2 = up, so all directions are given as angles with the X-axis. The way `dir` is calculated, it is the direction from chaser to target, but for the cosine rule, we're looking from the target to the chaser, so we add Pi to switch the direction. – m69's been on strike for years Sep 02 '19 at 14:16