2017-06-16 3 views
-1

私は2つのポイントAとBとポイントの母集団を持っており、それぞれのポイントからラインABまでの距離を求めたいと思います。数値の逆数を求める方法は?

まず、線の傾きを求め、次にY切片を求めます。 Distance between point & lineに続いて、2番目の00:48には、勾配(数)の負の逆数が必要であることが記載されています。

私は任意の数をとって、それの負の逆数を返す関数を望みます。 let inverseOfSlope = getInverse(slope);してくださいと4castleコメント「の数の負の逆数」として感謝

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/slope'になります。 – 4castle

答えて

1

のようなものは、あなたの問題への明白な関連性を持つ些細な事です。 Wikipediaはthe formulaから、点(x0、y0)から2点(x1、y1)と(x2、y2)で定義された線までの距離を計算する必要があり、その式は直接的にgetInverse(スロープ)関数。

関連する問題