GetDistBetwPointsByVectorDirection MEL
From scripting
global proc float getDistBetwPointsByVectorDirection(vector $p1, vector $p2, vector $n) { //0001D LLC (c) Nick Pisca 2015 //vector $p1 = <<1,3,4>>; vector $p2 = <<-2,0,5>>; vector $n = <<0.5,0.5,0.75>>; //d' = abs((-pd-qe-of)-(-pa-qb-oc)) where p1 = (a,b,c) and p2 = (d,e,f) // --------------------------- and the vector direction = (p,q,o) // sqrt(p^2+q^2+o^2) //Equation solved by Nick Pisca 2015. See http://nickpisca.com/sherpa/?p=589 for details. float $pd = ($n.x) * ($p2.x); float $qe = ($n.y) * ($p2.y); float $of = ($n.z) * ($p2.z); float $pa = ($n.x) * ($p1.x); float $qb = ($n.y) * ($p1.y); float $oc = ($n.z) * ($p1.z); float $f1 = ((-1*$pd) - $qe - $of); float $f2 = ((-1*$pa) - $qb - $oc); float $top = abs($f1 - $f2); float $bot = sqrt( (($n.x)*($n.x)) + (($n.y)*($n.y)) + (($n.z)*($n.z)) ); float $fin; if ($bot != 0.0 ) { $fin = $top / $bot; } else { $fin = -1.0; } return $fin; }
More information on vectors and vector mathematics, read pages 14-16, 20-21 in YSYT.