问题描述
我正在尝试使用此处提供的答案:具有纬度/经度坐标的两个运动对象的交点
I'm trying to use the answer provided here: Intersection of two Moving Objects with Latitude/Longitude Coordinates
但是我有一些问题.
这个角度是什么?
var angle = Math.PI + dir - target.dir
我当时在考虑余弦定律应该使用的角度已经是"alpha或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);
代码不应该使用x轴或y轴与目标速度矢量之间的角度吗?为什么作者在这里使用Alpha?
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 angle = Math.PI + dir - target.dir
名为 angle 的变量确实是角度 alpha .因为 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.
也许使用单词 angle 作为变量名有点含糊;我将其更改为 alpha ,我在图像中为此角度使用的名称.
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.
var x = target.x + target.vel * time * Math.cos(target.dir);
var y = target.y + target.vel * time * Math.sin(target.dir);
我们确实在使用 target.dir (即目标的方向,即x轴与目标矢量之间的角度)来计算截取点的坐标,而不是角度α.
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.
这篇关于两个运动物体的交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!