-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
}
數字的負反比只是'-1 /斜率'。 – 4castle