J'ai deux points A et B et une population de points, et je voudrais trouver la distance de chaque point à la ligne AB. Je reçois d'abord la pente de la ligne, puis son ordonnée à l'origine. Et suivant Distance between point & line, à la deuxième 00:48 il indique que nous avons besoin de l'inverse négatif de la pente (nombre).Comment trouver l'inverse négatif d'un nombre?
Je voudrais une fonction qui prend n'importe quel nombre, et renvoie l'inverse négatif de celui-ci. Quelque chose comme let inverseOfSlope = getInverse(slope);
S'il vous plaît et merci
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
}
L'inverse négatif d'un nombre serait juste '-1/slope'. – 4castle