/*
Question:
Determine whether two line segments overlap, parallel, or intersection
Analysis:
Using the cross product operation, we can first determine whether it is parallel. We only need to vectorize each line segment and then use another
If the cross product operation is performed on a vector, if it is 0, it is parallel or overlapped to determine whether it is overlapped. You only need to find one of the vectors and one end of the vector and the other
The cross product operation is performed on the vectors composed of one end. If the value is 0, the result is a coincidence.
If it is not parallel, there is an intersection in this question. You can find the straight line (AX + by + c = 0) where the two line segments are respectively located, and then joinCubeCheng Jie
X, Y (this is my own method, and there may be some vulnerabilities. There are many templates on the Internet)
*/
# Include <iostream>
# Include <cstdio>
# Include <cmath>
Using namespace STD;
Struct point // point
{
Int X, Y;
};
Struct line // line
{
Point A, B;
} Line [2];
Int det (INT X1, int Y1, int X2, int Y2) // Cross Product Operation
{
Return X1 * y2-x2 * Y1;
}
Bool parallel (line U, line V) // you can determine whether a parallel line exists.
{
If (det (U. B. x-u.a.x, U. B. y-u.a.y, V. B. x-v.a.x, V. B. y-v.a.y) = 0)
Return true;
Return false;
}
Bool same_line (line U, line V) // you can determine whether a coincidence exists.
{
If (det (V. A. x-u.a.x, V. A. y-u.a.y, U. B. x-u.a.x, U. B. y-u.a.y) = 0)
Return true;
Return false;
}
Void CAL (INT A1, int B1, int C1, int A2, int B2, int C2) // three coefficients of the general equation of the two linear lines
{
Double X, Y;
Y = (A1 * c2-c1 * A2 * 1.0)/(A2 * b1-a1 * B2 );
If (a1 = 0)
X = (-c2-b2 * Y)/A2;
Else
X = (-c1-b1 * Y)/A1;
Printf ("Point %. 2lf %. 2lf \ n", x, y );
}
Void intersect (line U, line V) // Intersection
{
Int a1 = U. B. y-u.a.y;
Int b1 = U. A. x-u. B .x;
Int C1 =-U. B. y * b1-u. B .x * A1;
Int a2 = V. B. y-v.a.y;
Int b2 = V. A. x-v. B .x;
Int C2 =-V. B. y * b2-v. B .x * A2;
Cal (A1, B1, C1, A2, B2, C2 );
}
Int main ()
{
Freopen ("sum. In", "r", stdin );
Freopen ("sum. Out", "W", stdout );
Int T;
Cin> T;
Cout <"intersecting lines output" <Endl;
While (t --)
{
For (INT I = 0; I <2; I ++)
Cin> line [I]. a. x> line [I]. a. y> line [I]. b. x> line [I]. b. y;
If (parallel (line [0], line [1])
{
If (same_line (line [0], line [1])
Cout <"line" <Endl;
Else
Cout <"NONE" <Endl;
}
Else
Intersect (line [0], line [1]);
}
Cout <"End of output" <Endl;
Return 0;
}