2017-06-16 20 views
-1

我有兩個點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 
} 
+0

數字的負反比只是'-1 /斜率'。 – 4castle

回答

1

由於4castle意見「等多項負面反」是沒有明顯的相關性,以您的問題一件微不足道的小事。維基百科給出the formula您需要計算從點(x0,y0)到由兩點(x1,y1)和(x2,y2)定義的線的距離,並且該公式可以直接用任何語言實現,而無需您getInverse(斜率)函數。

相關問題