Some time ago I made computer graphics and now I am idle. I am trying to sort out the code a little. It is a practical function.
// Determine whether or not the intersection exists // (x1, Y1) (X2, Y2) frontend // (X3, Y3) (X4, Y4) aftermarket // (x, y) intersection coordinate // return 1, return 2, return 3, do not intersection return 0 short ctriobject: mycross (double X1, double Y1, double X2, double Y2, double X3, double Y3, double X4, double Y4, double & X, double & Y) {double K1, K2; If (x1 = x2) & (Y1 = Y2) & (Y3 = Y4) & (X3 = X4) {return 0;} If (x1 = x2) & (Y1 = Y2) {If (X3 = X4) & (x1 = X3) {x = x1; y = Y1; return 1 ;} else if (y2 = (X2-X3 )* (Y4-Y3)/(X4-X3) + Y3) {x = x1; y = Y1; return 1 ;}}if (Y3 = Y4) & (X3 = X4) {If (x2 = x1) & (x1 = X3) {x = X3; y = Y3; return 2 ;} else if (Y3 = (X3-X1) * (Y2-Y1)/(X2-X1) + Y1) {x = X3; y = Y3; return 2 ;}} if (x1! = X2) {k1 = (Y2-Y1)/(X2-X1); If (X3! = X4) {k2 = (Y4-Y3)/(X4-X3); If (k1 = k2) {return 0;} X = (Y3-Y1-k2 * X3 + X1 * k1) /(K1-K2); y = K1 * (x-X1) + Y1; If (X1-x) * (X2-x) <0 | (X1-x) * (X2-x) = 0) & (Y1-y) * (Y2-y) <0 | (Y1-y) * (Y2-y) = 0) return 1; if (X3-x) * (X4-x) <0 | (X3-x) * (X4-x) = 0) & (Y3-y) * (Y4-y) <0 | (Y3-y) * (Y4-y) = 0) return 2; If (X3-x) * (X4-x)> 0 & (Y3-y) * (Y4-y)> 0 & (X1-x) * (X2-x)> 0 & (Y1-y) * (Y2-y)> 0) return 3;} If (X3 = X4) {x = X3; y = K1 * (X3-X1) + Y1; return 1 ;}} Else {If (X3! = X4) {k2 = (Y4-Y3)/(X4-X3); X = double (X1); y = k2 * (X1-X3) + Y3; return 2 ;} if (X3 = X4) {return 0 ;}} return 0 ;}