Find the intersection of two straight lines in the plane. When the two straight lines are uneven, there must be only one intersection.
/* Returns the intersection of two straight lines */PointLinesintersection(Line m, line N, int * flag) {double D = n. A * m. b-M. A * n. b; If (D = 0) {* flag = 0; return;} Point I; I. X = (N. B * m. c-M. B * n. c)/d; I. y = (M. A * n. c-n. A * m. c)/d; * flag = 1; return I ;}
The disadvantage of this function is that the parameter flag is added, because the two straight lines M and N may be parallel, and the return value is null.
If you change the function to return a point pointer, the return value is null when the parallel operation is performed.
Why didn't I choose this method? if the pointer is used, you must use malloc in this function to apply for a space. The space must be released outside the function, so it is easy to forget to release it.
About malloc: malloc is the space applied for when the program is running. It is more efficient, and you need to consider the unsuccessful processing of the application and the release of all malloc variables accidentally. My personal principle is to try not to use the malloc variable while solving the problem.