Poj_1410
Notes:
① The coordinates of the rectangular vertices must be re-sorted and used again. It is only a reference for discuss to say that the top is not strictly above the top, so we need to re-sort and re-use them in the lower order.
② Because the inside of the rectangle is also part of the rectangle, the line segment is considered to be at the intersection of the rectangle in the rectangle.
③ When determining whether the four sides of a line segment and a rectangle have intersection points, pay attention to the non-standard intersection judgment. When the line segment and the side are Collocated and do not intersection, the cross product is also 0.
# Include <stdio. h>
# Include < String . H>
# Define Zero 1e-8
Double XS, ys, XE, ye, XL, YL, xr, YR, X1 [ 5 ], Y1 [ 5 ], X2 [ 5 ], Y2 [ 5 ];
Double Det ( Double X1, Double Y1, Double X2, Double Y2)
{
Return X1 * Y2-Y1 * X2;
}
Double FABS ( Double X)
{
Return X < 0 ? -X: X;
}
Double Min ( Double X, Double Y)
{
Return X <Y? X: Y;
}
Double Max ( Double X, Double Y)
{
Return X> Y? X: Y;
}
Int DCMP ( Double X)
{
If (FABS (x) <zero)
Return 0 ;
If (X < 0 )
Return - 1 ;
Return 1 ;
}
Int Onseg ( Double X, Double Y, Double X1, Double Y1, Double X2, Double Y2)
{
If (FABS (x2-X1) <FABS (Y2-Y1 ))
Return DCMP (Y-Y2) * (Y-Y1) <=0 ;
Else
Return DCMP (X-X2) * (X-X1) <= 0 ;
}
Void Solve ()
{
Int I, J, K;
Double T1, T2, T3, T4;
X1 [ 0 ] = XL, Y1 [ 0 ] = Yr, X2 [ 0 ] = XR, Y2 [0 ] = Yr;
X1 [ 1 ] = XL, Y1 [ 1 ] = Yr, X2 [ 1 ] = XL, Y2 [ 1 ] = Yl;
X1 [ 2 ] = XL, Y1 [ 2 ] = YL, X2 [ 2 ] = XR, Y2 [ 2 ] = Yl;
X1 [ 3 ] = XR, Y1 [ 3 ] = Yr, X2 [3 ] = XR, Y2 [ 3 ] = Yl;
For (I = 0 ; I < 4 ; I ++)
{
T1 = det (X2 [I]-X1 [I], Y2 [I]-Y1 [I], xs-X1 [I], ys-Y1 [I]);
T2 = det (X2 [I]-X1 [I], Y2 [I]-Y1 [I], Xe-X1 [I], Ye-Y1 [I]);
T3 = det (Xe-xs, Ye-Ys, X1 [I]-xs, Y1 [I]-Ys );
T4 = det (Xe-xs, Ye-Ys, X2 [I]-xs, Y2 [I]-Ys );
If (DCMP (T1) * DCMP (T2) < 0 & DCMP (T3) * DCMP (T4) < 0 )
{
Printf ( " T \ n " );
Return ;
}
If (DCMP (T1) = 0 & Onseg (XS, ys, X1 [I], Y1 [I], X2 [I], Y2 [I]) | (DCMP (T2) = 0 & Onseg (xe, ye, X1 [I], Y1 [I], X2 [I], Y2 [I]) | (DCMP (T3) = 0 & Onseg (x1 [I], Y1 [I], xs, ys, XE, ye) | (DCMP (T4) = 0 & Onseg (X2 [I], Y2 [I], xs, ys, XE, ye )))
{
Printf ( " T \ n " );
Return ;
}
}
Printf ( " F \ n " );
}
Int Main ()
{
Int I, T;
Double X;
Scanf ( " % D " , & T );
While (T --)
{
Scanf ( " % Lf " , & XS, & ys, & XE, & Ye, & XL, & YL, & XR, & yr );
If (XL> xr)
X = XL, XL = XR, xr = X;
If (Yl <yr)
X = YL, yl = yr, yr = X;
If (XS <XR & Xs> XL & ys <yl & ys> yr) | (Xe <XR & Xe> XL & Ye <yl & Ye> yr ))
Printf ( " T \ n " );
Else
Solve ();
}
Return 0 ;
}