Drawing3d documented Class Library

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

This method calculates the distance to an other line only if the distance is smaller than MaxDist, otherwise Utils.big will be returned. Imagine a cylinder with radius MaxDist around the line. If now a line passes the cylinder, a reasonable result for the lenght of the distance will be returned. If CheckP is true, additional to the Cylinder a halfsphere with center P and radius Maxdist is considered and analogusly for CheckQ.

[Visual Basic]
Public Overloads Sub Distance( _
   ByVal L As LineType, _
   ByVal MaxDist As Double, _
   ByVal CheckP As Boolean, _
   ByVal CheckQ As Boolean, _
   ByRef Lam As Double _
)
[C#]
public double Distance(
   LineType L,
   double MaxDist,
   bool CheckP,
   bool CheckQ,
   out double Lam
);

Parameters

L
The other line which will be tested
MaxDist
The maximal distance at which a reasonable result is returned.
CheckP
If CheckP is true: a line, which has to point P a distance less than Maxdist, a result will be returned.
CheckQ
If CheckQ is true: a line, which has to point Q a distance less than Maxdist, a result will be returned.
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 than Maxdist, the distance is returned otherwise. 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 | Drawing3d.Math Namespace | LineType.Distance Overload List