好的,我需要在JavaScript中弄清楚如何在三角形上绘制第三个点。请参见下面的图示。
A和B将是随机点(可能是正数或负数,取决于它们相对于0,0原点的位置)。
因此,A和B是已知点(x和y)。
我已经弄清楚了如何基于A和B绘制C。
我想控制C和D之间的距离。例如,我想说“C和D之间的距离现在是20px…… D在哪里?”
因此,为了举例,我们可以说C和D之间的距离将是20px。这意味着我拥有CD和CB,但没有DB。我还知道C(x,y)和B(x,y)。
现在我需要找到D……我不是一个数学天才,所以请像我五岁那样给我解释一下。我已经多次搜索过谷歌,尝试使用多个示例,但仍然迷失方向……例如:我看到一些涉及phi的方程式……phi是什么?我如何在JavaScript术语中使用phi等等......
总结:
A(x,y) is known (randomized)
B(x,y) is known (randomized)
C(x,y) is known (midpoint of AB)
CB is known (using distance formula)
CD = 20 pixels (or whatever I set it to).
DB = ???
D(x,y) = ???
以下是我目前的翻译,但可能不正确...
var Aeh = {x:50, y:75};
var Bee = {x:300, y:175};
var Cee = {x:0, y:0};
var Dee = {x:0, y:0};
window.onload = function(){
refreshPoints();
solveForC();
}
function refreshPoints(){
TweenLite.set("#pointA", {x:Aeh.x, y:Aeh.y});
TweenLite.set("#pointB", {x:Bee.x, y:Bee.y});
TweenLite.set("#pointC", {x:Cee.x, y:Cee.y});
TweenLite.set("#pointD", {x:Dee.x, y:Dee.y});
}
function solveForC() {
Cee.x = (Bee.x + Aeh.x)/2;
Cee.y = (Bee.y + Aeh.y)/2;
refreshPoints();
solveForD();
}
function solveForD() {
// Dee.x = AB * Cos(Φ) + x_1
// Dee.y = AB * Sin(Φ) + y_1
Dee.x = (Cee.x+Bee.x/2) * Math.cos((1 + Math.sqrt(5)) / 2) + Cee.x;
Dee.y = (Cee.y+Bee.y/2) * Math.sin((1 + Math.sqrt(5)) / 2) + Cee.y;
refreshPoints();
}