画出三角形的高

draw the altitude of a triangle

我想画一条线来表示三角形的高度。我知道圆的所有 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 开始的线。

通过谷歌搜索,我知道我可以使用向量,但我还没有在我的数学课程中涉及到它,我更愿意使用直线方程。

对了,在你有了 yIntercept 和垂直线的斜率之后,你需要从 2 个线性方程(bc 线和穿过一种)。该系统的解决方案是您沿 bc 线的交点。

让点 p 沿 bc,由矢量方程 p = b + t bc 给出,其中 t 是一个参数。你用

表示海拔和基地的正交性
ap.bc = 0, or (ab + t bc) bc = 0.

这给出了

t = -ab.bc/bc²

它允许您计算 p