public Plane3D(LineDescription3D l1, LineDescription3D l2) { Point3D ptLinesCross = LineDescription3D.CrossPoint(l1, l2); if (ptLinesCross.IsNull) { return; } else { p0 = ptLinesCross; n = l1.directionVector.VectorProduct(l2.directionVector); n.VectorLength = 1.0d; } }
public static Point3D CrossPoint(LineDescription3D l1, LineDescription3D l2) { DenseMatrix dmFactorsA = DenseMatrix.Create(2, 2, (r, c) => { if (r == 0) // x row { switch (c) { case 0: return(l1.directionVector.X); break; case 1: return(-l2.directionVector.X); break; default: break; } } if (r == 1) // y row { switch (c) { case 0: return(l1.directionVector.Y); break; case 1: return(-l2.directionVector.Y); break; default: break; } } return(0.0d); }); DenseVector dvFactorB = DenseVector.Create(2, r => { switch (r) { case 0: // x row return(l2.p0.X - l1.p0.X); break; case 1: // y row return(l2.p0.Y - l1.p0.Y); break; default: break; } return(0.0d); }); DenseVector dvKvaluesResult = (DenseVector)dmFactorsA.LU().Solve(dvFactorB); Point3D cross1 = l1.p0 + dvKvaluesResult[0] * l1.directionVector; Point3D cross2 = l2.p0 + dvKvaluesResult[1] * l2.directionVector; if (cross1 == cross2) { return(cross1); } else { return(Point3D.nullPoint3D()); } }
public double Distance(LineDescription3D l1) { return(l1.Distance(this)); }