如何找到数字的负倒数?

时间:2017-06-16 18:12:55

标签: javascript math language-agnostic logic

我有两个点A和B以及一组点,我想找到从每个点到AB线的距离。

我先得到线的斜率,然后是Y截距。在Distance between point & line之后,在第二个00:48,它表明我们需要斜率(数字)的负倒数。

我想要一个接受任何数字的函数,并返回它的负反函数。像let inverseOfSlope = getInverse(slope);请点赞,谢谢

getDistance(PointA: Object, PointB: Object, Target: Object)
{
    // find slope of the line
    let slope = (PointA.y - PointB.y) / (PointA.x - PointB.x)

    // find y intercept
    let yIntercept = PointA.y + ((-1 * slope) * PointA.x)

    // find inverse negative of the slope
    let newSlope = -1 * getInverse(slope);

    // find new y-intercept
    let NewYintercept = PointA.y + ((-1 * newSlope) * PointA.x)

    // get point of intersection between the two lines
    // by solving the two equations equal to each other

    // calculate distance between target and point of intersection
    // easy

    // return result
}

1 个答案:

答案 0 :(得分:1)

正如4castle评论“数字的负倒数”是一件微不足道的事情,与你的问题没有明显的关联。维基百科给出the formula你需要计算从点(x0,y0)到由两点(x1,y1)和(x2,y2)定义的线的距离,并且该公式可以直接用任何语言实现任何需要你的getInverse(斜率)函数。