javascript - 画出三 Angular 形的高

标签 javascript math geometry 2d computational-geometry

我想画一条线来表示三 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/

相关文章:

java - Swing无法画圆

javascript - 如何从矩形点计算旋转 Angular ?

javascript - jquery Accordion 默认展开

javascript - 在抓取图像 src 上获取 base64 字符串

flutter - 我想要列表中的数字总和并显示在文本小部件中

math - 神经网络输出非二进制值?

javascript - $watch 监听器被调用一次而不改变表达式

javascript - 有人可以向我解释 Twitter Bootstrap 插件中使用的这种 javascript 模式吗?

c++ - 优化稀疏矩阵中的对数熵计算

algorithm - 给定点时如何确定哪个半径长