Jaeseo,
You are welcome.
DPoint.Cross method calculates the cross product between two vectors. To understand the cross product, please refer to the following article:
https://betterexplained.com/articles/cross-product/.
If you need to find the intersection of two lines that are in the X-Y plane, please try the method below.
Code: Select all
public static CAD2DPoint FindIntersectionOfLines(DPoint s1, DPoint e1, DPoint s2, DPoint e2)
{
double a1 = e1.Y - s1.Y;
double b1 = s1.X - e1.X;
double c1 = a1 * s1.X + b1 * s1.Y;
double a2 = e2.Y - s2.Y;
double b2 = s2.X - e2.X;
double c2 = a2 * s2.X + b2 * s2.Y;
double delta = a1 * b2 - a2 * b1;
//If lines are parallel, the result will be (NaN, NaN).
return delta == 0 ? new CAD2DPoint(double.NaN, double.NaN)
: new CAD2DPoint((b2 * c1 - b1 * c2) / delta, (a1 * c2 - a2 * c1) / delta);
}
The arguments s1 and e1 take the start and the end point of the first CADLine, respectively.
The arguments s2 and e2 take the start and the end point of the second CADLine, respectively.
In the case of 2 polylines you will need to check each line segment of one polyline against each line segment of the other polyline for intersection.
Mikhail