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.
In case the distance of the line is smaller then Maxdist, the distance is returned else big
// 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);
}
LineType Class | Minais.Drawing3d.Math Namespace | LineType.Distance Overload List