예제 #1
0
/** Compute the distance from a point pta
 *    to the line defined by the 2 points ptb and ptc
 *  The two points ptb and ptc defining the baseline also define
 *    its positive direction from point ptb toward point ptc.
 *  It is assumed that the 3 points pta, ptb, ptc define a plane
 *    not far from the X-Y plane.
 *  The sign of d is positive if the point pta
 *    is left of the line ptb=>ptc
 *  The sign of d is negative if pta is right of the line.
 *
 * @author Robert Laine alias Sailcuter
 */
real Distance3d(const CPoint3d &pta, const CPoint3d &ptb, const CPoint3d &ptc)
{
    real d;
    CVector3d Va = CVector3d( pta - ptb );
    CVector3d Vb = CVector3d( ptc - ptb).normalized();
    CVector3d Vd = CVector3d::crossProduct(Vb, Va);
    d = Vd.length();
    if ( Vd.z() < 0 )
        d = -d;
    //
    return d;
}