An NDoc Documented Class Library

LineType.Distance Method (LineType, Double, Boolean, Boolean, Double)

This method calculates the distance to an other line only in case, when the distance is smaller then MaxDist else Utils.big will be returned. You can imagine a cylinder with radius MaxDist around the line. If now a line goes through the cylinder, then this is a good one and the distance will be calculated and returned. If CheckP is true then additional to the Cylinder a halfsphere with center P and radius Maxdist is considered and analogusly for CheckQ.

public double Distance(
   LineType L,
   double MaxDist,
   bool CheckP,
   bool CheckQ,
   out double Lam
);

Parameters

L
The other line, who will be tested
MaxDist
The maximal distance, for what a line a good result returns
CheckP
If CheckP is true a line, which has to point P a distance smaller then Maxdist returns good results
CheckQ
If CheckQ is true a line, which has to point Q a distance smaller then Maxdist returns good results
Lam
The param Lam can be taken to calculate the nearest point on the line by Value(Lam)

Return Value

In case the distance of the line is smaller then Maxdist, the distance is returned else big

Example

    // Given an array of xyz :
 xyz[] a = new xyz[4];
 xyz[0] = new xyz(0, 0, 0);
 xyz[1] = new xyz(0, 4, 0);
 xyz[2] = new xyz(0, 4, 4);
 xyz[3] = new xyz(4, 0, 0);
 // and a Line 
 LineType L = new LineType( new xyz(-2, 3, 1),new xyz(1, 1, 1));
 // how to find out the nearest point in the array a ??
 
double MaxDist = Utils.Big;
double lam;
LineType L2;
param=0;
    
        for (int i= 0; i < xyz.Length-1; i++)
            {
                L2 = new LineType(A[i], A[i+1] - A[i]);
                if (i == 0) 
                // Check first and second point
                di = L.Distance(L2, MaxDist, true, true, out lam);
                // Check only second point
                else di = L.Distance(L2, MaxDist, false, true, out lam);
                if (Utils.Less( di, MaxDist))
                {
                MaxDist = di;
                param = i + lam
                }
            }

 if (MaxDist < Utils.Big)
        {
        // Solution found
        // Index in array A
        int id = Utils.Trunc(param);
        // nearest Point :
        xyz nearstpoint = A[id] + (A[id+1] - A[id])* (param - id);
        }

 

See Also

LineType Class | Minais.Drawing3d.Math Namespace | LineType.Distance Overload List