我想画一条线来表示三 Angular 形的高度。我知道圆的所有 3 个点(a、b、c)。我想通过a画出高度。
我有以下函数来计算 bc 的垂直梯度
gradient = function(a, b) {
return b.y - a.y / b.x - a.x;
};
perpendicularGradient = function (a, b) {
return -1 / gradient(a, b);
};
我现在可以使用 y = mx + c
得到直线的方程,直线的斜率为 bc,我可以计算出 y 截距。
function perpendicularLine(vertex, a, b) {
// b = y - m * x
var slope = perpendicularGradient(a, b),
yIntercept = (- slope * vertex.x) + vertex.y;
//how do I find the coordinates of the point on bc to draw a line from vertex
}
我不知道下一步该怎么做,即我如何找到 bc 上的点的坐标以加入来自 a 的线。
通过谷歌搜索,我知道我可以使用向量,但我还没有在我的数学类(class)中涉及到它,我更愿意使用直线方程。
最佳答案
是的,在获得 yIntercept 和垂直线的斜率之后,您需要从 2 个线性方程(bc 线和穿过 a 的线)构建一个包含 2 个未知数 (x0, y0) 的 2 个线性方程组.该系统的解决方案是您沿 bc 线的交点。
关于javascript - 画出三 Angular 形的高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32924143/